Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

series.js 2.9KB

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