Skip to content

Commit

Permalink
Merge pull request #1 from marcolino/marcolino-patch-readme-waterfall…
Browse files Browse the repository at this point in the history
…-more-examples

Update README.md
  • Loading branch information
marcolino committed Dec 15, 2015
2 parents f9f6204 + 5937fbd commit a0598d0
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down

0 comments on commit a0598d0

Please sign in to comment.