diff options
author | Hubert Argasinski <argasinski.hubert@gmail.com> | 2016-03-31 02:22:16 -0700 |
---|---|---|
committer | Graeme Yeates <yeatesgraeme@gmail.com> | 2016-04-12 18:46:28 -0400 |
commit | 8eb2a7cec2c62edf35d7b812765bd64e6b7d484f (patch) | |
tree | 76a0c7715c612acddd9e6801dc14ec43f768176f /lib/waterfall.js | |
parent | a778ee63788d533111ff63b611cc5034e18a907f (diff) | |
download | async-8eb2a7cec2c62edf35d7b812765bd64e6b7d484f.tar.gz |
jsdoc-style documentation began documenting `Control Flow` methods
remaining `Control Flow` methods to document:
- queue
- priorityQueue
- cargo
- auto
- autoInject
- retry
- retryable
- iterator
- times, timesSeries, timesLimit
- race
Diffstat (limited to 'lib/waterfall.js')
-rw-r--r-- | lib/waterfall.js | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/lib/waterfall.js b/lib/waterfall.js index aaed2ee..c76b332 100644 --- a/lib/waterfall.js +++ b/lib/waterfall.js @@ -7,6 +7,61 @@ import rest from 'lodash/rest'; import onlyOnce from './internal/onlyOnce'; +/** + * Runs the `tasks` array of functions in series, each passing their results to + * the next in the array. However, if any of the `tasks` pass an error to their + * own callback, the next function is not executed, and the main `callback` is + * immediately called with the error. + * + * @name waterfall + * @static + * @memberOf async + * @category Control Flow + * @param {Array} tasks - An array of functions to run, each function is passed + * a `callback(err, result1, result2, ...)` it must call on completion. The + * first argument is an error (which can be `null`) and any further arguments + * will be passed as arguments in order to the next task. + * @param {Function} [callback] - An optional callback to run once all the + * functions have completed. This will be passed the results of the last task's + * callback. Invoked with (err, [results]). + * @example + * + * async.waterfall([ + * function(callback) { + * callback(null, 'one', 'two'); + * }, + * function(arg1, arg2, callback) { + * // arg1 now equals 'one' and arg2 now equals 'two' + * callback(null, 'three'); + * }, + * function(arg1, callback) { + * // arg1 now equals 'three' + * callback(null, 'done'); + * } + * ], function (err, result) { + * // result now equals 'done' + * }); + * + * // Or, with named functions: + * 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'); + * } + */ export default function(tasks, cb) { cb = once(cb || noop); if (!isArray(tasks)) return cb(new Error('First argument to waterfall must be an array of functions')); |