Constructs a new TaskRunner.
The following options can be provided:
maxConcurrentTask
: Max number of task executed concurrently. Extra tasks will be queued and
executed when there will be room available.
Private
_activePrivate
_lastWe group event sources into this sub-object to make the code more readable.
Emits an event any time the TaskRunner completes all pending tasks and has nothing left to do.
Emits an event any time a task is completed. The only argument given is the completed task itself.
Emits an event any time a task throws an error. The first argument given is the task itself while the second the thrown error.
Options passed to the constructor after applying default values.
Pending tasks.
Private
_spawnGenerated using TypeDoc
Runs a list of tasks one with the configured concurrency. When
maxConcurrentTask
is set to 1 this class behaves like a task queue. You can obtain info about tasks by listening to the events exposed by this class. See theevents
property for more information.Example
In this example we simulate fetching 30 different people from an API. We simulated random fetching time that, by running the example, will result in out-of-order fetching.