timesLimit.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = timesLimit;
  6. var _mapLimit = require('./mapLimit.js');
  7. var _mapLimit2 = _interopRequireDefault(_mapLimit);
  8. var _range = require('./internal/range.js');
  9. var _range2 = _interopRequireDefault(_range);
  10. var _wrapAsync = require('./internal/wrapAsync.js');
  11. var _wrapAsync2 = _interopRequireDefault(_wrapAsync);
  12. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  13. /**
  14. * The same as [times]{@link module:ControlFlow.times} but runs a maximum of `limit` async operations at a
  15. * time.
  16. *
  17. * @name timesLimit
  18. * @static
  19. * @memberOf module:ControlFlow
  20. * @method
  21. * @see [async.times]{@link module:ControlFlow.times}
  22. * @category Control Flow
  23. * @param {number} count - The number of times to run the function.
  24. * @param {number} limit - The maximum number of async operations at a time.
  25. * @param {AsyncFunction} iteratee - The async function to call `n` times.
  26. * Invoked with the iteration index and a callback: (n, next).
  27. * @param {Function} callback - see [async.map]{@link module:Collections.map}.
  28. * @returns {Promise} a promise, if no callback is provided
  29. */
  30. function timesLimit(count, limit, iteratee, callback) {
  31. var _iteratee = (0, _wrapAsync2.default)(iteratee);
  32. return (0, _mapLimit2.default)((0, _range2.default)(count), limit, _iteratee, callback);
  33. }
  34. module.exports = exports['default'];