/** * @license * Copyright 2025 Steven Roussey * SPDX-License-Identifier: Apache-2.0 */ /** * A type that represents a listener function for an event. * @template Events - A record of event names and their corresponding listener functions * @template EventType - The name of the event */ type EventListener = Events[EventType]; /** * A type that represents the parameters of an event. * @template Events - A record of event names and their corresponding listener functions * @template EventType - The name of the event */ export type EventParameters = { [Event in EventType]: EventListener extends (...args: infer P) => any ? P : never; }[EventType]; /** * A type that represents the return type of the emitted method. * @template Events - A record of event names and their corresponding listener functions * @template EventType - The name of the event */ export type EmittedReturnType = EventParameters; /** * A class that implements an event emitter pattern. * @template EventListenerTypes - A record of event names and their corresponding listener functions */ export declare class EventEmitter any>> { private listeners; private maxListeners; private warnedEvents; /** * Set the maximum number of listeners per event before a warning is emitted. * 0 means unlimited (default). */ setMaxListeners(n: number): this; /** * Get the number of listeners for a specific event */ listenerCount(event: Event): number; /** * Get all event names that have registered listeners */ eventNames(): Array; /** * Remove all listeners for a specific event or all events * @param event - Optional event name. If not provided, removes all listeners for all events * @returns this, so that calls can be chained */ removeAllListeners(event?: Event): this; /** * Adds a listener function for the event * @param event - The event name to listen for * @param listener - The listener function to add * @returns this, so that calls can be chained */ on(event: Event, listener: EventListener): this; /** * Removes a listener function for the event * @param event - The event name to remove the listener from * @param listener - The listener function to remove * @returns this, so that calls can be chained */ off(event: Event, listener: EventListener): this; /** * Adds a listener function for the event that will be called only once * @param event - The event name to listen for * @param listener - The listener function to add * @returns this, so that calls can be chained */ once(event: Event, listener: EventListener): this; /** * Returns a promise that resolves when the event is emitted * @param event - The event name to listen for * @returns a promise that resolves to an array of all parameters of the event (empty array for events with no parameters) */ waitOn(event: Event): Promise>; /** * Emits an event with the specified name and arguments * @param event - The event name to emit * @param args - Arguments to pass to the event listeners */ emit(this: EventEmitter, event: Event, ...args: EventParameters): void; private checkMaxListeners; /** * Subscribes to an event and returns a function to unsubscribe * @param event - The event name to subscribe to * @param listener - The listener function to add * @returns a function to unsubscribe from the event */ subscribe(event: Event, listener: EventListener): () => void; } export {}; //# sourceMappingURL=EventEmitter.d.ts.map