Constructs a new AsyncTaskQueue. The new instance will initially not be in paused state.
The number of tasks that can be executing simultaneously.
A function responsible for executing tasks scheduled with scheduleDefaultTask
. Pass null to not specify any default task.
Destroys this queue, immediately rejecting any queued tasks with the provided reason. Tasks that are currently executing are allowed to complete.
Calling scheduleDefaultTask
or scheduleTask
after this method has been called will result in the returned promise
to be rejected immediately with the specified reason
The object that should be used for rejecting queued tasks.
Gets the number of tasks that are currently running/executing.
Gets the number of tasks that are queued for execution sometime in the future.
If this instance has been destroyed. See destroy()
for the behaviour when an instance is destroyed.
If this async task queue is paused.
Pauses this async task queue. No new or queued tasks will be executed while this instance is paused. Tasks that are currently executing will still run to completion.
Calling this method on an already paused instance has no effect.
Resumes this async task queue. New and queued tasks will be allowed to execute again.
Calling this method on an instance that is not paused has no effect.
Schedules the default task to run with the specified argument in the future.
The argument to pass to this instance's default task.
The priority of the task. Tasks with higher priority values will execute before tasks with lower priority value. Tasks with the same priority value will execute in FIFO order.
Schedules an async function (task) to be executed in the future.
The function that should be executed in the future.
The priority of the task. Tasks with higher priority values will execute before tasks with lower priority value. Tasks with the same priority value will execute in FIFO order.
Sets a callback function to be called just before a task is to be taken from the queue and executed. This enables the callback function to pause this instance.
Generated using TypeDoc
Allows executing async tasks with a limit on the number of tasks that is executing at the same time. This is useful for long-running tasks that potentially allocates a lot of memory, like resource fetching/decompression.
The implementation uses a priority queue for tasks. Tasks with higher priority will start executing before tasks with lower priority.
Tasks for the AsyncTaskQueue can be scheduled in two ways:
scheduleDefaultTask
with an argument that will be sent to the "defaultTask" function when the task executes.scheduleTask
with the async function that should execute sometime in the future.New and queued tasks can be prevented from starting by pausing the AsyncTaskQueue with
pause()
. To resume execution of queued tasks, callresume()
. Note that tasks that have already started executing will not be paused and are allowed to continue.