basant307/AI_Governance_Project
045
1'use strict';2 3Object.defineProperty(exports, "__esModule", {4 value: true5});6 7var _once = require('./internal/once.js');8 9var _once2 = _interopRequireDefault(_once);10 11var _wrapAsync = require('./internal/wrapAsync.js');12 13var _wrapAsync2 = _interopRequireDefault(_wrapAsync);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 * Runs the `tasks` array of functions in parallel, without waiting until the23 * previous function has completed. Once any of the `tasks` complete or pass an24 * error to its callback, the main `callback` is immediately called. It's25 * equivalent to `Promise.race()`.26 *27 * @name race28 * @static29 * @memberOf module:ControlFlow30 * @method31 * @category Control Flow32 * @param {Array} tasks - An array containing [async functions]{@link AsyncFunction}33 * to run. Each function can complete with an optional `result` value.34 * @param {Function} callback - A callback to run once any of the functions have35 * completed. This function gets an error or result from the first function that36 * completed. Invoked with (err, result).37 * @returns {Promise} a promise, if a callback is omitted38 * @example39 *40 * async.race([41 * function(callback) {42 * setTimeout(function() {43 * callback(null, 'one');44 * }, 200);45 * },46 * function(callback) {47 * setTimeout(function() {48 * callback(null, 'two');49 * }, 100);50 * }51 * ],52 * // main callback53 * function(err, result) {54 * // the result will be equal to 'two' as it finishes earlier55 * });56 */57function race(tasks, callback) {58 callback = (0, _once2.default)(callback);59 if (!Array.isArray(tasks)) return callback(new TypeError('First argument to race must be an array of functions'));60 if (!tasks.length) return callback();61 for (var i = 0, l = tasks.length; i < l; i++) {62 (0, _wrapAsync2.default)(tasks[i])(callback);63 }64}65 66exports.default = (0, _awaitify2.default)(race, 2);67module.exports = exports.default;