Last active
February 11, 2019 07:40
-
-
Save tankala/220f4ab4e8a1a7427b8abf022a2a5a26 to your computer and use it in GitHub Desktop.
Async Queue Example
This file contains hidden or 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
const async = require('async'); | |
//Code for processing the task | |
var processQueue = function (message, callback) { | |
setTimeout(function() { | |
console.log(`Task ${message} completed`); | |
callback(); | |
}, 500); | |
} | |
//Queue initialization. This queue process 3 tasks at a time | |
var queue = async.queue(processQueue, 3); | |
//After all tasks completion queue process this function | |
queue.drain = function() { | |
console.log('Yuppie all tasks completed'); | |
} | |
//To add tasks to queue we are using this function. | |
var processTasks = function () { | |
for (let index = 1; index <= 10; index++) { | |
queue.push(index); | |
} | |
} | |
processTasks(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Before running this example don't forget to install the Async package. To install it use below command