CoolFace
Datasetpublic

basant307/AI_Governance_Project

sourceHugging Faceapache-2.0updated 2mo agoView on Hugging Face
0likes48downloads
concatLimit.js60 linesDownload Raw Back to async
1'use strict';2 3Object.defineProperty(exports, "__esModule", {4    value: true5});6 7var _wrapAsync = require('./internal/wrapAsync.js');8 9var _wrapAsync2 = _interopRequireDefault(_wrapAsync);10 11var _mapLimit = require('./mapLimit.js');12 13var _mapLimit2 = _interopRequireDefault(_mapLimit);14 15var _awaitify = require('./internal/awaitify.js');16 17var _awaitify2 = _interopRequireDefault(_awaitify);18 19function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }20 21/**22 * The same as [`concat`]{@link module:Collections.concat} but runs a maximum of `limit` async operations at a time.23 *24 * @name concatLimit25 * @static26 * @memberOf module:Collections27 * @method28 * @see [async.concat]{@link module:Collections.concat}29 * @category Collection30 * @alias flatMapLimit31 * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.32 * @param {number} limit - The maximum number of async operations at a time.33 * @param {AsyncFunction} iteratee - A function to apply to each item in `coll`,34 * which should use an array as its result. Invoked with (item, callback).35 * @param {Function} [callback] - A callback which is called after all the36 * `iteratee` functions have finished, or an error occurs. Results is an array37 * containing the concatenated results of the `iteratee` function. Invoked with38 * (err, results).39 * @returns A Promise, if no callback is passed40 */41function concatLimit(coll, limit, iteratee, callback) {42    var _iteratee = (0, _wrapAsync2.default)(iteratee);43    return (0, _mapLimit2.default)(coll, limit, (val, iterCb) => {44        _iteratee(val, (err, ...args) => {45            if (err) return iterCb(err);46            return iterCb(err, args);47        });48    }, (err, mapResults) => {49        var result = [];50        for (var i = 0; i < mapResults.length; i++) {51            if (mapResults[i]) {52                result = result.concat(...mapResults[i]);53            }54        }55 56        return callback(err, result);57    });58}59exports.default = (0, _awaitify2.default)(concatLimit, 4);60module.exports = exports.default;
basant307/AI_Governance_Project · CoolFace