Registry / devops / d4c-queue

d4c-queue

JSON →
library1.7.1jsnpmunverified

A TypeScript task queue library (v1.7.1) that wraps async/promise-returning/sync functions into queue-ready functions. Supports sequential (FIFO) and concurrent execution with configurable concurrency limits. Includes ES6 builds (CommonJS and ES modules), optional decorators (@synchronized, @concurrent), sub-queues via tags, and features like inheriting errors from previous tasks, non-blocking execution, and dropping tasks when limit is reached. Fully typed, well-tested, works in Node.js (>=10) and browsers. Differences from other queues: O(1) FIFO performance, decorator support, and fine-grained concurrency control via instance or class methods.

npm install d4c-queue
INSTALL
IMPORT
SIG · D4C-QUEUE
D
d4c-queue
devopsjavascriptv1.7.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.

D4C
import { D4C } from 'd4c-queue'
import D4C from 'd4c-queue'
Named export, not default. Also available via CommonJS require.
synchronized
import { synchronized } from 'd4c-queue'
import { Sync } from 'd4c-queue'
Decorator for sequential execution. Requires experimentalDecorators in TypeScript.
concurrent
import { concurrent } from 'd4c-queue'
import { Concurrent } from 'd4c-queue'
Decorator for concurrent execution. Requires experimentalDecorators.
QConcurrency
import { QConcurrency } from 'd4c-queue'
const { QConcurrency } = require('d4c-queue')
Both ES import and CommonJS require work.

Demonstrates creating a D4C queue instance, wrapping functions, and sequential vs. concurrent execution.

import { D4C } from 'd4c-queue'; // Create a D4C instance with sequential execution (default) const queue = new D4C(); // Wrap a function const myTask = queue.wrap(async (x: number) => { return x * 2; }); // Call it multiple times; they execute sequentially Promise.all([ myTask(1), myTask(2), ]).then(results => { console.log(results); // [2, 4] }); // Concurrent mode with limit 2 const concurrentQueue = new D4C({ concurrency: 2 }); const task = concurrentQueue.wrap(async (x: number) => { return x * 3; }); Promise.all([ task(1), task(2), task(3), ]).then(results => { console.log(results); // [3, 6, 9] });
Debug
Known issues
breakingv1.0.0 changed the API from callback-based to promise-based. Old code using callbacks will break.
fix
Migrate to promise-based API: use async/await or .then().
affects: <1.0.0
gotchaDecorators (@synchronized, @concurrent) require TypeScript's experimentalDecorators: true in tsconfig.json. Without it, they will not work and may cause compile errors.
fix
Add "experimentalDecorators": true to compilerOptions in tsconfig.json.
affects: >=1.0.0
gotchaThe wrap method returns a new function; the original function is not modified. Calling the original function directly bypasses the queue.
fix
Always use the wrapped function for queued execution. Store the returned function and call it.
affects: >=1.0.0
deprecatedThe previous decorator names @Synchronized and @Concurrent (capital S/C) were deprecated in v1.5.0 and removed in v1.6.0.
fix
Use @synchronized and @concurrent (lowercase) instead.
affects: >=1.5.0 <1.6.0
Errors
Common errors & fixes
TypeError: Class constructor D4C cannot be invoked without 'new'
Using D4C as a function without 'new' keyword.
fix
Use 'new D4C()' to create an instance.
TS1254: A 'super' call must be a root-level ternary expression
Decorator syntax error when using @synchronized on a class method without correct experimentalDecorators setting.
fix
Enable 'experimentalDecorators' in tsconfig.json and ensure target >= ES5.
Error: QueueIsFull
Calling a wrapped function when dropWhenReachLimit is true and concurrency limit is reached.
fix
Catch the error and handle gracefully, or increase concurrency limit, or avoid dropping by setting dropWhenReachLimit to false.
Upgrade
Version history
1.7.1latest on npm
Audit
Dependencies
@babel/plugin-proposal-decoratorsoptionalRequired for JavaScript users who want to use decorators; not needed for TypeScript.
Agent activity
7 hits · last 30 days
node
4
Resources
d4c-queue — npm install d4c-queue · libregistry