queueable
Version:
Convert push-based streams to pull-based async iterables
37 lines (36 loc) • 1.08 kB
TypeScript
/**
* First-in, first-out (FIFO) buffer (queue) with default item values.
* Optionally circular based on {@link Buffer.limit}.
* Can be switched to LIFO with {@link Buffer#reverse}.
*/
export default class Buffer<A> {
#private;
/** The length after which the buffer becomes circular, i.e., discards oldest items. */
readonly limit: number;
length: number;
constructor(
/** The length after which the buffer becomes circular, i.e., discards oldest items. */
limit?: number);
/**
* Add an item to the end of the buffer.
*/
enqueue(value: A): void;
/**
* Return the oldest item from the buffer.
*/
dequeue(): A;
clear(): void;
forEach(f: (value: A) => void): void;
reverse(): this;
[Symbol.iterator](): {
next: () => {
value: A;
done: false;
} | {
done: true;
value: undefined;
};
[Symbol.iterator](): any;
};
static from<A>(iterable: Iterable<A>, limit: number): Buffer<A>;
}