Skip to content

Instantly share code, notes, and snippets.

@sahas-
Created August 31, 2016 22:09
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 sahas-/b7cccf72915daec08b77ee29d9ce5238 to your computer and use it in GitHub Desktop.
Save sahas-/b7cccf72915daec08b77ee29d9ce5238 to your computer and use it in GitHub Desktop.
var queue = require('queue');
var input = [1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13];
var q = queue();
q.concurrency = 1;
function test(element) {
return (function (cb) {
setTimeout(function() {
console.log(element);
cb();
}, Math.random()*2000);
});
}
input.forEach(function (element) {
var _test = test(element);
q.push(_test);
}, this);
q.on('end', function () {
console.log("all done");
})
q.on('success', function (result, job) {
console.log('job finished processing:');
});
q.start();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment