Created
March 24, 2016 18:19
-
-
Save ppg/907c3ed8769e7f49b14f to your computer and use it in GitHub Desktop.
Tests async.parallelLimit to see how it behaves
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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