Registry / devops / then-queue

then-queue

JSON →
library1.3.0jsnpmunverified

A simple promise-based asynchronous queue for Node.js, version 1.3.0. It provides a basic FIFO queue with push and pop methods, where pop returns a promise that resolves when an item is available. The queue length can be negative if pop is called more times than push, which may be surprising. It uses an event-driven approach (length-changed event) for managing workers. Since it is lightweight and minimal, it suits simple async workflows where a full-featured library like async.queue or bull is overkill. The package has no dependencies and is small, but is in maintenance mode with no recent updates since 2015. It does not support backpressure, concurrency limits, or persistence.

npm install then-queue
INSTALL
IMPORT
SIG · THEN-QUEUE
T
then-queue
devopsjavascriptv1.3.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.

Queue
var Queue = require('then-queue'); var q = new Queue();
import Queue from 'then-queue';
This is a CommonJS package; ESM import is not supported without a wrapper. Use require().
new Queue()
var Queue = require('then-queue'); var q = new Queue();
var q = Queue();
Queue must be instantiated with new; calling Queue() without new will cause a TypeError.
q.push
q.push(item)
q.push(item, callback)
push does not accept a callback; it returns nothing. Items are simply added.
q.pop
q.pop().then(function(item) { ... })
q.pop(callback)
pop returns a Promise; do not pass a callback. Use .then() or await.
q.length
var len = q.length;
length can be negative if pop is called more times than push.

Demonstrates creating a queue, pushing items, popping them asynchronously, and listening to the length-changed event.

var Queue = require('then-queue'); var q = new Queue(); // Push some items q.push('first'); q.push('second'); // Pop items in order q.pop().then(function(item) { console.log(item); // 'first' }); q.pop().then(function(item) { console.log(item); // 'second' }); // Listen for length changes q.on('length-changed', function() { console.log('Queue length:', q.length); }); // Push another triggers event q.push('third');
Debug
Known issues
gotchaqueue.length can be negative if pop() is called more than push() before promises resolve
fix
Monitor length carefully or ensure you push before pop.
affects: >=1.0.0
gotchaqueue.pop() returns a promise that may never resolve if no item is pushed
fix
Always ensure items are pushed eventually or use a timeout pattern.
affects: >=1.0.0
deprecatedThe package is no longer actively maintained; last update in 2015
fix
Consider migrating to modern alternatives like async.queue or bull.
affects: >=1.0.0
gotchaQueue constructor must be called with `new`; otherwise it throws TypeError
fix
Use `new Queue()` instead of `Queue()`.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: Class constructor Queue cannot be invoked without 'new'
Calling Queue() without new when using ES6 class syntax or relying on the library's error handling.
fix
Use `var q = new Queue();`
TypeError: q.pop is not a function
Trying to call pop on an undefined / non-Queue object, or wrong import.
fix
Ensure you have required and instantiated the Queue correctly.
Unhandled promise rejection: undefined
Calling q.pop() multiple times without pushing, causing unresolved promises.
fix
Only call pop after push, or implement a timeout/graceful handling.
q.on is not a function
Trying to use .on for events without checking if the library supports it (it does, but may be missing if using a custom build).
fix
Use standard Node event emitter pattern; ensure you have required 'events' if needed, but then-queue includes it.
Upgrade
Version history
1.3.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

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