Class IterableQueueMapperSimple<Element>

Accepts queue items via enqueue and calls the mapper on them with specified concurrency, storing the mapper result in a queue of specified max size, before being iterated / read by the caller. The enqueue method will block if the queue is full, until an item is read.

Remarks

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

Accepts items for mapping in the background, discards the results, but accumulates exceptions in the errors property.

Allows up to concurrency mappers to be in progress before enqueue will block until a mapper completes.

Type Parameters

  • Element

Hierarchy

  • IterableQueueMapperSimple

Constructors

  • Create a new IterableQueueMapperSimple

    Type Parameters

    • Element

    Parameters

    • mapper: Mapper<Element, void>

      Function which is called for every item in input. Expected to return a Promise or value.

      The mapper should handle all errors and not allow an error to be thrown out of the mapper function as this enables the best handling of errors closest to the time that they occur.

      If the mapper function does allow an error to be thrown then the errors will be accumulated in the errors property.

    • options: {
          concurrency?: number;
      } = {}

      IterableQueueMapperSimple options

      • Optional concurrency?: number

        Number of items to accept for mapping before requiring the caller to wait for one to complete.

        Default

        4
        

    Returns IterableQueueMapperSimple<Element>

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 back pressure 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