Events
globalAsynchronous resource event bus.
Methods
on(eventName: string, handler: EventHandler): UnsubscribeRegisters a persistent handler in the shared event namespace.
- eventName
- Case-sensitive event name.
- handler
- Resource-owned callback invoked with the emitted arguments.
Returns Function that removes this exact subscription.
once(eventName: string, handler: EventHandler)Registers a handler that is removed before its first invocation.
- eventName
- Case-sensitive event name.
- handler
- Resource-owned callback invoked with the emitted arguments.
off(eventName: string, handler: EventHandler)Removes a matching handler owned by the calling resource.
- eventName
- Case-sensitive event name.
- handler
- Resource-owned callback invoked with the emitted arguments.
emit(eventName: string, ...args: unknown[]): Promise<void>Invokes every shared handler and waits for all synchronous and asynchronous results.
- eventName
- Shared event name.
- args
- Arguments delivered to every matching handler.
Returns Promise rejected with an AggregateError when one or more handlers fail.
emitTo(resourceName: string, eventName: string, ...args: unknown[]): Promise<void>Invokes matching handlers belonging only to one resource.
- resourceName
- Destination running resource.
- eventName
- Shared event name.
- args
- Arguments delivered to matching handlers owned by the destination.
Returns Promise rejected when one or more destination handlers fail.
onLocal(eventName: string, handler: EventHandler)Registers a handler in the calling resource's private local-event namespace.
- eventName
- Case-sensitive event name.
- handler
- Resource-owned callback invoked with the emitted arguments.
emitLocal(eventName: string, ...args: unknown[]): Promise<void>Emits an event only within the calling resource.
- eventName
- Private local event name.
- args
- Arguments delivered only to handlers owned by the calling resource.
Returns Promise rejected when one or more local handlers fail.
listenerCount(eventName: string): numberCounts persistent and one-shot shared handlers across resources.
- eventName
- Shared event name to inspect.
Returns Number of matching handlers.
emitAllClients(eventName: string, payload?: unknown)Broadcasts a named event to every connected client's shared Events handlers.
- eventName
- Client shared-event name.
- payload
- Optional string payload sent verbatim; other values are JSON-serialized.
onClient(eventName: string, handler: EventHandler): UnsubscribeRegisters a persistent server handler for events originating from clients; this namespace is isolated from native events.
- eventName
- Case-sensitive event name.
- handler
- Resource-owned callback invoked with the emitted arguments.
Returns Function that removes this exact subscription.
onceClient(eventName: string, handler: EventHandler)Registers a one-shot server handler for a client-originated event.
- eventName
- Case-sensitive event name.
- handler
- Resource-owned callback invoked with the emitted arguments.
offClient(eventName: string, handler: EventHandler)Removes a matching client-originated event handler owned by the calling resource.
- eventName
- Case-sensitive event name.
- handler
- Resource-owned callback invoked with the emitted arguments.



