Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

concurrency-master

Package Overview
Dependencies
Maintainers
3
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

concurrency-master

a promise concurrency manager

  • 0.1.1
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
2
Maintainers
3
Weekly downloads
 
Created
Source

Concurrency Master

The Concurrency Master is a lightweight promise-based task scheduler. Initialize it with a concurrency value, then call its add method on functions that return Promises. The ConcurrencyMaster will execute all the given promise-returning functions. In doing so, it will make sure that no more than its given concurrency are running in parallel.

The wait() method returns a Promise that resolves when all of the ConcurrencyMaster's added Promises have resolved.

Example

var ConcurrencyMaster = require('concurrency-master');

function waitOneSecondAndLog() {
    return new Promise((resolve, reject) => {
        setTimeout(() => {
            console.log('Hey!');
            resolve();
        }, 1000);
    });    
}

var concurrencyMaster = new ConcurrencyMaster(2);
concurrencyMaster.add(waitOneSecondAndLog);
concurrencyMaster.add(waitOneSecondAndLog);
concurrencyMaster.add(waitOneSecondAndLog);
concurrencyMaster.wait().then(() => {
    console.log('all done!');
});

The ConcurrencyMaster in this example has a concurrency of 2, so after one second, you'll see two Hey! messages. After another second, you'll see the third Hey! message, then all done!. Sweet!

Keywords

FAQs

Package last updated on 11 Feb 2016

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