1 | import { Disposable, DisposableGroup } from './disposable';
|
2 | import { MaybePromise } from './types';
|
3 |
|
4 |
|
5 |
|
6 | export interface Event<T> {
|
7 | |
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | (listener: (e: T) => any, thisArgs?: any, disposables?: DisposableGroup): Disposable;
|
15 | }
|
16 | export declare namespace Event {
|
17 | function getMaxListeners(event: Event<unknown>): number;
|
18 | function setMaxListeners<N extends number>(event: Event<unknown>, maxListeners: N): N;
|
19 | function addMaxListeners(event: Event<unknown>, add: number): number;
|
20 | const None: Event<any>;
|
21 | |
22 |
|
23 |
|
24 | function once<T>(event: Event<T>): Event<T>;
|
25 | function toPromise<T>(event: Event<T>): Promise<T>;
|
26 | |
27 |
|
28 |
|
29 |
|
30 | function map<I, O>(event: Event<I>, mapFunc: (i: I) => O): Event<O>;
|
31 | |
32 |
|
33 |
|
34 | function any<T>(...events: Event<T>[]): Event<T>;
|
35 | function any(...events: Event<any>[]): Event<void>;
|
36 | }
|
37 | declare type Callback = (...args: any[]) => any;
|
38 | declare class CallbackList implements Iterable<Callback> {
|
39 | private _callbacks;
|
40 | private _contexts;
|
41 | get length(): number;
|
42 | add(callback: Function, context?: any, bucket?: Disposable[]): void;
|
43 | remove(callback: Function, context?: any): void;
|
44 | [Symbol.iterator](): IterableIterator<(...args: any[]) => any>;
|
45 | invoke(...args: any[]): any[];
|
46 | isEmpty(): boolean;
|
47 | dispose(): void;
|
48 | }
|
49 | export interface EmitterOptions {
|
50 | onFirstListenerAdd?: Function;
|
51 | onLastListenerRemove?: Function;
|
52 | }
|
53 | export declare class Emitter<T = any> {
|
54 | private _options?;
|
55 | private static LEAK_WARNING_THRESHHOLD;
|
56 | private static _noop;
|
57 | private _event;
|
58 | protected _callbacks: CallbackList | undefined;
|
59 | private _disposed;
|
60 | private _leakingStacks;
|
61 | private _leakWarnCountdown;
|
62 | constructor(_options?: EmitterOptions | undefined);
|
63 | /**
|
64 | * For the public to allow to subscribe
|
65 | * to events from this Emitter
|
66 | */
|
67 | get event(): Event<T>;
|
68 | protected checkMaxListeners(maxListeners: number): (() => void) | undefined;
|
69 | protected pushLeakingStack(): () => void;
|
70 | protected popLeakingStack(stack: string): void;
|
71 | /**
|
72 | * To be kept private to fire an event to
|
73 | * subscribers
|
74 | */
|
75 | fire(event: T): any;
|
76 | /**
|
77 | * Process each listener one by one.
|
78 | * Return `false` to stop iterating over the listeners, `true` to continue.
|
79 | */
|
80 | sequence(processor: (listener: (e: T) => any) => MaybePromise<boolean>): Promise<void>;
|
81 | dispose(): void;
|
82 | }
|
83 | export declare type WaitUntilData<T> = Omit<T, 'waitUntil' | 'token'>;
|
84 | export interface WaitUntilEvent {
|
85 | |
86 |
|
87 |
|
88 | token: CancellationToken;
|
89 | |
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 | waitUntil(thenable: Promise<any>): void;
|
97 | }
|
98 | export declare namespace WaitUntilEvent {
|
99 | |
100 |
|
101 |
|
102 |
|
103 |
|
104 | function fire<T extends WaitUntilEvent>(emitter: Emitter<T>, event: WaitUntilData<T>, timeout?: number, token?: CancellationToken): Promise<void>;
|
105 | }
|
106 | import { CancellationToken } from './cancellation';
|
107 | export declare class AsyncEmitter<T extends WaitUntilEvent> extends Emitter<T> {
|
108 | protected deliveryQueue: Promise<void> | undefined;
|
109 | |
110 |
|
111 |
|
112 | fire(event: WaitUntilData<T>, token?: CancellationToken, promiseJoin?: (p: Promise<any>, listener: Function) => Promise<any>): Promise<void>;
|
113 | protected deliver(listeners: Callback[], event: WaitUntilData<T>, token: CancellationToken, promiseJoin?: (p: Promise<any>, listener: Function) => Promise<any>): Promise<void>;
|
114 | }
|
115 | export {};
|
116 |
|
\ | No newline at end of file |