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 1.09 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.IterableQueue = void 0; const blocking_queue_1 = require("./blocking-queue"); /** * Exposes an `AsyncIterable` interface for the `BlockingQueue`. * * @category Low-Level */ class IterableQueue extends blocking_queue_1.BlockingQueue { /** * Create a new `IterableQueue` * @param options IterableQueue options */ constructor(options = {}) { super(options); } [Symbol.asyncIterator]() { return this; } /** * Used by the iterator returned from [Symbol.asyncIterator] * Called every time an item is needed * * @returns Iterator result */ async next() { // Check if queue has an item const item = await this.dequeue(); if (item === undefined) { // We finished - There were no more items return { value: undefined, done: true }; } return { value: item, done: false }; } } exports.IterableQueue = IterableQueue; //# sourceMappingURL=iterable-queue.js.map