forEachOfLimit.js 1.6 KB

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