Registry / testing / sequential-task-queue

sequential-task-queue

JSON →
library1.2.1jsnpmunverified

FIFO task queue for Node.js and browser that executes asynchronous tasks in strict order. Version 1.2.1 is stable, with infrequent updates. Supports promises, timeouts, and task cancellation via CancellationToken. Differentiators include simple API, cancellation of queued/active tasks, and error handling that continues execution. Ships TypeScript types.

npm install sequential-task-queue
INSTALL
IMPORT
SIG · SEQUENTIAL-TASK-QU
S
sequential-task-queue
testingjavascriptv1.2.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

SequentialTaskQueue
import { SequentialTaskQueue } from 'sequential-task-queue'
const SequentialTaskQueue = require('sequential-task-queue')
ESM-only package; named export.
CancellationToken
import { CancellationToken } from 'sequential-task-queue'
Exported for type usage, but typically not imported directly.
SequentialTaskQueue type
import type { SequentialTaskQueue } from 'sequential-task-queue'
TypeScript users can import the type separately.

Create a FIFO queue and push two synchronous tasks that log in order.

import { SequentialTaskQueue } from 'sequential-task-queue'; const queue = new SequentialTaskQueue(); queue.push(() => console.log('first')); queue.push(() => console.log('second')); // Output: first, second
Debug
Known issues
gotchaCancelled tasks reject the returned promise, even if the task function does not check the CancellationToken.
fix
Always attach a .catch() handler to the promise returned by push() to handle cancellation rejections.
affects: >=1.0.0
gotchaTimeout starts when the task execution begins, not when it is queued. This can lead to longer effective wait times if the queue is long.
fix
Be aware that timeout applies only to the execution duration; queue wait time is not counted.
affects: >=1.0.0
gotchaThe queue does not stop on promise rejection; it continues to the next task. Unhandled rejections may be missed if no 'error' event listener is attached.
fix
Listen to the 'error' event: queue.on('error', (err) => console.error(err));
affects: >=1.0.0
deprecatedThe push() API previously accepted a second argument as timeout number directly. That is now deprecated in favor of an options object with timeout property.
fix
Use queue.push(task, { timeout: 1000 }) instead of queue.push(task, 1000).
affects: >=1.1.0
Errors
Common errors & fixes
TypeError: class_1.default is not a constructor
Importing a CommonJS-style require when package is ESM-only.
fix
Use `import { SequentialTaskQueue } from 'sequential-task-queue'` instead of `const SequentialTaskQueue = require('sequential-task-queue')`.
Error: Task cancelled
Cancelling a task causes the promise to reject with an error. Not catching it leads to unhandled rejection.
fix
Attach a .catch() to the push() promise, or use the 'error' event on the queue.
Upgrade
Version history
1.2.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources
sequential-task-queue — npm install sequential-task-queue · libregistry