import { type Container, type PostProcessor } from './di'; /** An event class — used both to subscribe and (via `event.constructor`) to dispatch. */ export type EventType = abstract new (...args: any[]) => E; /** A subscriber to an event; may be async — {@link Events.publish} awaits its result and logs (never rethrows) a rejection. */ export type EventListener = (event: E) => unknown; /** * An in-process publish/subscribe bus. Inject it, `publish()` events, and * subscribe with `on()` or the `@onEvent` decorator. `publish` awaits all * listeners (a failing one is logged, not propagated). */ export declare class Events { private readonly listeners; /** * Subscribe to an event type. Matching is by exact event class — a listener on * a base class does not receive published subclass instances (dispatch keys off * `event.constructor`). Returns an unsubscribe function. * * @typeParam E - The event object type this listener receives. * @param type - The event class to subscribe to. * @param listener - invoked (and awaited) for each published event of `type`. * @returns an unsubscribe function; calling it removes this listener (repeat calls are no-ops). */ on(type: EventType, listener: EventListener): () => void; /** * Invoke every subscriber of the event's exact class concurrently; resolve once * all have settled. A listener that throws or rejects is caught and logged * (`console.error`, `[turnover]` prefix) and never fails this call, so one bad * listener cannot block the others. No subscribers is a no-op. * * @typeParam E - The event object type being published. * @param event - the instance to deliver; its exact `constructor` selects the subscribers. */ publish(event: E): Promise; } /** * Method decorator: subscribe this method to an event type. The service is * registered when it is constructed (inject it, or list it in * `createApp({ listeners })` to construct it eagerly). * * ```ts * @injectable() class Emailer { * @onEvent(UserCreated) welcome(e: UserCreated) { ... } * } * ``` * * @typeParam E - The event object type the decorated method handles. * @param type - The event class to subscribe the method to. * @returns A method decorator that records the subscription. */ export declare function onEvent(type: EventType): (_value: unknown, context: ClassMethodDecoratorContext) => void; /** * A post-processor that subscribes a constructed instance's `@onEvent` methods * to the container's `Events` bus. Registered automatically by `createApp`. * * @param container - The container whose `Events` bus receives the subscriptions. * @returns A `PostProcessor` that wires each instance's `@onEvent` methods. */ export declare function eventListenerProcessor(container: Container): PostProcessor; //# sourceMappingURL=events.d.ts.map