diff options
author | Alexander Early <alexander.early@gmail.com> | 2016-01-07 14:56:48 -0800 |
---|---|---|
committer | Alexander Early <alexander.early@gmail.com> | 2016-01-07 14:56:48 -0800 |
commit | 87fdf85f097d8a55d25eb745e5615344bc453c3a (patch) | |
tree | d5ad9aa440434fc4e8fc6d913d9ddaf10442de56 | |
parent | ed308256f5810ea015bb7673bcfe3d29545786ff (diff) | |
parent | a3d1e801216dcc1a75468997839e17828e7433c7 (diff) | |
download | async-87fdf85f097d8a55d25eb745e5615344bc453c3a.tar.gz |
Merge pull request #979 from marcolino/master
Updated README.md
-rw-r--r-- | README.md | 46 |
1 files changed, 46 insertions, 0 deletions
@@ -985,6 +985,52 @@ async.waterfall([ // result now equals 'done' }); ``` +Or, with named functions: + +```js +async.waterfall([ + myFirstFunction, + mySecondFunction, + myLastFunction, +], function (err, result) { + // result now equals 'done' +}); +function myFirstFunction(callback) { + callback(null, 'one', 'two'); +} +function mySecondFunction(arg1, arg2, callback) { + // arg1 now equals 'one' and arg2 now equals 'two' + callback(null, 'three'); +} +function myLastFunction(arg1, callback) { + // arg1 now equals 'three' + callback(null, 'done'); +} +``` + +Or, if you need to pass any argument to the first function: + +```js +async.waterfall([ + async.apply(myFirstFunction, 'zero'), + mySecondFunction, + myLastFunction, +], function (err, result) { + // result now equals 'done' +}); +function myFirstFunction(arg1, callback) { + // arg1 now equals 'zero' + callback(null, 'one', 'two'); +} +function mySecondFunction(arg1, arg2, callback) { + // arg1 now equals 'one' and arg2 now equals 'two' + callback(null, 'three'); +} +function myLastFunction(arg1, callback) { + // arg1 now equals 'three' + callback(null, 'done'); +} +``` --------------------------------------- <a name="compose" /> |