UNPKG

1.5 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = parallelLimit;
7
8var _eachOfLimit = require('./internal/eachOfLimit');
9
10var _eachOfLimit2 = _interopRequireDefault(_eachOfLimit);
11
12var _parallel = require('./internal/parallel');
13
14var _parallel2 = _interopRequireDefault(_parallel);
15
16function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
18/**
19 * The same as [`parallel`]{@link module:ControlFlow.parallel} but runs a maximum of `limit` async operations at a
20 * time.
21 *
22 * @name parallelLimit
23 * @static
24 * @memberOf module:ControlFlow
25 * @method
26 * @see [async.parallel]{@link module:ControlFlow.parallel}
27 * @category Control Flow
28 * @param {Array|Iterable|AsyncIterable|Object} tasks - A collection of
29 * [async functions]{@link AsyncFunction} to run.
30 * Each async function can complete with any number of optional `result` values.
31 * @param {number} limit - The maximum number of async operations at a time.
32 * @param {Function} [callback] - An optional callback to run once all the
33 * functions have completed successfully. This function gets a results array
34 * (or object) containing all the result arguments passed to the task callbacks.
35 * Invoked with (err, results).
36 * @returns {Promise} a promise, if a callback is not passed
37 */
38function parallelLimit(tasks, limit, callback) {
39 return (0, _parallel2.default)((0, _eachOfLimit2.default)(limit), tasks, callback);
40}
41module.exports = exports['default'];
\No newline at end of file