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. When empty, await enqueue() will return immediately, but when concurrency items are in progress, await enqueue() will block until a slot is available to accept the item.

Remarks

Typical Use Case

  • Pushing items to an async I/O destination
  • In the simple sequential (concurrency: 1) case, allows 1 item to be flushed async while caller prepares next item
  • Results of the flushed items are not needed in a subsequent step (if they are, use IterableQueueMapper)

Error Handling

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:

  • maxUnread defaults to equal concurrency (simplifying queue management)
  • Results are automatically iterated and discarded (all work should happen in mapper)
  • Errors are collected rather than thrown (available via errors property)

Usage

  • 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
  • IMPORTANT: Always await onIdle() to ensure all items are processed

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

See

Type Parameters

  • Element

Hierarchy

  • IterableQueueMapperSimple

Constructors

  • Create a new IterableQueueMapperSimple, which uses IterableQueueMapper underneath, but automatically iterates and discards results as they complete.

    Type Parameters

    • Element

    Parameters

    • mapper: Mapper<Element, void>

      Function called for every enqueued item. Returns a Promise or value.

    • options: IterableQueueMapperSimpleOptions = {}

      IterableQueueMapperSimple options

    Returns IterableQueueMapperSimple<Element>

    See

Properties

_done: Promise<void>
_errors: Errors<Element> = []
_isIdle: boolean = false
_mapper: Mapper<Element, void>
_writer: IterableQueueMapper<Element, typeof NoResult>

Accessors

  • get errors(): Errors<Element>
  • Accumulated errors from background mapperss

    Returns Errors<Element>

    Reference to the errors array

    Remarks

    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 if all background mappers have finished.

    Returns boolean

    true if .onIdle() has been called and finished all background writes

Methods

  • Accept a request for sending in the background if a concurrency slot is available. Else, do not return until a concurrency slot is freed up. This provides concurrency background writes with backpressure to prevent the caller from getting too far ahead.

    MUST await onIdle for background mapperss to finish

    Parameters

    • item: Element

    Returns Promise<void>

  • Wait for all background mappers to finish. MUST be called before exit to ensure no lost writes.

    Returns Promise<void>

Generated using TypeDoc