export = Emittery; declare class Emittery { /** * Subscribe to an event. * * Returns an unsubscribe method. * * Using the same listener multiple times for the same event will result * in only one method call per emitted event. */ on(eventName: string, listener: (eventData?: any) => any): Emittery.UnsubscribeFn; /** * Remove an event subscription. */ off(eventName: string, listener: (eventData?: any) => any): void; /** * Subscribe to an event only once. It will be unsubscribed after the first * event. * * Returns a promise for the event data when `eventName` is emitted. */ once(eventName: string): Promise; /** * Trigger an event asynchronously, optionally with some data. Listeners * are called in the order they were added, but execute concurrently. * * Returns a promise for when all the event listeners are done. *Done* * meaning executed if synchronous or resolved when an * async/promise-returning function. You usually wouldn't want to wait for * this, but you could for example catch possible errors. If any of the * listeners throw/reject, the returned promise will be rejected with the * error, but the other listeners will not be affected. * * Returns a promise for when all the event listeners are done. */ emit(eventName: string, eventData?: any): Promise; /** * Same as `emit()`, but it waits for each listener to resolve before * triggering the next one. This can be useful if your events depend on each * other. Although ideally they should not. Prefer `emit()` whenever * possible. * * If any of the listeners throw/reject, the returned promise will be * rejected with the error and the remaining listeners will *not* be called. * * Returns a promise for when all the event listeners are done. */ emitSerial(eventName: string, eventData?: any): Promise; /** * Subscribe to be notified about any event. * * Returns a method to unsubscribe. */ onAny(listener: (eventName: string, eventData?: any) => any): Emittery.UnsubscribeFn; /** * Remove an `onAny` subscription. */ offAny(listener: (eventName: string, eventData?: any) => any): void; /** * Clear all event listeners on the instance. * * If `eventName` is given, only the listeners for that event are cleared. */ clearListeners(eventName?: string): void; /** * The number of listeners for the `eventName` or all events if not * specified. */ listenerCount(eventName?: string): number; } declare namespace Emittery { /** * Removes an event subscription. */ type UnsubscribeFn = () => void; /** * Maps event names to their emitted data type. */ interface Events { [eventName: string]: any; } /** * Async event emitter. * * Must list supported events and the data type they emit, if any. * * For example: * * ```ts * import Emittery = require('emittery'); * * const ee = new Emittery.Typed<{value: string}, 'open' | 'close'>(); * * ee.emit('open'); * ee.emit('value', 'foo\n'); * ee.emit('value', 1); // TS compilation error * ee.emit('end'); // TS compilation error * ``` */ class Typed extends Emittery { on>(eventName: Name, listener: (eventData: EventDataMap[Name]) => any): Emittery.UnsubscribeFn; on(eventName: Name, listener: () => any): Emittery.UnsubscribeFn; once>(eventName: Name): Promise; once(eventName: Name): Promise; off>(eventName: Name, listener: (eventData: EventDataMap[Name]) => any): void; off(eventName: Name, listener: () => any): void; onAny(listener: (eventName: Extract | EmptyEvents, eventData?: EventDataMap[Extract]) => any): Emittery.UnsubscribeFn; offAny(listener: (eventName: Extract | EmptyEvents, eventData?: EventDataMap[Extract]) => any): void; emit>(eventName: Name, eventData: EventDataMap[Name]): Promise; emit(eventName: Name): Promise; emitSerial>(eventName: Name, eventData: EventDataMap[Name]): Promise; emitSerial(eventName: Name): Promise; } }