Priority queue for scheduling async work with a concurrency limit. Items are
sorted by priorityCallback and dispatched up to maxJobs at a time.
On this page
Properties
returns whether tasks are queued or actively running
maxJobs: number = 6
Maximum number of jobs that can run concurrently.
autoUpdate: boolean = true
If true, job runs are automatically scheduled after add and after each job completes.
priorityCallback: ( a: any, b: any ) => number | null = null
Comparator used to sort queued items. Higher-priority items should sort last
(i.e. return positive when itemA should run before itemB).
Methods
sort(): voidSorts the pending item list using priorityCallback, if set.
has( item: any ): booleanReturns whether the given item is currently queued.
add(
item: any,
// Invoked with `item` when it is dequeued; may return a Promise
callback: ( item: any ) => Promise<any> | any
): Promise<any>Adds an item to the queue and returns a Promise that resolves when the item's callback completes, or rejects if the item is removed before running.
remove( item: any ): voidRemoves an item from the queue, rejecting its promise with an AbortError DOMException.
removeByFilter(
// Called with each item; return true to remove
filter: ( item: any ) => boolean
): voidRemoves all queued items for which filter returns true.
tryRunJobs(): voidImmediately attempts to dequeue and run pending jobs up to maxJobs concurrency.
flush( item: any ): Promise<any> | anyImmediately runs the callback for the given item, removing it from the queue. Does nothing if the item is not queued.
scheduleJobRun(): voidSchedules a deferred call to tryRunJobs via schedulingCallback.