Docs (4.0.0)
class AsyncTaskQueue method

addOrReplace

Adds a task to be run asynchronously, possibly replacing a task currently in the queue.

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

Summary

The provided function will be called just like it was provided to add(), however if a task already existed in the same queue with the same handle that task is removed first.

This mechanism can be used to implement throttling or debouncing. By providing the same handle each time and setting the throttleDelay option, only the function added last will be run, once within the specified time frame.

Parameters

  • handle — A unique handle that identifies the task to be added and/or replaced
  • 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