Skip to main content

Class: AsyncQueue

The AsyncQueue class used to sequentialize burst requests

Constructors​

new AsyncQueue()​

new AsyncQueue(): AsyncQueue

Returns​

AsyncQueue

Properties​

promises​

private readonly promises: AsyncQueueEntry[] = []

The promises array

Defined in​

AsyncQueue.ts:26

Accessors​

queued​

Get Signature​

get queued(): number

The amount of queued entries.

Seealso​

remaining for the count with the head.

Returns​

number

Defined in​

AsyncQueue.ts:19


remaining​

Get Signature​

get remaining(): number

The amount of entries in the queue, including the head.

Seealso​

queued for the queued count.

Returns​

number

Defined in​

AsyncQueue.ts:11

Methods​

abortAll()​

abortAll(): void

Aborts all the pending promises.

Returns​

void

Note​

To avoid race conditions, this does not unlock the head lock.

Defined in​

AsyncQueue.ts:83


shift()​

shift(): void

Unlocks the head lock and transfers the next lock (if any) to the head.

Returns​

void

Defined in​

AsyncQueue.ts:65


wait()​

wait(options?: Readonly<AsyncQueueWaitOptions>): Promise<void>

Waits for last promise and queues a new one

Parameters​

ParameterType
options?Readonly<AsyncQueueWaitOptions>

Returns​

Promise<void>

Example​

const queue = new AsyncQueue();
async function request(url, options) {
await queue.wait({ signal: options.signal });
try {
const result = await fetch(url, options);
// Do some operations with 'result'
} finally {
// Remove first entry from the queue and resolve for the next entry
queue.shift();
}
}

request(someUrl1, someOptions1); // Will call fetch() immediately
request(someUrl2, someOptions2); // Will call fetch() after the first finished
request(someUrl3, someOptions3); // Will call fetch() after the second finished

Defined in​

AsyncQueue.ts:49