Limit concurrency when running multiple promise-returning and async functions in Node.js and browsers.
p-limit is a JavaScript library that limits the concurrency of promise-returning and async functions. It solves the problem of resource exhaustion by ensuring only a specified number of tasks run simultaneously, which is crucial for managing API calls, database queries, or any async operations where uncontrolled parallelism can cause performance issues.
JavaScript developers working in Node.js or browser environments who need to manage concurrent async operations, such as handling rate-limited APIs, controlling database connection pools, or optimizing resource usage in performance-critical applications.
Developers choose p-limit for its minimalistic, focused approach to concurrency control without the overhead of full queue implementations. It's lightweight, easy to integrate, and provides essential features like queue clearing and convenience methods while maintaining cross-platform compatibility.
Run multiple promise-returning & async functions with limited concurrency
Offers a straightforward API with core functions like pLimit and limit.map, making integration quick and reducing cognitive load, as shown in the simple usage example.
Provides activeCount and pendingCount for real-time monitoring and clearQueue for cleanup, with rejectOnClear option to handle pending promises cleanly using AbortError.
Includes limit.map() for batch processing and limitFunction() for scoping concurrency to a single function, reducing boilerplate for common use cases.
Works in both Node.js and browser environments, ensuring versatility across different JavaScript runtimes without platform-specific adjustments.
The README explicitly warns that calling the same limit function inside a limited function can cause deadlocks, requiring careful design or separate limiters for nested tasks.
Lacks advanced queue features like prioritization, event emission, or pausing, making it unsuitable for complex scheduling, as acknowledged in the FAQ comparison with p-queue.
clearQueue() only discards pending promises and cannot cancel or abort promises that are already running, which may be insufficient for dynamic or error-prone environments.
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.