forEachLimit.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. var _eachOfLimit = require('./internal/eachOfLimit.js');
  6. var _eachOfLimit2 = _interopRequireDefault(_eachOfLimit);
  7. var _withoutIndex = require('./internal/withoutIndex.js');
  8. var _withoutIndex2 = _interopRequireDefault(_withoutIndex);
  9. var _wrapAsync = require('./internal/wrapAsync.js');
  10. var _wrapAsync2 = _interopRequireDefault(_wrapAsync);
  11. var _awaitify = require('./internal/awaitify.js');
  12. var _awaitify2 = _interopRequireDefault(_awaitify);
  13. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  14. /**
  15. * The same as [`each`]{@link module:Collections.each} but runs a maximum of `limit` async operations at a time.
  16. *
  17. * @name eachLimit
  18. * @static
  19. * @memberOf module:Collections
  20. * @method
  21. * @see [async.each]{@link module:Collections.each}
  22. * @alias forEachLimit
  23. * @category Collection
  24. * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
  25. * @param {number} limit - The maximum number of async operations at a time.
  26. * @param {AsyncFunction} iteratee - An async function to apply to each item in
  27. * `coll`.
  28. * The array index is not passed to the iteratee.
  29. * If you need the index, use `eachOfLimit`.
  30. * Invoked with (item, callback).
  31. * @param {Function} [callback] - A callback which is called when all
  32. * `iteratee` functions have finished, or an error occurs. Invoked with (err).
  33. * @returns {Promise} a promise, if a callback is omitted
  34. */
  35. function eachLimit(coll, limit, iteratee, callback) {
  36. return (0, _eachOfLimit2.default)(limit)(coll, (0, _withoutIndex2.default)((0, _wrapAsync2.default)(iteratee)), callback);
  37. }
  38. exports.default = (0, _awaitify2.default)(eachLimit, 4);
  39. module.exports = exports['default'];