The number of queued items waiting to run.
The number of items currently running.
Size of the queue including running items
Abort all jobs in the queue and clear it
Adds a sync or async task to the queue. Always returns a promise.
Optional
options: JobOptionsAppends an event listener for events whose type attribute value is type. The callback argument sets the callback that will be invoked when the event is dispatched.
The options argument sets listener-specific options. For compatibility this can be a boolean, in which case the method behaves exactly as if the value was specified as options's capture.
When set to true, options's capture prevents callback from being invoked when the event's eventPhase attribute value is BUBBLING_PHASE. When false (or not present), callback will not be invoked when event's eventPhase attribute value is CAPTURING_PHASE. Either way, callback will be invoked if event's eventPhase attribute value is AT_TARGET.
When set to true, options's passive indicates that the callback will not cancel the event by invoking preventDefault(). This is used to enable performance optimizations described in § 2.8 Observing event listeners.
When set to true, options's once indicates that the callback will only be invoked once after which the event listener will be removed.
If an AbortSignal is passed for options's signal, then the event listener will be removed when signal is aborted.
The event listener is appended to target's event listener list and is not appended if it has the same type, callback, and capture.
Optional
options: boolean | AddEventListenerOptionsClear the queue
Dispatches a synthetic event event to target and returns true if either event's cancelable attribute value is false or its preventDefault() method was not invoked, and false otherwise.
Can be called multiple times. Useful if you for example add additional items at a later time.
Optional
options: AbortOptionsA promise that settles when the queue becomes empty.
The difference with .onEmpty
is that .onIdle
guarantees that all work
from the queue has finished. .onEmpty
merely signals that the queue is
empty, but it could mean that some promises haven't completed yet.
Optional
options: AbortOptionsA promise that settles when the queue becomes empty, and all
promises have completed; queue.size === 0 && queue.pending === 0
.
Optional
options: AbortOptionsA promise that settles when the queue size is less than the given
limit: queue.size < limit
.
If you want to avoid having the queue grow beyond a certain size you can
await queue.onSizeLessThan()
before adding a new item.
Note that this only limits the number of items waiting to start. There
could still be up to concurrency
jobs already running that this call does
not include in its calculation.
Removes the event listener in target's event listener list with the same type, callback, and options.
Optional
listener: null | EventHandler<QueueEvents<JobReturnType, JobOptions>[K]>Optional
options: boolean | EventListenerOptionsOptional
detail: CustomEventInit<Detail>Returns an async generator that makes it easy to iterate over the results of jobs added to the queue.
The generator will end when the queue becomes idle, that is there are no jobs running and no jobs that have yet to run.
If you need to keep the queue open indefinitely, consider using it-pushable instead.
Optional
options: AbortOptions
Heavily influence by
p-queue
with the following differences:queue.size
includesqueue.pending
items - this is so interested parties can join the results of a queue item while it is running