UNPKG

1.79 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6
7var _eachOfLimit = require('./internal/eachOfLimit.js');
8
9var _eachOfLimit2 = _interopRequireDefault(_eachOfLimit);
10
11var _withoutIndex = require('./internal/withoutIndex.js');
12
13var _withoutIndex2 = _interopRequireDefault(_withoutIndex);
14
15var _wrapAsync = require('./internal/wrapAsync.js');
16
17var _wrapAsync2 = _interopRequireDefault(_wrapAsync);
18
19var _awaitify = require('./internal/awaitify.js');
20
21var _awaitify2 = _interopRequireDefault(_awaitify);
22
23function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
24
25/**
26 * The same as [`each`]{@link module:Collections.each} but runs a maximum of `limit` async operations at a time.
27 *
28 * @name eachLimit
29 * @static
30 * @memberOf module:Collections
31 * @method
32 * @see [async.each]{@link module:Collections.each}
33 * @alias forEachLimit
34 * @category Collection
35 * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
36 * @param {number} limit - The maximum number of async operations at a time.
37 * @param {AsyncFunction} iteratee - An async function to apply to each item in
38 * `coll`.
39 * The array index is not passed to the iteratee.
40 * If you need the index, use `eachOfLimit`.
41 * Invoked with (item, callback).
42 * @param {Function} [callback] - A callback which is called when all
43 * `iteratee` functions have finished, or an error occurs. Invoked with (err).
44 * @returns {Promise} a promise, if a callback is omitted
45 */
46function eachLimit(coll, limit, iteratee, callback) {
47 return (0, _eachOfLimit2.default)(limit)(coll, (0, _withoutIndex2.default)((0, _wrapAsync2.default)(iteratee)), callback);
48}
49exports.default = (0, _awaitify2.default)(eachLimit, 4);
50module.exports = exports.default;
\No newline at end of file