A minimalist async task queue/serializer for JavaScript.
TaskQueue ensures async operations execute in FIFO (first-in, first-out) order, preventing race conditions when multiple async tasks need to be serialized.
Use directly as an ES module via jsdelivr:
import { TaskQueue } from 'https://cdn.jsdelivr.net/gh/mesgjs/task-queue/src/task-queue.esm.js';import { TaskQueue } from 'https://cdn.jsdelivr.net/gh/mesgjs/task-queue/src/task-queue.esm.js';
const queue = new TaskQueue();
// Queue async tasks
const result1 = await queue.task(async () => {
// Your async operation
return 'result';
});
const result2 = await queue.task(async () => {
// This runs after result1 completes
return 'another result';
});Creates a new task queue instance.
Queues an async function for execution.
- Parameters:
callback- Async function to execute - Returns: Promise that resolves with the callback's return value
- Throws: Rejects if the queue is shutting down
Cancels a queued task.
- Parameters:
callback- The callback function to cancel - Returns:
trueif cancelled,falseif not found
Shuts down the queue and rejects all pending operations.
Returns the number of pending operations in the queue.
See LICENSE file for details.
Copyright 2025 Kappa Computer Solutions, LLC and Brian Katzung