import { Disposable } from './disposable'; import { MaybePromise } from './types'; type Pick = { [P in K]: T[P]; }; type Exclude = T extends U ? never : T; type Omit = Pick>; export interface CancellationToken { isCancellationRequested: boolean; onCancellationRequested: Event; } export declare namespace CancellationToken { const None: CancellationToken; const Cancelled: CancellationToken; } export declare class CancellationError extends Error { constructor(); } export declare class CancellationTokenSource { private _token; readonly token: CancellationToken; cancel(): void; dispose(): void; } export declare function cancelled(): Error; export declare function isCancelled(err: Error | undefined): boolean; export declare function checkCancelled(token?: CancellationToken): void; /** * Represents a typed event. */ export interface Event { /** * @param listener The listener function will be call when the event happens. * @param thisArgs The 'this' which will be used when calling the event listener. * @param disposables An array to which a {{IDisposable}} will be added. * @return a disposable to remove the listener again. */ (listener: (e: T) => any, thisArgs?: any, disposables?: { push(disposable: Disposable): void; }): Disposable; } export declare namespace Event { function getMaxListeners(event: Event): number; function setMaxListeners(event: Event, maxListeners: N): N; function addMaxListeners(event: Event, add: number): number; const None: Event; /** * Given an event and a `map` function, returns another event which maps each element * through the mapping function. */ function map(event: Event, mapFunc: (i: I) => O): Event; } type Callback = (...args: any[]) => any; export declare class CallbackList implements Iterable { private _callbacks; private _contexts; readonly length: number; add(callback: Function, context?: any, bucket?: Disposable[]): void; remove(callback: Function, context?: any): void; [Symbol.iterator](): IterableIterator<(...args: any[]) => any>; invoke(...args: any[]): any[]; isEmpty(): boolean; dispose(): void; } export interface EmitterOptions { onFirstListenerAdd?: Function; onLastListenerRemove?: Function; } export declare class Emitter { private _options?; private static LEAK_WARNING_THRESHHOLD; private static _noop; private _event; protected _callbacks: CallbackList | undefined; private _disposed; private _leakingStacks; private _leakWarnCountdown; constructor(_options?: EmitterOptions); /** * For the public to allow to subscribe * to events from this Emitter */ readonly event: Event; protected checkMaxListeners(maxListeners: number): (() => void) | undefined; protected pushLeakingStack(): () => void; protected popLeakingStack(stack: string): void; /** * To be kept private to fire an event to * subscribers */ fire(event: T): any; /** * Process each listener one by one. * Return `false` to stop iterating over the listeners, `true` to continue. */ sequence(processor: (listener: (e: T) => any) => MaybePromise): Promise; dispose(): void; } export interface WaitUntilEvent { /** * Allows to pause the event loop until the provided thenable resolved. * * *Note:* It can only be called during event dispatch and not in an asynchronous manner * * @param thenable A thenable that delays execution. */ waitUntil(thenable: Promise): void; } export declare namespace WaitUntilEvent { /** * Fire all listeners in the same tick. * * Use `AsyncEmitter.fire` to fire listeners async one after another. */ function fire(emitter: Emitter, event: Omit, timeout?: number | undefined): Promise; } export declare class AsyncEmitter extends Emitter { protected deliveryQueue: Promise | undefined; /** * Fire listeners async one after another. */ fire(event: Omit, token?: CancellationToken, promiseJoin?: (p: Promise, listener: Function) => Promise): Promise; protected deliver(listeners: Callback[], event: Omit, token: CancellationToken, promiseJoin?: (p: Promise, listener: Function) => Promise): Promise; } export {};