Skip to content

Instantly share code, notes, and snippets.

@ppg
Created March 24, 2016 18:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ppg/907c3ed8769e7f49b14f to your computer and use it in GitHub Desktop.
Save ppg/907c3ed8769e7f49b14f to your computer and use it in GitHub Desktop.
Tests async.parallelLimit to see how it behaves
var async = require('async');
var tasks = [];
for (var i = 0; i < 25; i++) {
(function(i) {
if (i % 2 === 0) {
tasks.push(function(cb) {
console.log('Start ' + i.toString() + ' - fast');
setTimeout(function() {
console.log('Finish ' + i.toString() + ' - fast');
cb();
}, 100);
});
} else {
tasks.push(function(cb) {
console.log('Start ' + i.toString() + ' - slow');
setTimeout(function() {
console.log('Finish ' + i.toString() + ' - slow');
cb();
}, 500);
});
}
})(i);
}
async.parallelLimit(tasks, 5, function(err) {
console.log('done with tasks', err);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment