Skip to content

Instantly share code, notes, and snippets.

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