Optionalvalues: Iterable<T, any, any>Optionaloptions: AsyncQueueOptions<T>The first (next) item in the queue, or undefined when the queue is empty.
Time complexity: O(1).
Whether to route pushes to the parent queue.
Only relevant when a parent queue is set.
Set whether to route pushes to the parent queue.
Can only be set when a parent queue is set.
Whether the queue is empty.
Time complexity: O(1).
The last item in the queue, or undefined when the queue is empty.
Time complexity: O(1).
The number of values currently in the queue.
Time complexity: O(1).
The parent queue, which can be set in the constructor options.
The number of pending requests waiting for values to be added to the queue.
Time complexity: O(1).
Returns an iterator over the values in the queue from first to last.
Time complexity: O(1) to create the iterator, and O(n) for a full iteration.
Get the next item in the queue, waiting for one to be added if the queue is empty.
The item is wrapped in an AsyncQueueItemLease, which enqueues the item again when disposed.
Time complexity: O(1) amortized, with occasional O(n) compaction. Cancelling a pending request is O(n).
Optionalsignal: AbortSignalReturns the item at the given index without removing it.
Negative indexes count backwards from the end of the queue.
Time complexity: O(1).
Removes all values from the queue.
Time complexity: O(1).
Deletes values from the queue starting at start and ending before end.
When end is omitted, only the value at start is deleted.
Negative indexes count backwards from the end of the queue.
Returns the number of deleted values.
Time complexity: O(k) when deleting from either end, where k is the number of deleted values,
and O(n) when deleting from the middle.
Optionalend: numberIf a parent queue is set, moves all items from the current queue to it.
Time complexity: O(n).
Returns an iterator over index-value pairs in the queue.
Time complexity: O(n) for a full iteration and O(1) per value.
Returns the index of the first occurrence of a value in the queue, or -1 when it is not found.
Time complexity: O(n).
Returns the index of the last occurrence of a value in the queue, or -1 when it is not found.
Time complexity: O(n).
OptionalfromIndex: numberAdds an item to the end of the queue. If there is a pending request, the item is immediately delivered to the oldest pending request instead of being added to the queue.
Time complexity: O(1) amortized. O(h) to traverse the parent chain.
Reject all the pending requests with the given reason.
Time complexity: O(n), where n is the number of pending requests.
Optionalreason: unknownRemoves and returns the first (next) item in the queue, and if the queue is empty, waits for an item to be added first and then returns that item.
Time complexity: O(1) amortized without a parent, with occasional O(n) compaction.
Cancelling a pending request is O(n). O(h) to traverse the parent chain.
Optionalsignal: AbortSignalReturns the queue values as a new array.
Time complexity: O(n).
Removes and returns the first (next) value in the queue without waiting for an item to be added if the queue is empty.
Returns undefined when the queue is empty.
Time complexity: O(1) amortized without a parent, with occasional O(n) compaction.
O(h) to traverse the parent chain.
Returns an iterator over the values in the queue from first to last.
Time complexity: O(n) for a full iteration and O(1) per value.
Run a callback with the next item in the queue, and if the queue is empty, wait for an item to be added first and then run the callback with that item.
When the callback is done, the item is enqueued again.
The return value of the callback is returned to the caller.
Time complexity: O(1) amortized, with occasional O(n) compaction. Cancelling a pending request is O(n).
Run a callback with the next item in the queue, and if the queue is empty, wait for an item to be added first and then run the callback with that item.
When the callback is done, the item is enqueued again.
The return value of the callback is returned to the caller.
Time complexity: O(1) amortized, with occasional O(n) compaction. Cancelling a pending request is O(n).
An async queue that allows you to wait for items to become available when the queue is empty.
shift retrieves the first locally queued item, falling back to queues in the parent chain (if a parent is set). If no item is available, it waits until one is pushed.
When waiting, the request is registered with the current queue and all parent queues, and the first one to provide an item satisfies the request.
Pushing adds the item to the current queue, unless forwardPushesToParent is enabled.
Example
Example