/** * Options accepted by the event-bus `stream` rail. Carries the abort signal that terminates the iteration; further keys are reserved for a future backpressure policy. * The default behavior is unbounded, matching the livestream-subscription rule (a subscriber receives every emission until it aborts or stops iterating). * * @category Events */ export interface StreamOptions { signal?: AbortSignal; } /** * A typed facade over `node:events.EventEmitter` that exposes exactly three subscription shapes - the canonical contract every event-producing subsystem in this * library presents (`Transport`, `EventStream`, `ConnectionMonitor`, `LivestreamSession`, `ProtectClient`). * * We *compose* `EventEmitter` rather than *extend* it, for several load-bearing reasons: * * 1. {@link on} returns a `Disposable`, not `this`. `using sub = bus.on(...)` auto-cleans at scope exit, so listener leaks are prevented structurally rather than by * discipline - and inline arrow handlers are fine because the handle, not the function identity, is what unsubscribes. * 2. None of `EventEmitter`'s many inherited methods (`prependOnceListener`, `eventNames`, `rawListeners`, `getMaxListeners`, ...) leak onto the public type of the * host class. Consumers see only the three rails. * 3. It aligns subscriptions with the library's `await using` resource-lifetime discipline: a subscription is a resource, and a `Disposable` subscription completes * that alignment. * 4. It preserves Node's battle-tested emit machinery - listener-during-emit reentrancy, sync-throw handling, listener self-removal - which has fifteen years of * bug-fixing behind it, without inheriting the surface bloat. * * The same internal emitter drives all three rails, so a single {@link emit} notifies every active {@link on} callback, resolves every pending {@link once} promise, * and pushes to every open {@link stream} iterator. That is the single-source-of-truth guarantee: there is exactly one fan-out path per event. * * `EventMap` keys are the event names; each value is the tuple of arguments that event carries (e.g., `{ throttleEntered: []; packet: [event: TypedEvent] }`). * * @typeParam EventMap - A record mapping each event name to the readonly tuple of arguments emitted with it. * * @category Events */ export declare class EventBus> { #private; constructor(); /** * Long-lived notification subscription. Registers `handler` for `event` and returns a `Disposable` whose disposal detaches it. * * Prefer `using sub = bus.on("event", handler);` so the listener is removed automatically when the binding leaves scope. Where a `using` declaration does not fit, * call `sub[Symbol.dispose]()` explicitly. Disposing twice is safe - the second `off` is a no-op. * * @param event - The event name to listen for. * @param handler - Invoked with the event's argument tuple on every emission until the returned handle is disposed. * * @returns A `Disposable` that removes this listener when disposed. */ on(event: K, handler: (...args: EventMap[K]) => void): Disposable; /** * One-shot wait for the next emission of `event`. Resolves with the event's argument tuple. Cancellable: if `opts.signal` aborts before the event fires, the * promise rejects with the signal's abort reason (an `AbortError` by default). * * @param event - The event name to await. * @param opts - Optional abort signal that cancels the wait. * * @returns A promise resolving to the argument tuple of the next emission. */ once(event: K, opts?: { signal?: AbortSignal; }): Promise; /** * Backpressure-aware async iterable of every subsequent emission of `event`, until `opts.signal` aborts or the consumer stops iterating. Each yielded value is the * event's argument tuple. The queue is unbounded by default - a slow consumer accumulates pending emissions rather than dropping them. * * @param event - The event name to stream. * @param opts - Optional abort signal that terminates the iteration. * * @returns An async iterable yielding the argument tuple of each emission. */ stream(event: K, opts?: StreamOptions): AsyncIterable; /** * Emit `event` with its argument tuple, synchronously invoking every active listener (callbacks, pending `once` waiters, open `stream` iterators). * * This method is package-internal: the host subsystem emits; the host's public type re-exposes only `on` / `once` / `stream`. It is not part of any consumer-facing * surface. * * @param event - The event name to emit. * @param args - The argument tuple for this event. * * @returns `true` if the event had listeners, `false` otherwise (the `EventEmitter.emit` contract). * * @internal */ emit(event: K, ...args: EventMap[K]): boolean; } //# sourceMappingURL=event-bus.d.ts.map