prex-es5
Version:
Async coordination primitives and extensions on top of ES6 Promises
43 lines (42 loc) • 1.47 kB
TypeScript
import "./asyncIterable";
/**
* An asynchronous queue with a bounded endpoint.
*/
export declare class AsyncBoundedQueue<T> {
private _queue;
private _state;
/**
* Initializes a new instance of the AsyncProducerConsumerQueue class.
*
* @param iterable An optional iterable of values or promises.
*/
constructor(iterable?: Iterable<T | PromiseLike<T>>);
/**
* Gets the number of entries in the queue.
* When positive, indicates the number of entries available to get.
* When negative, indicates the number of requests waiting to be fulfilled.
*/
readonly size: number;
/**
* Adds a value to the end of the queue. If the queue is empty but has a pending
* dequeue request, the value will be dequeued and the request fulfilled.
*
* @param value A value or promise to add to the queue.
*/
put(value: T | PromiseLike<T>): void;
/**
* Indicates the queue is done adding and that no more items will be added to the queue.
*/
end(): void;
/**
* Removes and returns a Promise for the first value in the queue. If the queue has
* ended, returns a Promise for `undefined`. If the queue is empty, returns a Promise
* for the next value to be added to the queue.
*/
get(): Promise<T | undefined>;
/**
* Consumes all items in the queue until the queue ends.
*/
drain(): AsyncIterableIterator<T>;
private _dequeue;
}