3 Object.defineProperty(exports, "__esModule", {
6 exports.default = parallelLimit;
8 var _eachOf = require('./eachOf');
10 var _eachOf2 = _interopRequireDefault(_eachOf);
12 var _parallel = require('./internal/parallel');
14 var _parallel2 = _interopRequireDefault(_parallel);
16 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19 * Run the `tasks` collection of functions in parallel, without waiting until
20 * the previous function has completed. If any of the functions pass an error to
21 * its callback, the main `callback` is immediately called with the value of the
22 * error. Once the `tasks` have completed, the results are passed to the final
23 * `callback` as an array.
25 * **Note:** `parallel` is about kicking-off I/O tasks in parallel, not about
26 * parallel execution of code. If your tasks do not use any timers or perform
27 * any I/O, they will actually be executed in series. Any synchronous setup
28 * sections for each task will happen one after the other. JavaScript remains
31 * It is also possible to use an object instead of an array. Each property will
32 * be run as a function and the results will be passed to the final `callback`
33 * as an object instead of an array. This can be a more readable way of handling
34 * results from {@link async.parallel}.
38 * @memberOf module:ControlFlow
40 * @category Control Flow
41 * @param {Array|Iterable|Object} tasks - A collection containing functions to run.
42 * Each function is passed a `callback(err, result)` which it must call on
43 * completion with an error `err` (which can be `null`) and an optional `result`
45 * @param {Function} [callback] - An optional callback to run once all the
46 * functions have completed successfully. This function gets a results array
47 * (or object) containing all the result arguments passed to the task callbacks.
48 * Invoked with (err, results).
51 * function(callback) {
52 * setTimeout(function() {
53 * callback(null, 'one');
56 * function(callback) {
57 * setTimeout(function() {
58 * callback(null, 'two');
62 * // optional callback
63 * function(err, results) {
64 * // the results array will equal ['one','two'] even though
65 * // the second function had a shorter timeout.
68 * // an example using an object instead of an array
70 * one: function(callback) {
71 * setTimeout(function() {
75 * two: function(callback) {
76 * setTimeout(function() {
80 * }, function(err, results) {
81 * // results is now equals to: {one: 1, two: 2}
84 function parallelLimit(tasks, callback) {
85 (0, _parallel2.default)(_eachOf2.default, tasks, callback);
87 module.exports = exports['default'];