js-queue provides a straightforward JavaScript queue implementation for both Node.js and browser environments, featuring an 'auto-run' capability where the queue processes new items as they are added, provided it's not explicitly stopped. The current stable version is 2.0.2, with releases appearing to be made as needed for updates and fixes, rather than a strict cadence. A key differentiator is its simplicity and explicit support for both CommonJS environments (Node.js, Webpack, Browserify) and vanilla browser usage. Additionally, since version 2.0.0, it exposes an ES6-based Last In First Out (LIFO) stack via `js-queue/stack.js`, offering an alternative data structure with a similar interface, useful for different application needs.
npm install js-queueVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to create a queue, add functions to it, and ensure the queue progresses using `this.next()` within the queued functions, showcasing the auto-run behavior.
Ensure your Node.js environment is version 6 or higher if you intend to use the `easy-stack` functionality via `js-queue/stack.js`. For the core queue, compatibility remains broad.
Always include `this.next();` at the point your queued function has completed its work. If using an asynchronous operation, ensure `this.next()` is called after the async task resolves (e.g., in a callback or promise `.then()`).
Review the MIT License terms to ensure compliance with your project's legal requirements. If you require the previous DBAD license, you must explicitly use version 2.0.0 or earlier.
Instantiate the queue correctly using `const queue = new Queue();`. If in an ES module context, you might need to reconsider `js-queue` or use a bundler to handle CommonJS `require`.
Ensure that every function you add to the queue explicitly calls `this.next()` once its operation is finished, particularly for asynchronous tasks.
If in Node.js, ensure your file is treated as CommonJS (default `.js` or `type: 'commonjs'` in `package.json`). If in a browser, use the provided vanilla JS script tag method or a bundler like Webpack/Parcel/Rollup configured for CommonJS.