eachLimit.js 1.6 KB

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