2023-01-28 01:53:29 -05:00
|
|
|
/**
|
|
|
|
* A callback function called when a an event is triggered.
|
|
|
|
*/
|
2023-02-02 04:05:47 -05:00
|
|
|
export type Listener = (...args: Array<any>) => void;
|
2023-01-28 01:53:29 -05:00
|
|
|
/**
|
|
|
|
* An **EventEmitterable** behaves similar to an EventEmitter
|
|
|
|
* except provides async access to its methods.
|
|
|
|
*
|
|
|
|
* An EventEmitter implements the observer pattern.
|
|
|
|
*/
|
2022-09-05 16:57:11 -04:00
|
|
|
export interface EventEmitterable<T> {
|
2023-01-28 01:53:29 -05:00
|
|
|
/**
|
|
|
|
* Registers a %%listener%% that is called whenever the
|
|
|
|
* %%event%% occurs until unregistered.
|
|
|
|
*/
|
2022-09-05 16:57:11 -04:00
|
|
|
on(event: T, listener: Listener): Promise<this>;
|
2023-01-28 01:53:29 -05:00
|
|
|
/**
|
|
|
|
* Registers a %%listener%% that is called the next time
|
|
|
|
* %%event%% occurs.
|
|
|
|
*/
|
2022-09-05 16:57:11 -04:00
|
|
|
once(event: T, listener: Listener): Promise<this>;
|
2023-01-28 01:53:29 -05:00
|
|
|
/**
|
|
|
|
* Triggers each listener for %%event%% with the %%args%%.
|
|
|
|
*/
|
2022-09-05 16:57:11 -04:00
|
|
|
emit(event: T, ...args: Array<any>): Promise<boolean>;
|
2023-01-28 01:53:29 -05:00
|
|
|
/**
|
|
|
|
* Resolves to the number of listeners for %%event%%.
|
|
|
|
*/
|
2022-09-05 16:57:11 -04:00
|
|
|
listenerCount(event?: T): Promise<number>;
|
2023-01-28 01:53:29 -05:00
|
|
|
/**
|
|
|
|
* Resolves to the listeners for %%event%%.
|
|
|
|
*/
|
2022-09-05 16:57:11 -04:00
|
|
|
listeners(event?: T): Promise<Array<Listener>>;
|
2023-01-28 01:53:29 -05:00
|
|
|
/**
|
|
|
|
* Unregister the %%listener%% for %%event%%. If %%listener%%
|
|
|
|
* is unspecified, all listeners are unregistered.
|
|
|
|
*/
|
2022-09-05 16:57:11 -04:00
|
|
|
off(event: T, listener?: Listener): Promise<this>;
|
2023-01-28 01:53:29 -05:00
|
|
|
/**
|
|
|
|
* Unregister all listeners for %%event%%.
|
|
|
|
*/
|
2022-09-05 16:57:11 -04:00
|
|
|
removeAllListeners(event?: T): Promise<this>;
|
2023-01-28 01:53:29 -05:00
|
|
|
/**
|
|
|
|
* Alias for [[on]].
|
|
|
|
*/
|
2022-09-05 16:57:11 -04:00
|
|
|
addListener(event: T, listener: Listener): Promise<this>;
|
2023-01-28 01:53:29 -05:00
|
|
|
/**
|
|
|
|
* Alias for [[off]].
|
|
|
|
*/
|
2022-09-05 16:57:11 -04:00
|
|
|
removeListener(event: T, listener: Listener): Promise<this>;
|
|
|
|
}
|
2023-01-28 01:53:29 -05:00
|
|
|
/**
|
|
|
|
* When an [[EventEmitterable]] triggers a [[Listener]], the
|
|
|
|
* callback always ahas one additional argument passed, which is
|
|
|
|
* an **EventPayload**.
|
|
|
|
*/
|
2022-09-05 16:57:11 -04:00
|
|
|
export declare class EventPayload<T> {
|
|
|
|
#private;
|
2023-01-28 01:53:29 -05:00
|
|
|
/**
|
|
|
|
* The event filter.
|
|
|
|
*/
|
2022-09-05 16:57:11 -04:00
|
|
|
readonly filter: T;
|
2023-01-28 01:53:29 -05:00
|
|
|
/**
|
|
|
|
* The **EventEmitterable**.
|
|
|
|
*/
|
2022-09-05 16:57:11 -04:00
|
|
|
readonly emitter: EventEmitterable<T>;
|
2023-01-28 01:53:29 -05:00
|
|
|
/**
|
|
|
|
* Create a new **EventPayload** for %%emitter%% with
|
|
|
|
* the %%listener%% and for %%filter%%.
|
|
|
|
*/
|
2022-09-05 16:57:11 -04:00
|
|
|
constructor(emitter: EventEmitterable<T>, listener: null | Listener, filter: T);
|
2023-01-28 01:53:29 -05:00
|
|
|
/**
|
|
|
|
* Unregister the triggered listener for future events.
|
|
|
|
*/
|
2022-09-05 16:57:11 -04:00
|
|
|
removeListener(): Promise<void>;
|
|
|
|
}
|
|
|
|
//# sourceMappingURL=events.d.ts.map
|