Skip to content

Instantly share code, notes, and snippets.

@Chris927
Created July 11, 2014 14:14
Show Gist options
  • Select an option

  • Save Chris927/88ba412dc3e09eba4a9e to your computer and use it in GitHub Desktop.

Select an option

Save Chris927/88ba412dc3e09eba4a9e to your computer and use it in GitHub Desktop.
// same as previous gist, but now via 'async' library
var async = require('async');
// some dummy rows
var rows = [];
for (var i = 0; i < 10000; i++) {
rows.push("this is row " + i);
}
var maxRunning = 20;
function callHandler(row, cb) {
console.log("callHandler for row: " + row);
setTimeout(function() {
cb(null);
}, 500 * Math.random());
}
async.eachLimit(rows, maxRunning, function(row, done) {
callHandler(row, function(err) {
if (err) throw new Error(err);
done();
});
}, function(err) {
if (err) throw new Error(err);
console.log('done');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment