Release inline
queue.add(function(){
updateCache();
this.next();
});Five-minute path
Install one package, create one queue, and make each task explicitly release the next.
1 · Install
Node.js 22.13 or newer can consume the runtime through ESM or CommonJS. No compiler, transpiler, or bundler is required.
npm install js-queue2 · Create
add() validates the complete batch, appends it, and starts the front item when the queue is idle, not stopped, and configured to auto-run.
import Queue from 'js-queue';
const queue=new Queue;
queue.add(
function(){
console.log('prepare');
this.next();
},
function(){
console.log('send');
this.next();
},
function(){
console.log('record');
this.next();
}
);An arrow function keeps its surrounding this; it does not receive the queue binding.
3 · Release
js-queue never treats a return value or promise as an automatic completion signal. Call this.next() at the exact release point.
queue.add(function(){
updateCache();
this.next();
});queue.add(function(){
saveRecord()
.finally(()=>this.next());
});Ready for stop gates, error recovery, and real async coordination?
Open patterns