summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormarcolino <marcosolari@gmail.com>2015-12-15 15:26:53 +0100
committermarcolino <marcosolari@gmail.com>2015-12-15 15:26:53 +0100
commit5937fbd5e218fdb0e2175749d6303e17fd15b457 (patch)
tree54367863800eb676064f8feaca0dfdf06eb9ad3c
parentf9f62043460e16db0f5bf42045228db150590171 (diff)
downloadasync-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.md44
1 files changed, 44 insertions, 0 deletions
diff --git a/README.md b/README.md
index 6c9b5eb..4aaed09 100644
--- a/README.md
+++ b/README.md
@@ -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" />