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(["[email protected]","[email protected]"]);
// add email to the front of the queue
q.unshift("[email protected]");
//output
/*
Sending email to [email protected]
Sending email to [email protected]
Sending email to [email protected]
all emails sent
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment