cm

concurrency-master

a promise concurrency manager

Showing:

Popularity

Downloads/wk

2

Maintenance

No Maintenance Data Available

Package

Dependencies

0

License

ISC

Type Definitions

Tree-Shakeable

No?

Categories

Readme

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!

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100
No reviews found
Be the first to rate

Alternatives

No alternatives found

Tutorials

No tutorials found
Add a tutorial