UNPKG

1.22 kBTypeScriptView Raw
1/** A simple queue that holds promises. */
2export declare class PromiseBuffer<T> {
3 protected _limit?: number | undefined;
4 /** Internal set of queued Promises */
5 private readonly _buffer;
6 constructor(_limit?: number | undefined);
7 /**
8 * Says if the buffer is ready to take more requests
9 */
10 isReady(): boolean;
11 /**
12 * Add a promise to the queue.
13 *
14 * @param task Can be any PromiseLike<T>
15 * @returns The original promise.
16 */
17 add(task: PromiseLike<T>): PromiseLike<T>;
18 /**
19 * Remove a promise to the queue.
20 *
21 * @param task Can be any PromiseLike<T>
22 * @returns Removed promise.
23 */
24 remove(task: PromiseLike<T>): PromiseLike<T>;
25 /**
26 * This function returns the number of unresolved promises in the queue.
27 */
28 length(): number;
29 /**
30 * This will drain the whole queue, returns true if queue is empty or drained.
31 * If timeout is provided and the queue takes longer to drain, the promise still resolves but with false.
32 *
33 * @param timeout Number in ms to wait until it resolves with false.
34 */
35 drain(timeout?: number): PromiseLike<boolean>;
36}
37//# sourceMappingURL=promisebuffer.d.ts.map
\No newline at end of file