Skip to content

AsyncJobQueue

In‑process async job queue with configurable concurrency. Jobs are enqueued and processed in parallel up to the given limit.

// Create a queue that runs up to 2 jobs at a time
const queue = new AsyncJobQueue(2);
// Enqueue multiple async tasks
for (let i = 1; i <= 5; i++) {
queue.enqueue(async () => {
console.log(`Job ${i} starting`);
// simulate work
await new Promise(res => setTimeout(res, 500));
console.log(`Job ${i} done`);
});
}
// Wait for all jobs to finish
await queue.drain();
console.log('All jobs completed');

new AsyncJobQueue(concurrency): AsyncJobQueue

number = 1

Maximum number of jobs to run in parallel. Minimum 1.

AsyncJobQueue

get length(): number

Number of jobs still waiting in the queue.

number

drain(): Promise<void>

Wait until all currently enqueued and in‑flight jobs have completed.

Promise<void>


enqueue(job): void

Add a new job to the queue and trigger processing.

() => Promise<void>

A function returning a Promise; its resolution signals job completion.

void