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