Registry / devops / workq
library3.0.0jsnpmunverified

A super tiny work queue for Node.js (v3.0.0, stable). It guarantees ordered execution, supports nested queues, and runs automatically when jobs are added. Works with async/await and promises. Features a drain hook for completion and optional singletons for shared queues across files. Current version requires Node >=10. Lightweight alternative to async.queue or bull with minimal API surface.

npm install workq
INSTALL
IMPORT
SIG · WORKQ
W
workq
devopsjavascriptv3.0.0
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.

workq
import workq from 'workq'
const { workq } = require('workq')
Default export is a factory function that returns a queue instance. ESM-only since v3.
workq (CommonJS)
const workq = require('workq')
const { default: workq } = require('workq')
CommonJS require still works but is deprecated. Prefer ESM import.
Queue instance methods
const q = workq(); q.add(job); q.drain(cb); q.child()
new workq()
workq is a factory, not a constructor. Call it as a function to create a queue.

Shows creating a queue, adding jobs with callbacks (including nested), async/await, and drain hook.

import workq from 'workq'; const q = workq(); q.add((child, done) => { console.log('First job'); child.add((child2, done2) => { console.log('Nested job'); done2(); }); done(); }); q.add(async (child) => { console.log('Second job (async)'); await someAsyncWork(); // no need to call done }); q.drain(() => { console.log('All jobs finished'); }); async function someAsyncWork() { return new Promise(resolve => setTimeout(resolve, 100)); }
Debug
Known issues
breakingESM-only since v3: Module not found, require() of ES Module not supported.
fix
Use import instead of require(), or downgrade to v2.x if you must use CommonJS.
affects: >=3.0.0
deprecatedCommonJS require() via const workq = require('workq') still works but may be removed in future.
fix
Switch to ESM import: import workq from 'workq'.
affects: >=2.0.0
gotchaCalling done() prevents adding more jobs to the current queue. Attempting to add after done will throw.
fix
Only call done() when you are finished adding child jobs. Use child queues if needed.
affects: >=1.0.0
gotchaDrain hook can be called multiple times on the top-level queue if new jobs are added after drain.
fix
Make sure drain callback is idempotent or guard against multiple invocations.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: workq is not a function
Using default import with CommonJS require incorrectly.
fix
Use `const workq = require('workq')` for CommonJS or switch to ESM: `import workq from 'workq'`.
ERR_REQUIRE_ESM: require() of ES Module
Using require() with v3+ which is ESM-only.
fix
Use `import workq from 'workq'` or downgrade to v2.x.
Error: cannot add job, current queue is finished
Calling q.add() or child.add() after done() has been called for that queue.
fix
Ensure all jobs are added before calling done(), or use child queues for additional nested jobs.
Upgrade
Version history
3.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
13 hits · last 30 days
node
12
Resources
packageworkq
workq — npm install workq · libregistry