UNPKG

@shutterstock/p-map-iterable

Version:

Set of classes used for async prefetching with backpressure (IterableMapper) and async flushing with backpressure (IterableQueueMapper, IterableQueueMapperSimple)

38 lines 994 B
"use strict"; // // 2021-08-27 - Based on simple example here: https://www.telerik.com/blogs/stack-queue-javascript // Object.defineProperty(exports, "__esModule", { value: true }); exports.Queue = void 0; /** * A simple queue implementation. * * @category Low-Level */ class Queue { constructor() { this._queue = {}; this._tail = 0; this._head = 0; } get length() { return this._tail - this._head; } // Add an element to the end of the queue. enqueue(element) { if (element === undefined) { throw new TypeError('cannot enqueue `undefined`'); } this._queue[this._tail++] = element; } // Delete the first element of the queue. dequeue() { if (this._tail === this._head) return undefined; const element = this._queue[this._head]; delete this._queue[this._head++]; return element; } } exports.Queue = Queue; //# sourceMappingURL=queue.js.map