Docs (4.0.0)
class AsyncTaskQueue method

add

Adds a task to be run asynchronously.

add(f: (t: AsyncTaskQueue.Task) => Promise<void> | void, priority?: number): this

Summary

The provided function will be called (while the queue isn’t paused), after other tasks in the queue have finished. There’s no need to schedule execution or use the run method to start the task.

If the function throws an error (or returns a promise that’s rejected), the error is logged or otherwise handled globally — unless AsyncTaskQueue.Options.catchErrors is set, in which case all errors are added to the errors array.

The provided function is invoked with a single argument that represents the task itself. This AsyncTaskQueue.Task object contains a reference to the queue, as well as a cancelled property that’s set to true when the queue is stopped or the task has timed out.

Parameters

  • f — The function to be invoked, may be asynchronous
  • priority — A number that specifies the priority of this task (a higher number deprioritizes a task, keeping it at the end of the queue)

Related