Created
June 4, 2020 06:58
-
-
Save velotiotech/fed1ba482e5f17e816e345c9fb2d5fab 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 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