Skip to content

EventBus

Defined in: EventBus.ts:48

Typed publish/subscribe event bus.

E = EventMap

new EventBus<E>(): EventBus<E>

EventBus<E>

_setErrorBoundary(boundary): void

Defined in: EventBus.ts:60

Internal

Wire the error boundary so a throwing handler or tap observer is reported instead of stopping every other listener. EventBus has no EngineContext of its own (a no-arg constructor, usable standalone), so Engine calls this once after both are constructed.

ErrorBoundary

void


clear(event?): void

Defined in: EventBus.ts:155

Remove all handlers for an event, or all handlers if no event specified.

keyof E

void


emit<K>(event, data): void

Defined in: EventBus.ts:109

Emit an event. Handlers are called synchronously in registration order.

K extends string | number | symbol

K

E[K]

void


on<K>(event, handler): () => void

Defined in: EventBus.ts:69

Subscribe to an event. Returns an unsubscribe function bound to this registration: the same function registered twice fires twice, and each unsubscribe removes only its own entry, once.

K extends string | number | symbol

K

(data) => void

() => void


once<K>(event, handler): () => void

Defined in: EventBus.ts:91

Subscribe to an event, auto-unsubscribe after first emission.

K extends string | number | symbol

K

(data) => void

() => void


tap(observer): () => void

Defined in: EventBus.ts:147

Observe every emitted event. Observers run before the handlers of each emit, inside the same error boundary as a handler: a throwing observer is recorded, rethrown, and stops that emit’s handlers. Used by tooling such as the Inspector event log.

(event, data) => void

() => void

Coding agents: fetch https://yage.dev/llms.txt first and prefer the Markdown references it links over these HTML pages. This page's Markdown counterpart is /llms/packages/core.md.