Created
June 4, 2020 06:56
-
-
Save velotiotech/d92e399e1752782ec9387e434afaafef to your computer and use it in GitHub Desktop.
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
// create a queue object with concurrency 2 | |
var q = async.queue(function(task, callback) { | |
console.log('Hello ' + task.name); | |
callback(); | |
}, 2); | |
// assign a callback | |
q.drain = function() { | |
console.log('All items have been processed'); | |
}; | |
// add some items to the queue | |
q.push({name: 'foo'}, function(err) { | |
console.log('Finished processing foo'); | |
}); | |
q.push({name: 'bar'}, function (err) { | |
console.log('Finished processing bar'); | |
}); | |
// add some items to the queue (batch-wise) | |
q.push([{name: 'baz'},{name: 'bay'},{name: 'bax'}], function(err) { | |
console.log('Finished processing item'); | |
}); | |
// add some items to the front of the queue | |
q.unshift({name: 'bar'}, function (err) { | |
console.log('Finished processing bar'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment