Skip to content

Instantly share code, notes, and snippets.

@shaikh-shahid
Created April 7, 2016 07:18
Show Gist options
  • Save shaikh-shahid/ae521d86d582ee5b0db101ad55d987c7 to your computer and use it in GitHub Desktop.
Save shaikh-shahid/ae521d86d582ee5b0db101ad55d987c7 to your computer and use it in GitHub Desktop.
var async = require('async');
// Send email
var sendEmail = function(email,callback) {
console.log("Sending email to "+email);
callback(null);
}
// create a queue object with concurrency 2
var q = async.queue(sendEmail,2);
// Called when every processing is done
q.drain = function() {
console.log('all emails sent');
}
// add some emails to the queue
q.push(["rwtc66@gmail.com","shahid@codeforgeek.com"]);
// add email to the front of the queue
q.unshift("abc@gmail.com");
//output
/*
Sending email to abc@gmail.com
Sending email to rwtc66@gmail.com
Sending email to shahid@codeforgeek.com
all emails sent
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment