From 5937fbd5e218fdb0e2175749d6303e17fd15b457 Mon Sep 17 00:00:00 2001 From: marcolino Date: Tue, 15 Dec 2015 15:26:53 +0100 Subject: [PATCH 1/3] Update README.md Added two waterfall examples: with named functions, and with named functions passing arguments to the first one. --- README.md | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/README.md b/README.md index 6c9b5eb15..4aaed0910 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'); +} +``` --------------------------------------- From 85f44689e347093f607659dceb9e73615da9caaa Mon Sep 17 00:00:00 2001 From: marcolino Date: Tue, 15 Dec 2015 15:36:37 +0100 Subject: [PATCH 2/3] updated README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4aaed0910..76148196d 100644 --- a/README.md +++ b/README.md @@ -1007,7 +1007,7 @@ function myLastFunction(arg1, callback) { } ``` -If you need to pass any argument to the first function: +Or, if you need to pass any argument to the first function: ```js async.waterfall([ async.apply(myFirstFunction, 'zero'), From a3d1e801216dcc1a75468997839e17828e7433c7 Mon Sep 17 00:00:00 2001 From: marcolino Date: Tue, 15 Dec 2015 15:45:42 +0100 Subject: [PATCH 3/3] updated README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 76148196d..fc565ce5b 100644 --- a/README.md +++ b/README.md @@ -986,6 +986,7 @@ async.waterfall([ }); ``` Or, with named functions: + ```js async.waterfall([ myFirstFunction, @@ -1008,6 +1009,7 @@ function myLastFunction(arg1, callback) { ``` Or, if you need to pass any argument to the first function: + ```js async.waterfall([ async.apply(myFirstFunction, 'zero'),