parallelLimit.js 1.5 KB

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