[6a3a178] | 1 | 'use strict';
|
---|
| 2 |
|
---|
| 3 | Object.defineProperty(exports, "__esModule", {
|
---|
| 4 | value: true
|
---|
| 5 | });
|
---|
| 6 | exports.default = series;
|
---|
| 7 |
|
---|
| 8 | var _parallel = require('./internal/parallel');
|
---|
| 9 |
|
---|
| 10 | var _parallel2 = _interopRequireDefault(_parallel);
|
---|
| 11 |
|
---|
| 12 | var _eachOfSeries = require('./eachOfSeries');
|
---|
| 13 |
|
---|
| 14 | var _eachOfSeries2 = _interopRequireDefault(_eachOfSeries);
|
---|
| 15 |
|
---|
| 16 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
---|
| 17 |
|
---|
| 18 | /**
|
---|
| 19 | * Run the functions in the `tasks` collection in series, each one running once
|
---|
| 20 | * the previous function has completed. If any functions in the series pass an
|
---|
| 21 | * error to its callback, no more functions are run, and `callback` is
|
---|
| 22 | * immediately called with the value of the error. Otherwise, `callback`
|
---|
| 23 | * receives an array of results when `tasks` have completed.
|
---|
| 24 | *
|
---|
| 25 | * It is also possible to use an object instead of an array. Each property will
|
---|
| 26 | * be run as a function, and the results will be passed to the final `callback`
|
---|
| 27 | * as an object instead of an array. This can be a more readable way of handling
|
---|
| 28 | * results from {@link async.series}.
|
---|
| 29 | *
|
---|
| 30 | * **Note** that while many implementations preserve the order of object
|
---|
| 31 | * properties, the [ECMAScript Language Specification](http://www.ecma-international.org/ecma-262/5.1/#sec-8.6)
|
---|
| 32 | * explicitly states that
|
---|
| 33 | *
|
---|
| 34 | * > The mechanics and order of enumerating the properties is not specified.
|
---|
| 35 | *
|
---|
| 36 | * So if you rely on the order in which your series of functions are executed,
|
---|
| 37 | * and want this to work on all platforms, consider using an array.
|
---|
| 38 | *
|
---|
| 39 | * @name series
|
---|
| 40 | * @static
|
---|
| 41 | * @memberOf module:ControlFlow
|
---|
| 42 | * @method
|
---|
| 43 | * @category Control Flow
|
---|
| 44 | * @param {Array|Iterable|Object} tasks - A collection containing
|
---|
| 45 | * [async functions]{@link AsyncFunction} to run in series.
|
---|
| 46 | * Each function can complete with any number of optional `result` values.
|
---|
| 47 | * @param {Function} [callback] - An optional callback to run once all the
|
---|
| 48 | * functions have completed. This function gets a results array (or object)
|
---|
| 49 | * containing all the result arguments passed to the `task` callbacks. Invoked
|
---|
| 50 | * with (err, result).
|
---|
| 51 | * @example
|
---|
| 52 | * async.series([
|
---|
| 53 | * function(callback) {
|
---|
| 54 | * // do some stuff ...
|
---|
| 55 | * callback(null, 'one');
|
---|
| 56 | * },
|
---|
| 57 | * function(callback) {
|
---|
| 58 | * // do some more stuff ...
|
---|
| 59 | * callback(null, 'two');
|
---|
| 60 | * }
|
---|
| 61 | * ],
|
---|
| 62 | * // optional callback
|
---|
| 63 | * function(err, results) {
|
---|
| 64 | * // results is now equal to ['one', 'two']
|
---|
| 65 | * });
|
---|
| 66 | *
|
---|
| 67 | * async.series({
|
---|
| 68 | * one: function(callback) {
|
---|
| 69 | * setTimeout(function() {
|
---|
| 70 | * callback(null, 1);
|
---|
| 71 | * }, 200);
|
---|
| 72 | * },
|
---|
| 73 | * two: function(callback){
|
---|
| 74 | * setTimeout(function() {
|
---|
| 75 | * callback(null, 2);
|
---|
| 76 | * }, 100);
|
---|
| 77 | * }
|
---|
| 78 | * }, function(err, results) {
|
---|
| 79 | * // results is now equal to: {one: 1, two: 2}
|
---|
| 80 | * });
|
---|
| 81 | */
|
---|
| 82 | function series(tasks, callback) {
|
---|
| 83 | (0, _parallel2.default)(_eachOfSeries2.default, tasks, callback);
|
---|
| 84 | }
|
---|
| 85 | module.exports = exports['default']; |
---|