1 | ;
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.default = series;
|
7 |
|
8 | var _parallel2 = require('./internal/parallel');
|
9 |
|
10 | var _parallel3 = _interopRequireDefault(_parallel2);
|
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|AsyncIterable|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 | * @return {Promise} a promise, if no callback is passed
|
52 | * @example
|
53 | * async.series([
|
54 | * function(callback) {
|
55 | * // do some stuff ...
|
56 | * callback(null, 'one');
|
57 | * },
|
58 | * function(callback) {
|
59 | * // do some more stuff ...
|
60 | * callback(null, 'two');
|
61 | * }
|
62 | * ],
|
63 | * // optional callback
|
64 | * function(err, results) {
|
65 | * // results is now equal to ['one', 'two']
|
66 | * });
|
67 | *
|
68 | * async.series({
|
69 | * one: function(callback) {
|
70 | * setTimeout(function() {
|
71 | * callback(null, 1);
|
72 | * }, 200);
|
73 | * },
|
74 | * two: function(callback){
|
75 | * setTimeout(function() {
|
76 | * callback(null, 2);
|
77 | * }, 100);
|
78 | * }
|
79 | * }, function(err, results) {
|
80 | * // results is now equal to: {one: 1, two: 2}
|
81 | * });
|
82 | */
|
83 | function series(tasks, callback) {
|
84 | return (0, _parallel3.default)(_eachOfSeries2.default, tasks, callback);
|
85 | }
|
86 | module.exports = exports['default']; |
\ | No newline at end of file |