TaskStackAsync

Used to run many sync/async functions simultaneously, but return results in the order they were added. This utilizes TaskLimiter internally to limit the number of executed tasks. An example use case might be the need to read/preprocess many files, but needing to aggregate the results in order.

Constructor

new TaskStackAsync(listenernon-null, running_limitopt, queued_limitopt)

Create a new TaskStackAsync

Parameters:
NameTypeAttributesDefaultDescription
listenerStacklistener

listener for task results

running_limitnumber<optional>
16

number of tasks that can be running at a time (e.g. TaskLimiter#running_limit)

queued_limitnumber<optional>
Infinity

number of tasks that can be queued at a time (e.g. TaskLimiter#queued_limit)

Classes

TaskStackAsync

Members

limiter :TaskLimiter

Limiter for simultaneous running tasks

(non-null) listener :StackListener

Listener for results

Methods

(async) add(task, …args) → {Promise}

Add an ordered task to the stack

Parameters:
NameTypeAttributesDescription
taskPromise | function

Running promise or function (if promise is already running, the limit config option may not be respected)

argsany<repeatable>

Arguments to pass to the TaskStackAsync#listener (not the task!)

Returns:

a promise resolving when the underlying TaskLimiter unblocks

Type: 
Promise

empty() → {Promise}

Returns promise which resolves when stack is empty

Returns:
Type: 
Promise