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.

parallel.js 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = parallelLimit;
  6. var _eachOf = require('./eachOf');
  7. var _eachOf2 = _interopRequireDefault(_eachOf);
  8. var _parallel = require('./internal/parallel');
  9. var _parallel2 = _interopRequireDefault(_parallel);
  10. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  11. /**
  12. * Run the `tasks` collection of functions in parallel, without waiting until
  13. * the previous function has completed. If any of the functions pass an error to
  14. * its callback, the main `callback` is immediately called with the value of the
  15. * error. Once the `tasks` have completed, the results are passed to the final
  16. * `callback` as an array.
  17. *
  18. * **Note:** `parallel` is about kicking-off I/O tasks in parallel, not about
  19. * parallel execution of code. If your tasks do not use any timers or perform
  20. * any I/O, they will actually be executed in series. Any synchronous setup
  21. * sections for each task will happen one after the other. JavaScript remains
  22. * single-threaded.
  23. *
  24. * **Hint:** Use [`reflect`]{@link module:Utils.reflect} to continue the
  25. * execution of other tasks when a task fails.
  26. *
  27. * It is also possible to use an object instead of an array. Each property will
  28. * be run as a function and the results will be passed to the final `callback`
  29. * as an object instead of an array. This can be a more readable way of handling
  30. * results from {@link async.parallel}.
  31. *
  32. * @name parallel
  33. * @static
  34. * @memberOf module:ControlFlow
  35. * @method
  36. * @category Control Flow
  37. * @param {Array|Iterable|Object} tasks - A collection of
  38. * [async functions]{@link AsyncFunction} to run.
  39. * Each async 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 successfully. This function gets a results array
  42. * (or object) containing all the result arguments passed to the task callbacks.
  43. * Invoked with (err, results).
  44. *
  45. * @example
  46. * async.parallel([
  47. * function(callback) {
  48. * setTimeout(function() {
  49. * callback(null, 'one');
  50. * }, 200);
  51. * },
  52. * function(callback) {
  53. * setTimeout(function() {
  54. * callback(null, 'two');
  55. * }, 100);
  56. * }
  57. * ],
  58. * // optional callback
  59. * function(err, results) {
  60. * // the results array will equal ['one','two'] even though
  61. * // the second function had a shorter timeout.
  62. * });
  63. *
  64. * // an example using an object instead of an array
  65. * async.parallel({
  66. * one: function(callback) {
  67. * setTimeout(function() {
  68. * callback(null, 1);
  69. * }, 200);
  70. * },
  71. * two: function(callback) {
  72. * setTimeout(function() {
  73. * callback(null, 2);
  74. * }, 100);
  75. * }
  76. * }, function(err, results) {
  77. * // results is now equals to: {one: 1, two: 2}
  78. * });
  79. */
  80. function parallelLimit(tasks, callback) {
  81. (0, _parallel2.default)(_eachOf2.default, tasks, callback);
  82. }
  83. module.exports = exports['default'];