Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
promise-concurrency-limiter
Advanced tools
Tiny scheduler for functions returning promises that can limit their concurrency.
Tiny scheduler for functions returning promises that can limit their concurrency.
npm install --save promise-concurrency-limiter
import Limiter from 'promise-concurrency-limiter';
const limiter = new Limiter ({
concurrency: 2 // Limit the number of simultaneously active promises to 2
});
const somePromiseReturningFunction = async () => { /* ... */ };
limiter.add ( somePromiseReturningFunction ); // First function added, executed immediately
limiter.add ( somePromiseReturningFunction ); // Second function added, executed immediately
limiter.add ( somePromiseReturningFunction ); // Third function added, executed immediately only if one of the 2 available slots got freed, deferred otherwise
Note that if your concurrency-limited functions can also schedule other concurrency-limited functions you can get in a deadlock situation, where if the concurrency limit is N, and you have N currently executing functions, but all of those functions need to schedule other functions before they can resolve, then nothing will happen because all the available spots are filled already, and no current function will ever resolve.
For situations like that, unless you have some assurances that a deadlock can't actually happen, this library may not be the appropriate way to limit concurrency for your use case.
MIT © Fabio Spampinato
FAQs
Tiny scheduler for functions returning promises that can limit their concurrency.
The npm package promise-concurrency-limiter receives a total of 336 weekly downloads. As such, promise-concurrency-limiter popularity was classified as not popular.
We found that promise-concurrency-limiter demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.