someLimit.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. var _createTester = require('./internal/createTester.js');
  6. var _createTester2 = _interopRequireDefault(_createTester);
  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 [`some`]{@link module:Collections.some} but runs a maximum of `limit` async operations at a time.
  14. *
  15. * @name someLimit
  16. * @static
  17. * @memberOf module:Collections
  18. * @method
  19. * @see [async.some]{@link module:Collections.some}
  20. * @alias anyLimit
  21. * @category Collection
  22. * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
  23. * @param {number} limit - The maximum number of async operations at a time.
  24. * @param {AsyncFunction} iteratee - An async truth test to apply to each item
  25. * in the collections in parallel.
  26. * The iteratee should complete with a boolean `result` value.
  27. * Invoked with (item, callback).
  28. * @param {Function} [callback] - A callback which is called as soon as any
  29. * iteratee returns `true`, or after all the iteratee functions have finished.
  30. * Result will be either `true` or `false` depending on the values of the async
  31. * tests. Invoked with (err, result).
  32. * @returns {Promise} a promise, if no callback provided
  33. */
  34. function someLimit(coll, limit, iteratee, callback) {
  35. return (0, _createTester2.default)(Boolean, res => res)((0, _eachOfLimit2.default)(limit), coll, iteratee, callback);
  36. }
  37. exports.default = (0, _awaitify2.default)(someLimit, 4);
  38. module.exports = exports['default'];