Created
June 4, 2020 06:55
-
-
Save velotiotech/81290b3e768820ac03a7366c5f7feb3b 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
async.waterfall([ | |
function(callback) { | |
callback(null, 'Task 1', 'Task 2'); | |
}, | |
function(arg1, arg2, callback) { | |
// arg1 now equals 'Task 1' and arg2 now equals 'Task 2' | |
let arg3 = arg1 + ' and ' + arg2; | |
callback(null, arg3); | |
}, | |
function(arg1, callback) { | |
// arg1 now equals 'Task1 and Task2' | |
arg1 += ' completed'; | |
callback(null, arg1); | |
} | |
], function(err, result) { | |
// result now equals to 'Task1 and Task2 completed' | |
console.log(result); | |
}); | |
// Or, with named functions: | |
async.waterfall([ | |
myFirstFunction, | |
mySecondFunction, | |
myLastFunction, | |
], function(err, result) { | |
// result now equals 'Task1 and Task2 completed' | |
console.log(result); | |
}); | |
function myFirstFunction(callback) { | |
callback(null, 'Task 1', 'Task 2'); | |
} | |
function mySecondFunction(arg1, arg2, callback) { | |
// arg1 now equals 'Task 1' and arg2 now equals 'Task 2' | |
let arg3 = arg1 + ' and ' + arg2; | |
callback(null, arg3); | |
} | |
function myLastFunction(arg1, callback) { | |
// arg1 now equals 'Task1 and Task2' | |
arg1 += ' completed'; | |
callback(null, arg1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment