UNPKG

1.39 kBTypeScriptView Raw
1/*! *****************************************************************************
2Copyright (c) Microsoft Corporation.
3Licensed under the Apache License, Version 2.0.
4
5See LICENSE file in the project root for details.
6***************************************************************************** */
7/**
8 * An asynchronous queue.
9 */
10export declare class AsyncQueue<T> {
11 private _available;
12 private _pending;
13 /**
14 * Initializes a new instance of the AsyncQueue class.
15 *
16 * @param iterable An optional iterable of values or promises.
17 */
18 constructor(iterable?: Iterable<T | PromiseLike<T>>);
19 /**
20 * Gets the number of entries in the queue.
21 * When positive, indicates the number of entries available to get.
22 * When negative, indicates the number of requests waiting to be fulfilled.
23 */
24 get size(): number;
25 /**
26 * Adds a value to the end of the queue. If the queue is empty but has a pending
27 * dequeue request, the value will be dequeued and the request fulfilled.
28 *
29 * @param value A value or promise to add to the queue.
30 */
31 put(value: T | PromiseLike<T>): void;
32 /**
33 * Removes and returns a Promise for the first value in the queue. If the queue is empty,
34 * returns a Promise for the next value to be added to the queue.
35 */
36 get(): Promise<T>;
37}