@shutterstock/p-map-iterable
    Preparing search index...

    Class IterableQueueMapperSimple<Element>

    Accepts queue items via enqueue and calls the mapper on them with specified concurrency, discards the results, and accumulates exceptions in the errors property. Await enqueue() for producer backpressure while the worker callback runs asynchronously.

    Also exported as WorkerQueue, with the same constructor and instance types. Each input uses the same worker callback supplied at construction. Asynchronous work overlaps in the current JavaScript process, and results are consumed internally.

    • Running background status checks or other queued work through a fixed callback
    • Sending items to an async I/O destination
    • Processing items whose return values can be discarded (if results are needed, use IterableQueueMapper / MappingQueue)

    The mapper should ideally handle all errors internally to enable error handling closest to where they occur. However, if errors do escape the mapper:

    • Processing continues despite errors
    • All errors are collected in the errors property
    • Errors can be checked/handled during processing via the errors property

    Key Differences from IterableQueueMapper:

    • The internal maxUnread limit equals concurrency; only concurrency is configurable
    • Results are automatically iterated and discarded (all work should happen in mapper)
    • Errors are collected rather than thrown (available via errors property)
    • Items are added to the queue via the await enqueue() method
    • Check errors property to see if any errors occurred, stop if desired
    • IMPORTANT: await enqueue() method will block until a slot is available, if queue is full
    • After the last awaited enqueue, await onIdle() to close input permanently and finish accepted work
    • Subsequent enqueues reject, so onIdle() is a final shutdown operation
    • Worker failures are collected in errors; they do not reject onIdle()
    • Await each enqueue for producer backpressure; unawaited calls can accumulate pending inputs
    • Admission limits for event callbacks, cancellation, and per-item completion handles belong to the caller

    Note: the name is somewhat of a misnomer as this wraps IterableQueueMapper but is not itself an Iterable.

    Type Parameters

    • Element
    Index
    • get errors(): Errors<Element>

      Accumulated errors from the worker callback.

      Returns Errors<Element>

      Reference to the errors array

      Note that this property can be periodically checked during processing and errors can be .pop()'d off of the array and logged / handled as desired. Errors .pop()'d off of the array will no longer be available in the array on the next check.

    • get isIdle(): boolean

      Indicates whether final shutdown has completed.

      Returns boolean

      true after onIdle() has finished all accepted work and closed input

    • Accept an input for the worker callback, waiting until it can be accepted. Resolves on acceptance, rather than completion of this item's work. Await each enqueue for producer backpressure.

      After the last enqueue, await onIdle() to close input and finish accepted work.

      Parameters

      • item: Element

        Input for the worker callback

      Returns Promise<void>

    • Permanently close input and wait for all accepted work to finish. Call after the last awaited enqueue. Subsequent enqueues reject. Worker failures are available in errors instead of rejecting this wait.

      Returns Promise<void>