Socket
Socket
Sign inDemoInstall

promise-concurrency-limiter

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

promise-concurrency-limiter

Tiny scheduler for functions returning promises that can limit their concurrency.


Version published
Weekly downloads
342
decreased by-49.18%
Maintainers
1
Weekly downloads
 
Created
Source

Promise Concurrency Limiter

Tiny scheduler for functions returning promises that can limit their concurrency.

Install

npm install --save promise-concurrency-limiter

Usage

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

Deadlocks

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.

License

MIT © Fabio Spampinato

Keywords

FAQs

Package last updated on 04 Apr 2024

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc