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/series.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/series.js')
-rw-r--r-- | lib/series.js | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/lib/series.js b/lib/series.js index bd8e15d..b0cc6bf 100644 --- a/lib/series.js +++ b/lib/series.js @@ -3,6 +3,69 @@ import parallel from './internal/parallel'; import eachOfSeries from './eachOfSeries'; +/** + * Run the functions in the `tasks` collection in series, each one running once + * the previous function has completed. If any functions in the series pass an + * error to its callback, no more functions are run, and `callback` is + * immediately called with the value of the error. Otherwise, `callback` + * receives an array of results when `tasks` have completed. + * + * It is also possible to use an object instead of an array. Each property will + * be run as a function, and the results will be passed to the final `callback` + * as an object instead of an array. This can be a more readable way of handling + * results from [`series`](#series). + * + * **Note** that while many implementations preserve the order of object + * properties, the [ECMAScript Language Specification](http://www.ecma-international.org/ecma-262/5.1/#sec-8.6) + * explicitly states that + * + * > The mechanics and order of enumerating the properties is not specified. + * + * So if you rely on the order in which your series of functions are executed, + * and want this to work on all platforms, consider using an array. + * + * @name series + * @static + * @memberOf async + * @category Control Flow + * @param {Array|Object} tasks - A collection containing functions to run, each + * function is passed a `callback(err, result)` it must call on completion with + * an error `err` (which can be `null`) and an optional `result` value. + * @param {Function} [callback] - An optional callback to run once all the + * functions have completed. This function gets a results array (or object) + * containing all the result arguments passed to the `task` callbacks. Invoked + * with (err, result). + * @example + * async.series([ + * function(callback) { + * // do some stuff ... + * callback(null, 'one'); + * }, + * function(callback) { + * // do some more stuff ... + * callback(null, 'two'); + * } + * ], + * // optional callback + * function(err, results) { + * // results is now equal to ['one', 'two'] + * }); + * + * async.series({ + * one: function(callback) { + * setTimeout(function() { + * callback(null, 1); + * }, 200); + * }, + * two: function(callback){ + * setTimeout(function() { + * callback(null, 2); + * }, 100); + * } + * }, function(err, results) { + * // results is now equal to: {one: 1, two: 2} + * }); + */ export default function series(tasks, cb) { return parallel(eachOfSeries, tasks, cb); } |