1.0.1 • Published 5 years ago
@jorygu/concurrency-limit v1.0.1
Install
npm install @jorygu/concurrency-limit
Usage
This package exports a single function limit(numWorkers, promises)
that takes 2 parameters: numWorkers
takes the number of concurrent processes you would like to limit your process to, and promises
takes an array of promises that you would like to process. Please note that the order of these promises is not preserved. Function will not return until all promises have been resolved.
const { limit } = require('@jorygu/concurrency-limit');
const myPromise = (n, i) => new Promise(resolve => setTimeout(() => {
resolve(`Promise and index ${i} finshed executing.`);
}, n));
const promises = [];
for (let i = 0; i < 50; i++) {
promises.push(myPromise(Math.floor(Math.random() * 5000), i));
}
limit(40, promises)
.then(res => console.log(res));