Create a new IterableQueueMapperSimple
, which uses IterableQueueMapper
underneath, but
automatically iterates and discards results as they complete.
Function called for every enqueued item. Returns a Promise
or value.
IterableQueueMapperSimple options
Private
Readonly
_donePrivate
Readonly
_errorsPrivate
_isPrivate
Readonly
_mapperPrivate
Readonly
_writerAccumulated errors from background mappers
s
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.
Indicates if all background mapper
s have finished.
true if .onIdle() has been called and finished all background writes
Private
discardAccept 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 mappers
s to finish
Private
workerGenerated using TypeDoc
Accepts queue items via
enqueue
and calls themapper
on them with specifiedconcurrency
, discards the results, and accumulates exceptions in theerrors
property. When empty,await enqueue()
will return immediately, but whenconcurrency
items are in progress,await enqueue()
will block until a slot is available to accept the item.Remarks
Typical Use Case
concurrency: 1
) case, allows 1 item to be flushed async while caller prepares next itemIterableQueueMapper
)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:
errors
propertyerrors
propertyKey Differences from
IterableQueueMapper
:maxUnread
defaults to equalconcurrency
(simplifying queue management)Usage
await enqueue()
methoderrors
property to see if any errors occurred, stop if desiredawait enqueue()
method will block until a slot is available, if queue is fullawait onIdle()
to ensure all items are processedNote: the name is somewhat of a misnomer as this wraps
IterableQueueMapper
but is not itself anIterable
.See