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
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); |
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
var async = require('async'); | |
async.forEach(someData,function(singleData,callback){ | |
async.series(); | |
//OR | |
async.paralle(); | |
//OR | |
async.waterfall(); | |
},function(err,data) { | |
// final callback |
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
var async = require('async'); | |
var emails = ["[email protected]","[email protected]"]; | |
async.each(emails,function(singleEmail,callback) { | |
async.waterfall([ | |
function(callback) { | |
// code to send email. | |
callback(null,Flag); | |
}, | |
function(emailSentOrNot,callback) { |
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
var async = require('async'); | |
var emails = ["[email protected]","[email protected]"]; | |
async.eachLimit(emails,1000,function(singleEmail,callback) { | |
// Emailer code | |
// singleEmail will be one value at a time. | |
},function(err,data) { | |
// Once all done, comes here. | |
}); |
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
var async = require('async'); | |
var emails = ["[email protected]","[email protected]"]; | |
async.each(emails,function(singleEmail,callback) { | |
// Emailer code | |
// singleEmail will be one value at a time. | |
},function(err,data) { | |
// Once all done, comes here. | |
}); |
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
var async = require('async'); | |
async.waterfall([ | |
function(callback) { | |
// some code to execute | |
// in case to go to next function provide callback like this. | |
callback(null,valueForNextFunction); | |
// Got some error ? Don't wanna go further. | |
// Provide true in callback and execution will stop. | |
//callback(true,"Some error"); |
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
var async = require('async'); | |
async.series([ | |
function(callback) { | |
// some async task | |
callback(); | |
}, | |
function(callback) { | |
// some async task | |
callback(); |
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
var async = require('async'); | |
async.parallel([ | |
function(callback) { | |
// Some Async task | |
callback(); | |
}, | |
function(callback) { | |
// Some Async task | |
callback(); |
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
var EventEmitter = require('events').EventEmitter; | |
var emitter = new EventEmitter(); | |
var fs = require('fs'); | |
// Event to read file - generic function. | |
emitter.on('start_read',function(file_name) { | |
console.log("Started Reading file....\n\n"); | |
fs.readFile(file_name, 'utf8', function (err,data) { | |
if (err) { | |
console.log("Error happens."); | |
} else { |
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
var Promise = require('bluebird'); | |
// Converts all function of 'fs' into promises. | |
var fs = Promise.promisifyAll(require('fs')); | |
fs.readFileAsync('file.js','utf8') | |
// 'then' when result comes. | |
.then(function(data) { | |
console.log(data); | |
}) | |
//'catch' when error comes. |