findLimit.js
1 'use strict'; 2 3 Object.defineProperty(exports, "__esModule", { 4 value: true 5 }); 6 7 var _createTester = require('./internal/createTester'); 8 9 var _createTester2 = _interopRequireDefault(_createTester); 10 11 var _eachOfLimit = require('./internal/eachOfLimit'); 12 13 var _eachOfLimit2 = _interopRequireDefault(_eachOfLimit); 14 15 var _awaitify = require('./internal/awaitify'); 16 17 var _awaitify2 = _interopRequireDefault(_awaitify); 18 19 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 20 21 /** 22 * The same as [`detect`]{@link module:Collections.detect} but runs a maximum of `limit` async operations at a 23 * time. 24 * 25 * @name detectLimit 26 * @static 27 * @memberOf module:Collections 28 * @method 29 * @see [async.detect]{@link module:Collections.detect} 30 * @alias findLimit 31 * @category Collections 32 * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over. 33 * @param {number} limit - The maximum number of async operations at a time. 34 * @param {AsyncFunction} iteratee - A truth test to apply to each item in `coll`. 35 * The iteratee must complete with a boolean value as its result. 36 * Invoked with (item, callback). 37 * @param {Function} [callback] - A callback which is called as soon as any 38 * iteratee returns `true`, or after all the `iteratee` functions have finished. 39 * Result will be the first item in the array that passes the truth test 40 * (iteratee) or the value `undefined` if none passed. Invoked with 41 * (err, result). 42 * @returns a Promise if no callback is passed 43 */ 44 function detectLimit(coll, limit, iteratee, callback) { 45 return (0, _createTester2.default)(bool => bool, (res, item) => item)((0, _eachOfLimit2.default)(limit), coll, iteratee, callback); 46 } 47 exports.default = (0, _awaitify2.default)(detectLimit, 4); 48 module.exports = exports['default'];