Run an async task for each array element in parallel, but limit the number of tasks executing at the same time.
$ npm install --save run-each-limit
var eachLimit = require('run-each-limit');
var items = ['a', 'b', 'c', 'd'];
var result = '';
function onItem(item, fn) {
result += item;
setTimeout(fn, 200);
}
eachLimit(items, 2, onItem, function(err) {
console.log(result); // 'abcd'
});
MIT © Damian Krzeminski