UNPKG

@akala/core

Version:
32 lines (31 loc) 1.43 kB
import { type Subscription } from "../teardown-manager.js"; import { Event, type Listener } from "./shared.js"; /** * AsyncEvent class to manage asynchronous events. * @template T * @template TReturnType * @extends {Event<T, TReturnType | PromiseLike<TReturnType>>} */ export declare class AsyncEvent<T extends unknown[] = unknown[], TReturnType = void> extends Event<T, TReturnType | PromiseLike<TReturnType>> { /** * Creates an instance of AsyncEvent. * @param {number} [maxListeners=10] - The maximum number of listeners. * @param {(args: TReturnType[]) => TReturnType} combineReturnTypes - Function to combine return types. */ constructor(maxListeners?: number, combineReturnTypes?: Event<T, TReturnType>['combineReturnTypes']); /** * Adds a listener to the asynchronous event. * @param {Listener<T, TReturnType | Promise<TReturnType>>} listener - The listener to add. * @param {{ once?: boolean }} [options] - The event options. * @returns {Subscription} - The subscription. */ addListener(listener: Listener<T, TReturnType | PromiseLike<TReturnType>>, options?: { once?: boolean; }): Subscription; /** * Emits the asynchronous event. * @param {...T} args - The arguments to pass to the listeners. * @returns {Promise<TReturnType>} - The return value of the listeners. */ emit(...args: T): Promise<TReturnType>; }