Create a new IterableQueueMapperSimple
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.
IterableQueueMapperSimple options
Optional
concurrency?: numberNumber of items to accept for mapping before requiring the caller to wait for one to complete.
4
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 back pressure 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 specified concurrency, storing themapper
result in a queue of specified max size, before being iterated / read by the caller. Theenqueue
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 anIterable
.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 beforeenqueue
will block until a mapper completes.