everyLimit.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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 [`every`]{@link module:Collections.every} but runs a maximum of `limit` async operations at a time.
  14. *
  15. * @name everyLimit
  16. * @static
  17. * @memberOf module:Collections
  18. * @method
  19. * @see [async.every]{@link module:Collections.every}
  20. * @alias allLimit
  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 collection in parallel.
  26. * The iteratee must complete with a boolean result value.
  27. * Invoked with (item, callback).
  28. * @param {Function} [callback] - A callback which is called after all the
  29. * `iteratee` functions have finished. Result will be either `true` or `false`
  30. * depending on the values of the async tests. Invoked with (err, result).
  31. * @returns {Promise} a promise, if no callback provided
  32. */
  33. function everyLimit(coll, limit, iteratee, callback) {
  34. return (0, _createTester2.default)(bool => !bool, res => !res)((0, _eachOfLimit2.default)(limit), coll, iteratee, callback);
  35. }
  36. exports.default = (0, _awaitify2.default)(everyLimit, 4);
  37. module.exports = exports['default'];