Security update to Drupal 8.4.6
[yaffs-website] / node_modules / grunt-uncss / node_modules / async / race.js
1 'use strict';
2
3 Object.defineProperty(exports, "__esModule", {
4     value: true
5 });
6 exports.default = race;
7
8 var _isArray = require('lodash/isArray');
9
10 var _isArray2 = _interopRequireDefault(_isArray);
11
12 var _noop = require('lodash/noop');
13
14 var _noop2 = _interopRequireDefault(_noop);
15
16 var _once = require('./internal/once');
17
18 var _once2 = _interopRequireDefault(_once);
19
20 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
22 /**
23  * Runs the `tasks` array of functions in parallel, without waiting until the
24  * previous function has completed. Once any of the `tasks` complete or pass an
25  * error to its callback, the main `callback` is immediately called. It's
26  * equivalent to `Promise.race()`.
27  *
28  * @name race
29  * @static
30  * @memberOf module:ControlFlow
31  * @method
32  * @category Control Flow
33  * @param {Array} tasks - An array containing functions to run. Each function
34  * is passed a `callback(err, result)` which it must call on completion with an
35  * error `err` (which can be `null`) and an optional `result` value.
36  * @param {Function} callback - A callback to run once any of the functions have
37  * completed. This function gets an error or result from the first function that
38  * completed. Invoked with (err, result).
39  * @returns undefined
40  * @example
41  *
42  * async.race([
43  *     function(callback) {
44  *         setTimeout(function() {
45  *             callback(null, 'one');
46  *         }, 200);
47  *     },
48  *     function(callback) {
49  *         setTimeout(function() {
50  *             callback(null, 'two');
51  *         }, 100);
52  *     }
53  * ],
54  * // main callback
55  * function(err, result) {
56  *     // the result will be equal to 'two' as it finishes earlier
57  * });
58  */
59 function race(tasks, callback) {
60     callback = (0, _once2.default)(callback || _noop2.default);
61     if (!(0, _isArray2.default)(tasks)) return callback(new TypeError('First argument to race must be an array of functions'));
62     if (!tasks.length) return callback();
63     for (var i = 0, l = tasks.length; i < l; i++) {
64         tasks[i](callback);
65     }
66 }
67 module.exports = exports['default'];