Files
deepseek-harness/website/zh-CN/api/cordis/events.md
T

143 lines
5.3 KiB
Markdown
Raw Normal View History

<!-- Generated by scripts/gen-website-api.ts — do not edit by hand. Run `pnpm run gen-website-api` to regenerate. -->
2026-07-09 16:07:58 +08:00
# Events
The event system mixed into every context. Harness-defined events are cataloged on [Harness events](../harness/events.md).
### ctx.parallel(name, ...args)
```ts website-api
parallel<K extends keyof Events>(name: K, ...args: Parameters<Events[K]>): Promise<void>
parallel<K extends keyof Events>(thisArg: NoInfer<ThisType<Events[K]>>, name: K, ...args: Parameters<Events[K]>): Promise<void>
```
Dispatch an event, running all listeners concurrently.
2026-07-09 16:07:58 +08:00
- `name` — the event name.
- `args` — arguments passed to every listener.
2026-07-09 16:07:58 +08:00
**Returns** a promise resolving once every listener has settled.
2026-07-09 16:07:58 +08:00
[Source](https://github.com/deepseek-harness/deepseek-harness/blob/master/vendor/cordis/src/events.ts#L43)
2026-07-09 16:07:58 +08:00
### ctx.emit(name, ...args)
2026-07-09 16:07:58 +08:00
```ts website-api
emit<K extends keyof Events>(name: K, ...args: Parameters<Events[K]>): void
emit<K extends keyof Events>(thisArg: NoInfer<ThisType<Events[K]>>, name: K, ...args: Parameters<Events[K]>): void
2026-07-09 16:07:58 +08:00
```
Dispatch an event synchronously, ignoring listener return values.
2026-07-09 16:07:58 +08:00
- `name` — the event name.
- `args` — arguments passed to every listener.
2026-07-09 16:07:58 +08:00
[Source](https://github.com/deepseek-harness/deepseek-harness/blob/master/vendor/cordis/src/events.ts#L52)
2026-07-09 16:07:58 +08:00
### ctx.serial(name, ...args)
2026-07-09 16:07:58 +08:00
```ts website-api
serial<K extends keyof Events>(name: K, ...args: Parameters<Events[K]>): Promisify<ReturnType<Events[K]>>
serial<K extends keyof Events>(thisArg: NoInfer<ThisType<Events[K]>>, name: K, ...args: Parameters<Events[K]>): Promisify<ReturnType<Events[K]>>
```
2026-07-09 16:07:58 +08:00
Dispatch an event, awaiting listeners in order until one bails.
2026-07-09 16:07:58 +08:00
- `name` — the event name.
- `args` — arguments passed to each listener.
2026-07-09 16:07:58 +08:00
**Returns** the first bail value (non-null, non-false, non-undefined), if any.
2026-07-09 16:07:58 +08:00
[Source](https://github.com/deepseek-harness/deepseek-harness/blob/master/vendor/cordis/src/events.ts#L62)
2026-07-09 16:07:58 +08:00
### ctx.bail(name, ...args)
2026-07-09 16:07:58 +08:00
```ts website-api
bail<K extends keyof Events>(name: K, ...args: Parameters<Events[K]>): ReturnType<Events[K]>
bail<K extends keyof Events>(thisArg: NoInfer<ThisType<Events[K]>>, name: K, ...args: Parameters<Events[K]>): ReturnType<Events[K]>
```
2026-07-09 16:07:58 +08:00
Dispatch an event, calling listeners in order until one bails.
2026-07-09 16:07:58 +08:00
- `name` — the event name.
- `args` — arguments passed to each listener.
2026-07-09 16:07:58 +08:00
**Returns** the first bail value (non-null, non-false, non-undefined), if any.
2026-07-09 16:07:58 +08:00
[Source](https://github.com/deepseek-harness/deepseek-harness/blob/master/vendor/cordis/src/events.ts#L72)
2026-07-09 16:07:58 +08:00
### ctx.waterfall(name, ...args)
2026-07-09 16:07:58 +08:00
```ts website-api
waterfall<K extends keyof Events>(name: K, ...args: Parameters<Events[K]>): ReturnType<Events[K]>
waterfall<K extends keyof Events>(thisArg: NoInfer<ThisType<Events[K]>>, name: K, ...args: Parameters<Events[K]>): ReturnType<Events[K]>
2026-07-09 16:07:58 +08:00
```
Dispatch an event whose last argument is a `next` continuation.
Each listener wraps the rest of the chain: calling `next()` invokes the next listener (finally the built-in behavior); not calling it vetoes.
- `name` — the event name.
- `args` — listener arguments; the final one is the innermost `next`.
2026-07-09 16:07:58 +08:00
**Returns** the outermost listener's return value.
2026-07-09 16:07:58 +08:00
[Source](https://github.com/deepseek-harness/deepseek-harness/blob/master/vendor/cordis/src/events.ts#L85)
2026-07-09 16:07:58 +08:00
### ctx.on(name, listener, options?)
2026-07-09 16:07:58 +08:00
```ts website-api
on<K extends keyof Events>(name: K, listener: Events[K], options?: boolean | EventOptions): () => boolean
```
2026-07-09 16:07:58 +08:00
Register an event listener owned by the current fiber.
2026-07-09 16:07:58 +08:00
- `name` — the event name to listen for.
- `listener` — called with the dispatch arguments.
- `options` — listener options; a boolean is shorthand for `prepend`.
2026-07-09 16:07:58 +08:00
**Returns** a disposer removing the listener; `true` if it was still registered.
2026-07-09 16:07:58 +08:00
[Source](https://github.com/deepseek-harness/deepseek-harness/blob/master/vendor/cordis/src/events.ts#L96)
2026-07-09 16:07:58 +08:00
### ctx.once(name, listener, options?)
2026-07-09 16:07:58 +08:00
```ts website-api
once<K extends keyof Events>(name: K, listener: Events[K], options?: boolean | EventOptions): () => boolean
```
2026-07-09 16:07:58 +08:00
Same as `on()`, but the listener disposes itself after its first call.
2026-07-09 16:07:58 +08:00
- `name` — the event name to listen for.
- `listener` — called at most once with the dispatch arguments.
- `options` — listener options; a boolean is shorthand for `prepend`.
2026-07-09 16:07:58 +08:00
**Returns** a disposer removing the listener; `true` if it was still registered.
2026-07-09 16:07:58 +08:00
[Source](https://github.com/deepseek-harness/deepseek-harness/blob/master/vendor/cordis/src/events.ts#L105)
2026-07-09 16:07:58 +08:00
## EventOptions
2026-07-09 16:07:58 +08:00
Options accepted by `ctx.on()` and `ctx.once()`.
2026-07-09 16:07:58 +08:00
```ts website-api
interface EventOptions {
/** Add the listener before existing listeners for the same event. */
prepend?: boolean
/** Receive the event regardless of context filter checks. */
global?: boolean
}
```
2026-07-09 16:07:58 +08:00
[Source](https://github.com/deepseek-harness/deepseek-harness/blob/master/vendor/cordis/src/events.ts#L111)
2026-07-09 16:07:58 +08:00
## DispatchMode
2026-07-09 16:07:58 +08:00
Event dispatch strategy used by the event service.
`emit` runs synchronous listeners without awaiting them, `parallel` awaits all listeners together, `serial` awaits them in order until one bails, `bail` stops on the first synchronous bail value, and `waterfall` composes listeners around a final `next` callback.
2026-07-09 16:07:58 +08:00
```ts website-api
type DispatchMode = 'emit' | 'parallel' | 'serial' | 'bail' | 'waterfall'
```
2026-07-09 16:07:58 +08:00
[Source](https://github.com/deepseek-harness/deepseek-harness/blob/master/vendor/cordis/src/events.ts#L31)