diff options
author | marcolino <marcosolari@gmail.com> | 2015-12-15 15:26:53 +0100 |
---|---|---|
committer | marcolino <marcosolari@gmail.com> | 2015-12-15 15:26:53 +0100 |
commit | 5937fbd5e218fdb0e2175749d6303e17fd15b457 (patch) | |
tree | 54367863800eb676064f8feaca0dfdf06eb9ad3c | |
parent | f9f62043460e16db0f5bf42045228db150590171 (diff) | |
download | async-5937fbd5e218fdb0e2175749d6303e17fd15b457.tar.gz |
Update README.md
Added two waterfall examples: with named functions, and with named functions passing arguments to the first one.
-rw-r--r-- | README.md | 44 |
1 files changed, 44 insertions, 0 deletions
@@ -985,6 +985,50 @@ 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'); +} +``` + +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" /> |