mapLimit.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. var _map2 = require('./internal/map.js');
  6. var _map3 = _interopRequireDefault(_map2);
  7. var _eachOfLimit = require('./internal/eachOfLimit.js');
  8. var _eachOfLimit2 = _interopRequireDefault(_eachOfLimit);
  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 [`map`]{@link module:Collections.map} but runs a maximum of `limit` async operations at a time.
  14. *
  15. * @name mapLimit
  16. * @static
  17. * @memberOf module:Collections
  18. * @method
  19. * @see [async.map]{@link module:Collections.map}
  20. * @category Collection
  21. * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
  22. * @param {number} limit - The maximum number of async operations at a time.
  23. * @param {AsyncFunction} iteratee - An async function to apply to each item in
  24. * `coll`.
  25. * The iteratee should complete with the transformed item.
  26. * Invoked with (item, callback).
  27. * @param {Function} [callback] - A callback which is called when all `iteratee`
  28. * functions have finished, or an error occurs. Results is an array of the
  29. * transformed items from the `coll`. Invoked with (err, results).
  30. * @returns {Promise} a promise, if no callback is passed
  31. */
  32. function mapLimit(coll, limit, iteratee, callback) {
  33. return (0, _map3.default)((0, _eachOfLimit2.default)(limit), coll, iteratee, callback);
  34. }
  35. exports.default = (0, _awaitify2.default)(mapLimit, 4);
  36. module.exports = exports['default'];