Class: AsyncQueue
The AsyncQueue class used to sequentialize burst requests
Constructors
new AsyncQueue()
new AsyncQueue():
AsyncQueue
Returns
Properties
promises
private
readonly
promises:AsyncQueueEntry
[] =[]
The promises array
Defined in
Accessors
queued
Get Signature
get queued():
number
The amount of queued entries.
Seealso
remaining for the count with the head.
Returns
number
Defined in
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
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
shift()
shift():
void
Unlocks the head lock and transfers the next lock (if any) to the head.
Returns
void
Defined in
wait()
wait(
options
?:Readonly
<AsyncQueueWaitOptions
>):Promise
<void
>
Waits for last promise and queues a new one
Parameters
Parameter | Type |
---|---|
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