sb-promise-queue is a lightweight JavaScript/TypeScript utility library designed to manage and control the concurrency of asynchronous operations using a promise-based queue. Its current stable version is 2.1.1. It allows developers to specify a maximum number of promises that can run simultaneously, preventing resource exhaustion or rate-limiting issues. Key differentiators include its minimalistic and intuitive API, built-in TypeScript type definitions for enhanced developer experience, and clear methods such as `add`, `onIdle`, and `waitTillIdle` for effective task flow management. This library is particularly useful for scenarios requiring controlled execution of potentially resource-intensive async tasks, like API calls or data processing, ensuring stability and performance. While a specific release cadence is not explicitly stated, as a focused utility, updates are generally driven by bug fixes or minor enhancements rather than frequent feature additions.
npm install sb-promise-queueVerified import paths — ran on the pinned version, not inferred.
Demonstrates initializing a `PromiseQueue` with a specified concurrency, adding multiple asynchronous tasks, and then waiting for all tasks to complete before proceeding, logging their start and end.
Always ensure to `await queue.waitTillIdle()` when you need a guarantee that all tasks in the queue have finished their execution before proceeding with dependent code.
Always wrap the asynchronous logic inside your `add` callback with `try...catch` blocks or attach a `.catch()` handler to any promises returned, ensuring robust error handling for individual tasks.
For scenarios involving an exceptionally high number of tasks, consider implementing a mechanism to batch your task additions to the queue, or monitor memory usage closely to prevent resource exhaustion.
Ensure you are using the correct ES module named import: `import { PromiseQueue } from 'sb-promise-queue';`. If in a CommonJS environment, use `const { PromiseQueue } = require('sb-promise-queue');`.Modify the `async` callback passed to `queue.add()` to include error handling. For example: `queue.add(async () => { try { await someAsyncOp(); } catch (error) { console.error('Task failed:', error); } });`First, ensure the package is installed: `npm install sb-promise-queue`. If the error persists in an ES module environment (`"type": "module"` in `package.json`), verify your Node.js version supports ES modules or check for incorrect `tsconfig.json` module settings if using TypeScript.
No dependency data recorded yet.