1 (function (global, factory) {
2 typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3 typeof define === 'function' && define.amd ? define(['exports'], factory) :
4 (factory((global.async = global.async || {})));
5 }(this, (function (exports) { 'use strict';
8 * A faster alternative to `Function#apply`, this function invokes `func`
9 * with the `this` binding of `thisArg` and the arguments of `args`.
12 * @param {Function} func The function to invoke.
13 * @param {*} thisArg The `this` binding of `func`.
14 * @param {Array} args The arguments to invoke `func` with.
15 * @returns {*} Returns the result of `func`.
17 function apply(func, thisArg, args) {
18 switch (args.length) {
19 case 0: return func.call(thisArg);
20 case 1: return func.call(thisArg, args[0]);
21 case 2: return func.call(thisArg, args[0], args[1]);
22 case 3: return func.call(thisArg, args[0], args[1], args[2]);
24 return func.apply(thisArg, args);
27 /* Built-in method references for those with the same name as other `lodash` methods. */
28 var nativeMax = Math.max;
31 * A specialized version of `baseRest` which transforms the rest array.
34 * @param {Function} func The function to apply a rest parameter to.
35 * @param {number} [start=func.length-1] The start position of the rest parameter.
36 * @param {Function} transform The rest array transform.
37 * @returns {Function} Returns the new function.
39 function overRest$1(func, start, transform) {
40 start = nativeMax(start === undefined ? (func.length - 1) : start, 0);
44 length = nativeMax(args.length - start, 0),
45 array = Array(length);
47 while (++index < length) {
48 array[index] = args[start + index];
51 var otherArgs = Array(start + 1);
52 while (++index < start) {
53 otherArgs[index] = args[index];
55 otherArgs[start] = transform(array);
56 return apply(func, this, otherArgs);
61 * This method returns the first argument it receives.
67 * @param {*} value Any value.
68 * @returns {*} Returns `value`.
71 * var object = { 'a': 1 };
73 * console.log(_.identity(object) === object);
76 function identity(value) {
80 // Lodash rest function without function.toString()
82 function rest(func, start) {
83 return overRest$1(func, start, identity);
86 var initialParams = function (fn) {
87 return rest(function (args /*..., callback*/) {
88 var callback = args.pop();
89 fn.call(this, args, callback);
93 function applyEach$1(eachfn) {
94 return rest(function (fns, args) {
95 var go = initialParams(function (args, callback) {
97 return eachfn(fns, function (fn, cb) {
98 fn.apply(that, args.concat(cb));
102 return go.apply(this, args);
109 /** Detect free variable `global` from Node.js. */
110 var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
112 /** Detect free variable `self`. */
113 var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
115 /** Used as a reference to the global object. */
116 var root = freeGlobal || freeSelf || Function('return this')();
118 /** Built-in value references. */
119 var Symbol$1 = root.Symbol;
121 /** Used for built-in method references. */
122 var objectProto = Object.prototype;
124 /** Used to check objects for own properties. */
125 var hasOwnProperty = objectProto.hasOwnProperty;
128 * Used to resolve the
129 * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
132 var nativeObjectToString = objectProto.toString;
134 /** Built-in value references. */
135 var symToStringTag$1 = Symbol$1 ? Symbol$1.toStringTag : undefined;
138 * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values.
141 * @param {*} value The value to query.
142 * @returns {string} Returns the raw `toStringTag`.
144 function getRawTag(value) {
145 var isOwn = hasOwnProperty.call(value, symToStringTag$1),
146 tag = value[symToStringTag$1];
149 value[symToStringTag$1] = undefined;
153 var result = nativeObjectToString.call(value);
156 value[symToStringTag$1] = tag;
158 delete value[symToStringTag$1];
164 /** Used for built-in method references. */
165 var objectProto$1 = Object.prototype;
168 * Used to resolve the
169 * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
172 var nativeObjectToString$1 = objectProto$1.toString;
175 * Converts `value` to a string using `Object.prototype.toString`.
178 * @param {*} value The value to convert.
179 * @returns {string} Returns the converted string.
181 function objectToString(value) {
182 return nativeObjectToString$1.call(value);
185 /** `Object#toString` result references. */
186 var nullTag = '[object Null]';
187 var undefinedTag = '[object Undefined]';
189 /** Built-in value references. */
190 var symToStringTag = Symbol$1 ? Symbol$1.toStringTag : undefined;
193 * The base implementation of `getTag` without fallbacks for buggy environments.
196 * @param {*} value The value to query.
197 * @returns {string} Returns the `toStringTag`.
199 function baseGetTag(value) {
201 return value === undefined ? undefinedTag : nullTag;
203 return (symToStringTag && symToStringTag in Object(value))
205 : objectToString(value);
209 * Checks if `value` is the
210 * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
211 * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
217 * @param {*} value The value to check.
218 * @returns {boolean} Returns `true` if `value` is an object, else `false`.
224 * _.isObject([1, 2, 3]);
227 * _.isObject(_.noop);
233 function isObject(value) {
234 var type = typeof value;
235 return value != null && (type == 'object' || type == 'function');
238 /** `Object#toString` result references. */
239 var asyncTag = '[object AsyncFunction]';
240 var funcTag = '[object Function]';
241 var genTag = '[object GeneratorFunction]';
242 var proxyTag = '[object Proxy]';
245 * Checks if `value` is classified as a `Function` object.
251 * @param {*} value The value to check.
252 * @returns {boolean} Returns `true` if `value` is a function, else `false`.
258 * _.isFunction(/abc/);
261 function isFunction(value) {
262 if (!isObject(value)) {
265 // The use of `Object#toString` avoids issues with the `typeof` operator
266 // in Safari 9 which returns 'object' for typed arrays and other constructors.
267 var tag = baseGetTag(value);
268 return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
271 /** Used as references for various `Number` constants. */
272 var MAX_SAFE_INTEGER = 9007199254740991;
275 * Checks if `value` is a valid array-like length.
277 * **Note:** This method is loosely based on
278 * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
284 * @param {*} value The value to check.
285 * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
291 * _.isLength(Number.MIN_VALUE);
294 * _.isLength(Infinity);
300 function isLength(value) {
301 return typeof value == 'number' &&
302 value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
306 * Checks if `value` is array-like. A value is considered array-like if it's
307 * not a function and has a `value.length` that's an integer greater than or
308 * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
314 * @param {*} value The value to check.
315 * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
318 * _.isArrayLike([1, 2, 3]);
321 * _.isArrayLike(document.body.children);
324 * _.isArrayLike('abc');
327 * _.isArrayLike(_.noop);
330 function isArrayLike(value) {
331 return value != null && isLength(value.length) && !isFunction(value);
334 // A temporary value used to identify if the loop should be broken.
339 * This method returns `undefined`.
347 * _.times(2, _.noop);
348 * // => [undefined, undefined]
351 // No operation performed.
356 if (fn === null) return;
359 callFn.apply(this, arguments);
363 var iteratorSymbol = typeof Symbol === 'function' && Symbol.iterator;
365 var getIterator = function (coll) {
366 return iteratorSymbol && coll[iteratorSymbol] && coll[iteratorSymbol]();
370 * The base implementation of `_.times` without support for iteratee shorthands
371 * or max array length checks.
374 * @param {number} n The number of times to invoke `iteratee`.
375 * @param {Function} iteratee The function invoked per iteration.
376 * @returns {Array} Returns the array of results.
378 function baseTimes(n, iteratee) {
382 while (++index < n) {
383 result[index] = iteratee(index);
389 * Checks if `value` is object-like. A value is object-like if it's not `null`
390 * and has a `typeof` result of "object".
396 * @param {*} value The value to check.
397 * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
400 * _.isObjectLike({});
403 * _.isObjectLike([1, 2, 3]);
406 * _.isObjectLike(_.noop);
409 * _.isObjectLike(null);
412 function isObjectLike(value) {
413 return value != null && typeof value == 'object';
416 /** `Object#toString` result references. */
417 var argsTag = '[object Arguments]';
420 * The base implementation of `_.isArguments`.
423 * @param {*} value The value to check.
424 * @returns {boolean} Returns `true` if `value` is an `arguments` object,
426 function baseIsArguments(value) {
427 return isObjectLike(value) && baseGetTag(value) == argsTag;
430 /** Used for built-in method references. */
431 var objectProto$3 = Object.prototype;
433 /** Used to check objects for own properties. */
434 var hasOwnProperty$2 = objectProto$3.hasOwnProperty;
436 /** Built-in value references. */
437 var propertyIsEnumerable = objectProto$3.propertyIsEnumerable;
440 * Checks if `value` is likely an `arguments` object.
446 * @param {*} value The value to check.
447 * @returns {boolean} Returns `true` if `value` is an `arguments` object,
451 * _.isArguments(function() { return arguments; }());
454 * _.isArguments([1, 2, 3]);
457 var isArguments = baseIsArguments(function() { return arguments; }()) ? baseIsArguments : function(value) {
458 return isObjectLike(value) && hasOwnProperty$2.call(value, 'callee') &&
459 !propertyIsEnumerable.call(value, 'callee');
463 * Checks if `value` is classified as an `Array` object.
469 * @param {*} value The value to check.
470 * @returns {boolean} Returns `true` if `value` is an array, else `false`.
473 * _.isArray([1, 2, 3]);
476 * _.isArray(document.body.children);
485 var isArray = Array.isArray;
488 * This method returns `false`.
494 * @returns {boolean} Returns `false`.
497 * _.times(2, _.stubFalse);
498 * // => [false, false]
500 function stubFalse() {
504 /** Detect free variable `exports`. */
505 var freeExports = typeof exports == 'object' && exports && !exports.nodeType && exports;
507 /** Detect free variable `module`. */
508 var freeModule = freeExports && typeof module == 'object' && module && !module.nodeType && module;
510 /** Detect the popular CommonJS extension `module.exports`. */
511 var moduleExports = freeModule && freeModule.exports === freeExports;
513 /** Built-in value references. */
514 var Buffer = moduleExports ? root.Buffer : undefined;
516 /* Built-in method references for those with the same name as other `lodash` methods. */
517 var nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined;
520 * Checks if `value` is a buffer.
526 * @param {*} value The value to check.
527 * @returns {boolean} Returns `true` if `value` is a buffer, else `false`.
530 * _.isBuffer(new Buffer(2));
533 * _.isBuffer(new Uint8Array(2));
536 var isBuffer = nativeIsBuffer || stubFalse;
538 /** Used as references for various `Number` constants. */
539 var MAX_SAFE_INTEGER$1 = 9007199254740991;
541 /** Used to detect unsigned integer values. */
542 var reIsUint = /^(?:0|[1-9]\d*)$/;
545 * Checks if `value` is a valid array-like index.
548 * @param {*} value The value to check.
549 * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
550 * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
552 function isIndex(value, length) {
553 length = length == null ? MAX_SAFE_INTEGER$1 : length;
555 (typeof value == 'number' || reIsUint.test(value)) &&
556 (value > -1 && value % 1 == 0 && value < length);
559 /** `Object#toString` result references. */
560 var argsTag$1 = '[object Arguments]';
561 var arrayTag = '[object Array]';
562 var boolTag = '[object Boolean]';
563 var dateTag = '[object Date]';
564 var errorTag = '[object Error]';
565 var funcTag$1 = '[object Function]';
566 var mapTag = '[object Map]';
567 var numberTag = '[object Number]';
568 var objectTag = '[object Object]';
569 var regexpTag = '[object RegExp]';
570 var setTag = '[object Set]';
571 var stringTag = '[object String]';
572 var weakMapTag = '[object WeakMap]';
574 var arrayBufferTag = '[object ArrayBuffer]';
575 var dataViewTag = '[object DataView]';
576 var float32Tag = '[object Float32Array]';
577 var float64Tag = '[object Float64Array]';
578 var int8Tag = '[object Int8Array]';
579 var int16Tag = '[object Int16Array]';
580 var int32Tag = '[object Int32Array]';
581 var uint8Tag = '[object Uint8Array]';
582 var uint8ClampedTag = '[object Uint8ClampedArray]';
583 var uint16Tag = '[object Uint16Array]';
584 var uint32Tag = '[object Uint32Array]';
586 /** Used to identify `toStringTag` values of typed arrays. */
587 var typedArrayTags = {};
588 typedArrayTags[float32Tag] = typedArrayTags[float64Tag] =
589 typedArrayTags[int8Tag] = typedArrayTags[int16Tag] =
590 typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] =
591 typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] =
592 typedArrayTags[uint32Tag] = true;
593 typedArrayTags[argsTag$1] = typedArrayTags[arrayTag] =
594 typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] =
595 typedArrayTags[dataViewTag] = typedArrayTags[dateTag] =
596 typedArrayTags[errorTag] = typedArrayTags[funcTag$1] =
597 typedArrayTags[mapTag] = typedArrayTags[numberTag] =
598 typedArrayTags[objectTag] = typedArrayTags[regexpTag] =
599 typedArrayTags[setTag] = typedArrayTags[stringTag] =
600 typedArrayTags[weakMapTag] = false;
603 * The base implementation of `_.isTypedArray` without Node.js optimizations.
606 * @param {*} value The value to check.
607 * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
609 function baseIsTypedArray(value) {
610 return isObjectLike(value) &&
611 isLength(value.length) && !!typedArrayTags[baseGetTag(value)];
615 * The base implementation of `_.unary` without support for storing metadata.
618 * @param {Function} func The function to cap arguments for.
619 * @returns {Function} Returns the new capped function.
621 function baseUnary(func) {
622 return function(value) {
627 /** Detect free variable `exports`. */
628 var freeExports$1 = typeof exports == 'object' && exports && !exports.nodeType && exports;
630 /** Detect free variable `module`. */
631 var freeModule$1 = freeExports$1 && typeof module == 'object' && module && !module.nodeType && module;
633 /** Detect the popular CommonJS extension `module.exports`. */
634 var moduleExports$1 = freeModule$1 && freeModule$1.exports === freeExports$1;
636 /** Detect free variable `process` from Node.js. */
637 var freeProcess = moduleExports$1 && freeGlobal.process;
639 /** Used to access faster Node.js helpers. */
640 var nodeUtil = (function() {
642 return freeProcess && freeProcess.binding && freeProcess.binding('util');
646 /* Node.js helper references. */
647 var nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray;
650 * Checks if `value` is classified as a typed array.
656 * @param {*} value The value to check.
657 * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
660 * _.isTypedArray(new Uint8Array);
663 * _.isTypedArray([]);
666 var isTypedArray = nodeIsTypedArray ? baseUnary(nodeIsTypedArray) : baseIsTypedArray;
668 /** Used for built-in method references. */
669 var objectProto$2 = Object.prototype;
671 /** Used to check objects for own properties. */
672 var hasOwnProperty$1 = objectProto$2.hasOwnProperty;
675 * Creates an array of the enumerable property names of the array-like `value`.
678 * @param {*} value The value to query.
679 * @param {boolean} inherited Specify returning inherited property names.
680 * @returns {Array} Returns the array of property names.
682 function arrayLikeKeys(value, inherited) {
683 var isArr = isArray(value),
684 isArg = !isArr && isArguments(value),
685 isBuff = !isArr && !isArg && isBuffer(value),
686 isType = !isArr && !isArg && !isBuff && isTypedArray(value),
687 skipIndexes = isArr || isArg || isBuff || isType,
688 result = skipIndexes ? baseTimes(value.length, String) : [],
689 length = result.length;
691 for (var key in value) {
692 if ((inherited || hasOwnProperty$1.call(value, key)) &&
694 // Safari 9 has enumerable `arguments.length` in strict mode.
696 // Node.js 0.10 has enumerable non-index properties on buffers.
697 (isBuff && (key == 'offset' || key == 'parent')) ||
698 // PhantomJS 2 has enumerable non-index properties on typed arrays.
699 (isType && (key == 'buffer' || key == 'byteLength' || key == 'byteOffset')) ||
700 // Skip index properties.
709 /** Used for built-in method references. */
710 var objectProto$5 = Object.prototype;
713 * Checks if `value` is likely a prototype object.
716 * @param {*} value The value to check.
717 * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
719 function isPrototype(value) {
720 var Ctor = value && value.constructor,
721 proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto$5;
723 return value === proto;
727 * Creates a unary function that invokes `func` with its argument transformed.
730 * @param {Function} func The function to wrap.
731 * @param {Function} transform The argument transform.
732 * @returns {Function} Returns the new function.
734 function overArg(func, transform) {
735 return function(arg) {
736 return func(transform(arg));
740 /* Built-in method references for those with the same name as other `lodash` methods. */
741 var nativeKeys = overArg(Object.keys, Object);
743 /** Used for built-in method references. */
744 var objectProto$4 = Object.prototype;
746 /** Used to check objects for own properties. */
747 var hasOwnProperty$3 = objectProto$4.hasOwnProperty;
750 * The base implementation of `_.keys` which doesn't treat sparse arrays as dense.
753 * @param {Object} object The object to query.
754 * @returns {Array} Returns the array of property names.
756 function baseKeys(object) {
757 if (!isPrototype(object)) {
758 return nativeKeys(object);
761 for (var key in Object(object)) {
762 if (hasOwnProperty$3.call(object, key) && key != 'constructor') {
770 * Creates an array of the own enumerable property names of `object`.
772 * **Note:** Non-object values are coerced to objects. See the
773 * [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
780 * @param {Object} object The object to query.
781 * @returns {Array} Returns the array of property names.
789 * Foo.prototype.c = 3;
792 * // => ['a', 'b'] (iteration order is not guaranteed)
797 function keys(object) {
798 return isArrayLike(object) ? arrayLikeKeys(object) : baseKeys(object);
801 function createArrayIterator(coll) {
803 var len = coll.length;
804 return function next() {
805 return ++i < len ? { value: coll[i], key: i } : null;
809 function createES2015Iterator(iterator) {
811 return function next() {
812 var item = iterator.next();
813 if (item.done) return null;
815 return { value: item.value, key: i };
819 function createObjectIterator(obj) {
820 var okeys = keys(obj);
822 var len = okeys.length;
823 return function next() {
824 var key = okeys[++i];
825 return i < len ? { value: obj[key], key: key } : null;
829 function iterator(coll) {
830 if (isArrayLike(coll)) {
831 return createArrayIterator(coll);
834 var iterator = getIterator(coll);
835 return iterator ? createES2015Iterator(iterator) : createObjectIterator(coll);
838 function onlyOnce(fn) {
840 if (fn === null) throw new Error("Callback was already called.");
843 callFn.apply(this, arguments);
847 function _eachOfLimit(limit) {
848 return function (obj, iteratee, callback) {
849 callback = once(callback || noop);
850 if (limit <= 0 || !obj) {
851 return callback(null);
853 var nextElem = iterator(obj);
857 function iterateeCallback(err, value) {
862 } else if (value === breakLoop || done && running <= 0) {
864 return callback(null);
870 function replenish() {
871 while (running < limit && !done) {
872 var elem = nextElem();
881 iteratee(elem.value, elem.key, onlyOnce(iterateeCallback));
890 * The same as [`eachOf`]{@link module:Collections.eachOf} but runs a maximum of `limit` async operations at a
895 * @memberOf module:Collections
897 * @see [async.eachOf]{@link module:Collections.eachOf}
898 * @alias forEachOfLimit
899 * @category Collection
900 * @param {Array|Iterable|Object} coll - A collection to iterate over.
901 * @param {number} limit - The maximum number of async operations at a time.
902 * @param {Function} iteratee - A function to apply to each
903 * item in `coll`. The `key` is the item's key, or index in the case of an
904 * array. The iteratee is passed a `callback(err)` which must be called once it
905 * has completed. If no error has occurred, the callback should be run without
906 * arguments or with an explicit `null` argument. Invoked with
907 * (item, key, callback).
908 * @param {Function} [callback] - A callback which is called when all
909 * `iteratee` functions have finished, or an error occurs. Invoked with (err).
911 function eachOfLimit(coll, limit, iteratee, callback) {
912 _eachOfLimit(limit)(coll, iteratee, callback);
915 function doLimit(fn, limit) {
916 return function (iterable, iteratee, callback) {
917 return fn(iterable, limit, iteratee, callback);
921 // eachOf implementation optimized for array-likes
922 function eachOfArrayLike(coll, iteratee, callback) {
923 callback = once(callback || noop);
926 length = coll.length;
931 function iteratorCallback(err, value) {
934 } else if (++completed === length || value === breakLoop) {
939 for (; index < length; index++) {
940 iteratee(coll[index], index, onlyOnce(iteratorCallback));
944 // a generic version of eachOf which can handle array, object, and iterator cases.
945 var eachOfGeneric = doLimit(eachOfLimit, Infinity);
948 * Like [`each`]{@link module:Collections.each}, except that it passes the key (or index) as the second argument
953 * @memberOf module:Collections
956 * @category Collection
957 * @see [async.each]{@link module:Collections.each}
958 * @param {Array|Iterable|Object} coll - A collection to iterate over.
959 * @param {Function} iteratee - A function to apply to each
960 * item in `coll`. The `key` is the item's key, or index in the case of an
961 * array. The iteratee is passed a `callback(err)` which must be called once it
962 * has completed. If no error has occurred, the callback should be run without
963 * arguments or with an explicit `null` argument. Invoked with
964 * (item, key, callback).
965 * @param {Function} [callback] - A callback which is called when all
966 * `iteratee` functions have finished, or an error occurs. Invoked with (err).
969 * var obj = {dev: "/dev.json", test: "/test.json", prod: "/prod.json"};
972 * async.forEachOf(obj, function (value, key, callback) {
973 * fs.readFile(__dirname + value, "utf8", function (err, data) {
974 * if (err) return callback(err);
976 * configs[key] = JSON.parse(data);
978 * return callback(e);
982 * }, function (err) {
983 * if (err) console.error(err.message);
984 * // configs is now a map of JSON data
985 * doSomethingWith(configs);
988 var eachOf = function (coll, iteratee, callback) {
989 var eachOfImplementation = isArrayLike(coll) ? eachOfArrayLike : eachOfGeneric;
990 eachOfImplementation(coll, iteratee, callback);
993 function doParallel(fn) {
994 return function (obj, iteratee, callback) {
995 return fn(eachOf, obj, iteratee, callback);
999 function _asyncMap(eachfn, arr, iteratee, callback) {
1000 callback = callback || noop;
1005 eachfn(arr, function (value, _, callback) {
1006 var index = counter++;
1007 iteratee(value, function (err, v) {
1012 callback(err, results);
1017 * Produces a new collection of values by mapping each value in `coll` through
1018 * the `iteratee` function. The `iteratee` is called with an item from `coll`
1019 * and a callback for when it has finished processing. Each of these callback
1020 * takes 2 arguments: an `error`, and the transformed item from `coll`. If
1021 * `iteratee` passes an error to its callback, the main `callback` (for the
1022 * `map` function) is immediately called with the error.
1024 * Note, that since this function applies the `iteratee` to each item in
1025 * parallel, there is no guarantee that the `iteratee` functions will complete
1026 * in order. However, the results array will be in the same order as the
1029 * If `map` is passed an Object, the results will be an Array. The results
1030 * will roughly be in the order of the original Objects' keys (but this can
1031 * vary across JavaScript engines)
1035 * @memberOf module:Collections
1037 * @category Collection
1038 * @param {Array|Iterable|Object} coll - A collection to iterate over.
1039 * @param {Function} iteratee - A function to apply to each item in `coll`.
1040 * The iteratee is passed a `callback(err, transformed)` which must be called
1041 * once it has completed with an error (which can be `null`) and a
1042 * transformed item. Invoked with (item, callback).
1043 * @param {Function} [callback] - A callback which is called when all `iteratee`
1044 * functions have finished, or an error occurs. Results is an Array of the
1045 * transformed items from the `coll`. Invoked with (err, results).
1048 * async.map(['file1','file2','file3'], fs.stat, function(err, results) {
1049 * // results is now an array of stats for each file
1052 var map = doParallel(_asyncMap);
1055 * Applies the provided arguments to each function in the array, calling
1056 * `callback` after all functions have completed. If you only provide the first
1057 * argument, `fns`, then it will return a function which lets you pass in the
1058 * arguments as if it were a single function call. If more arguments are
1059 * provided, `callback` is required while `args` is still optional.
1063 * @memberOf module:ControlFlow
1065 * @category Control Flow
1066 * @param {Array|Iterable|Object} fns - A collection of asynchronous functions
1067 * to all call with the same arguments
1068 * @param {...*} [args] - any number of separate arguments to pass to the
1070 * @param {Function} [callback] - the final argument should be the callback,
1071 * called when all functions have completed processing.
1072 * @returns {Function} - If only the first argument, `fns`, is provided, it will
1073 * return a function which lets you pass in the arguments as if it were a single
1074 * function call. The signature is `(..args, callback)`. If invoked with any
1075 * arguments, `callback` is required.
1078 * async.applyEach([enableSearch, updateSchema], 'bucket', callback);
1080 * // partial application example:
1083 * async.applyEach([enableSearch, updateSchema]),
1087 var applyEach = applyEach$1(map);
1089 function doParallelLimit(fn) {
1090 return function (obj, limit, iteratee, callback) {
1091 return fn(_eachOfLimit(limit), obj, iteratee, callback);
1096 * The same as [`map`]{@link module:Collections.map} but runs a maximum of `limit` async operations at a time.
1100 * @memberOf module:Collections
1102 * @see [async.map]{@link module:Collections.map}
1103 * @category Collection
1104 * @param {Array|Iterable|Object} coll - A collection to iterate over.
1105 * @param {number} limit - The maximum number of async operations at a time.
1106 * @param {Function} iteratee - A function to apply to each item in `coll`.
1107 * The iteratee is passed a `callback(err, transformed)` which must be called
1108 * once it has completed with an error (which can be `null`) and a transformed
1109 * item. Invoked with (item, callback).
1110 * @param {Function} [callback] - A callback which is called when all `iteratee`
1111 * functions have finished, or an error occurs. Results is an array of the
1112 * transformed items from the `coll`. Invoked with (err, results).
1114 var mapLimit = doParallelLimit(_asyncMap);
1117 * The same as [`map`]{@link module:Collections.map} but runs only a single async operation at a time.
1121 * @memberOf module:Collections
1123 * @see [async.map]{@link module:Collections.map}
1124 * @category Collection
1125 * @param {Array|Iterable|Object} coll - A collection to iterate over.
1126 * @param {Function} iteratee - A function to apply to each item in `coll`.
1127 * The iteratee is passed a `callback(err, transformed)` which must be called
1128 * once it has completed with an error (which can be `null`) and a
1129 * transformed item. Invoked with (item, callback).
1130 * @param {Function} [callback] - A callback which is called when all `iteratee`
1131 * functions have finished, or an error occurs. Results is an array of the
1132 * transformed items from the `coll`. Invoked with (err, results).
1134 var mapSeries = doLimit(mapLimit, 1);
1137 * The same as [`applyEach`]{@link module:ControlFlow.applyEach} but runs only a single async operation at a time.
1139 * @name applyEachSeries
1141 * @memberOf module:ControlFlow
1143 * @see [async.applyEach]{@link module:ControlFlow.applyEach}
1144 * @category Control Flow
1145 * @param {Array|Iterable|Object} fns - A collection of asynchronous functions to all
1146 * call with the same arguments
1147 * @param {...*} [args] - any number of separate arguments to pass to the
1149 * @param {Function} [callback] - the final argument should be the callback,
1150 * called when all functions have completed processing.
1151 * @returns {Function} - If only the first argument is provided, it will return
1152 * a function which lets you pass in the arguments as if it were a single
1155 var applyEachSeries = applyEach$1(mapSeries);
1158 * Creates a continuation function with some arguments already applied.
1160 * Useful as a shorthand when combined with other control flow functions. Any
1161 * arguments passed to the returned function are added to the arguments
1162 * originally passed to apply.
1166 * @memberOf module:Utils
1169 * @param {Function} function - The function you want to eventually apply all
1170 * arguments to. Invokes with (arguments...).
1171 * @param {...*} arguments... - Any number of arguments to automatically apply
1172 * when the continuation is called.
1177 * async.apply(fs.writeFile, 'testfile1', 'test1'),
1178 * async.apply(fs.writeFile, 'testfile2', 'test2')
1182 * // the same process without using apply
1184 * function(callback) {
1185 * fs.writeFile('testfile1', 'test1', callback);
1187 * function(callback) {
1188 * fs.writeFile('testfile2', 'test2', callback);
1192 * // It's possible to pass any number of additional arguments when calling the
1195 * node> var fn = async.apply(sys.puts, 'one');
1196 * node> fn('two', 'three');
1201 var apply$2 = rest(function (fn, args) {
1202 return rest(function (callArgs) {
1203 return fn.apply(null, args.concat(callArgs));
1208 * Take a sync function and make it async, passing its return value to a
1209 * callback. This is useful for plugging sync functions into a waterfall,
1210 * series, or other async functions. Any arguments passed to the generated
1211 * function will be passed to the wrapped function (except for the final
1212 * callback argument). Errors thrown will be passed to the callback.
1214 * If the function passed to `asyncify` returns a Promise, that promises's
1215 * resolved/rejected state will be used to call the callback, rather than simply
1216 * the synchronous return value.
1218 * This also means you can asyncify ES2016 `async` functions.
1222 * @memberOf module:Utils
1226 * @param {Function} func - The synchronous function to convert to an
1227 * asynchronous function.
1228 * @returns {Function} An asynchronous wrapper of the `func`. To be invoked with
1232 * // passing a regular synchronous function
1234 * async.apply(fs.readFile, filename, "utf8"),
1235 * async.asyncify(JSON.parse),
1236 * function (data, next) {
1237 * // data is the result of parsing the text.
1238 * // If there was a parsing error, it would have been caught.
1242 * // passing a function returning a promise
1244 * async.apply(fs.readFile, filename, "utf8"),
1245 * async.asyncify(function (contents) {
1246 * return db.model.create(contents);
1248 * function (model, next) {
1249 * // `model` is the instantiated model object.
1250 * // If there was an error, this function would be skipped.
1255 * var q = async.queue(async.asyncify(async function(file) {
1256 * var intermediateStep = await processFile(file);
1257 * return await somePromise(intermediateStep)
1262 function asyncify(func) {
1263 return initialParams(function (args, callback) {
1266 result = func.apply(this, args);
1270 // if result is Promise object
1271 if (isObject(result) && typeof result.then === 'function') {
1272 result.then(function (value) {
1273 callback(null, value);
1275 callback(err.message ? err : new Error(err));
1278 callback(null, result);
1284 * A specialized version of `_.forEach` for arrays without support for
1285 * iteratee shorthands.
1288 * @param {Array} [array] The array to iterate over.
1289 * @param {Function} iteratee The function invoked per iteration.
1290 * @returns {Array} Returns `array`.
1292 function arrayEach(array, iteratee) {
1294 length = array == null ? 0 : array.length;
1296 while (++index < length) {
1297 if (iteratee(array[index], index, array) === false) {
1305 * Creates a base function for methods like `_.forIn` and `_.forOwn`.
1308 * @param {boolean} [fromRight] Specify iterating from right to left.
1309 * @returns {Function} Returns the new base function.
1311 function createBaseFor(fromRight) {
1312 return function(object, iteratee, keysFunc) {
1314 iterable = Object(object),
1315 props = keysFunc(object),
1316 length = props.length;
1319 var key = props[fromRight ? length : ++index];
1320 if (iteratee(iterable[key], key, iterable) === false) {
1329 * The base implementation of `baseForOwn` which iterates over `object`
1330 * properties returned by `keysFunc` and invokes `iteratee` for each property.
1331 * Iteratee functions may exit iteration early by explicitly returning `false`.
1334 * @param {Object} object The object to iterate over.
1335 * @param {Function} iteratee The function invoked per iteration.
1336 * @param {Function} keysFunc The function to get the keys of `object`.
1337 * @returns {Object} Returns `object`.
1339 var baseFor = createBaseFor();
1342 * The base implementation of `_.forOwn` without support for iteratee shorthands.
1345 * @param {Object} object The object to iterate over.
1346 * @param {Function} iteratee The function invoked per iteration.
1347 * @returns {Object} Returns `object`.
1349 function baseForOwn(object, iteratee) {
1350 return object && baseFor(object, iteratee, keys);
1354 * The base implementation of `_.findIndex` and `_.findLastIndex` without
1355 * support for iteratee shorthands.
1358 * @param {Array} array The array to inspect.
1359 * @param {Function} predicate The function invoked per iteration.
1360 * @param {number} fromIndex The index to search from.
1361 * @param {boolean} [fromRight] Specify iterating from right to left.
1362 * @returns {number} Returns the index of the matched value, else `-1`.
1364 function baseFindIndex(array, predicate, fromIndex, fromRight) {
1365 var length = array.length,
1366 index = fromIndex + (fromRight ? 1 : -1);
1368 while ((fromRight ? index-- : ++index < length)) {
1369 if (predicate(array[index], index, array)) {
1377 * The base implementation of `_.isNaN` without support for number objects.
1380 * @param {*} value The value to check.
1381 * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
1383 function baseIsNaN(value) {
1384 return value !== value;
1388 * A specialized version of `_.indexOf` which performs strict equality
1389 * comparisons of values, i.e. `===`.
1392 * @param {Array} array The array to inspect.
1393 * @param {*} value The value to search for.
1394 * @param {number} fromIndex The index to search from.
1395 * @returns {number} Returns the index of the matched value, else `-1`.
1397 function strictIndexOf(array, value, fromIndex) {
1398 var index = fromIndex - 1,
1399 length = array.length;
1401 while (++index < length) {
1402 if (array[index] === value) {
1410 * The base implementation of `_.indexOf` without `fromIndex` bounds checks.
1413 * @param {Array} array The array to inspect.
1414 * @param {*} value The value to search for.
1415 * @param {number} fromIndex The index to search from.
1416 * @returns {number} Returns the index of the matched value, else `-1`.
1418 function baseIndexOf(array, value, fromIndex) {
1419 return value === value
1420 ? strictIndexOf(array, value, fromIndex)
1421 : baseFindIndex(array, baseIsNaN, fromIndex);
1425 * Determines the best order for running the functions in `tasks`, based on
1426 * their requirements. Each function can optionally depend on other functions
1427 * being completed first, and each function is run as soon as its requirements
1430 * If any of the functions pass an error to their callback, the `auto` sequence
1431 * will stop. Further tasks will not execute (so any other functions depending
1432 * on it will not run), and the main `callback` is immediately called with the
1435 * Functions also receive an object containing the results of functions which
1436 * have completed so far as the first argument, if they have dependencies. If a
1437 * task function has no dependencies, it will only be passed a callback.
1441 * @memberOf module:ControlFlow
1443 * @category Control Flow
1444 * @param {Object} tasks - An object. Each of its properties is either a
1445 * function or an array of requirements, with the function itself the last item
1446 * in the array. The object's key of a property serves as the name of the task
1447 * defined by that property, i.e. can be used when specifying requirements for
1448 * other tasks. The function receives one or two arguments:
1449 * * a `results` object, containing the results of the previously executed
1450 * functions, only passed if the task has any dependencies,
1451 * * a `callback(err, result)` function, which must be called when finished,
1452 * passing an `error` (which can be `null`) and the result of the function's
1454 * @param {number} [concurrency=Infinity] - An optional `integer` for
1455 * determining the maximum number of tasks that can be run in parallel. By
1456 * default, as many as possible.
1457 * @param {Function} [callback] - An optional callback which is called when all
1458 * the tasks have been completed. It receives the `err` argument if any `tasks`
1459 * pass an error to their callback. Results are always returned; however, if an
1460 * error occurs, no further `tasks` will be performed, and the results object
1461 * will only contain partial results. Invoked with (err, results).
1462 * @returns undefined
1466 * // this function will just be passed a callback
1467 * readData: async.apply(fs.readFile, 'data.txt', 'utf-8'),
1468 * showData: ['readData', function(results, cb) {
1469 * // results.readData is the file's contents
1475 * get_data: function(callback) {
1476 * console.log('in get_data');
1477 * // async code to get some data
1478 * callback(null, 'data', 'converted to array');
1480 * make_folder: function(callback) {
1481 * console.log('in make_folder');
1482 * // async code to create a directory to store a file in
1483 * // this is run at the same time as getting the data
1484 * callback(null, 'folder');
1486 * write_file: ['get_data', 'make_folder', function(results, callback) {
1487 * console.log('in write_file', JSON.stringify(results));
1488 * // once there is some data and the directory exists,
1489 * // write the data to a file in the directory
1490 * callback(null, 'filename');
1492 * email_link: ['write_file', function(results, callback) {
1493 * console.log('in email_link', JSON.stringify(results));
1494 * // once the file is written let's email a link to it...
1495 * // results.write_file contains the filename returned by write_file.
1496 * callback(null, {'file':results.write_file, 'email':'user@example.com'});
1498 * }, function(err, results) {
1499 * console.log('err = ', err);
1500 * console.log('results = ', results);
1503 var auto = function (tasks, concurrency, callback) {
1504 if (typeof concurrency === 'function') {
1505 // concurrency is optional, shift the args.
1506 callback = concurrency;
1509 callback = once(callback || noop);
1510 var keys$$1 = keys(tasks);
1511 var numTasks = keys$$1.length;
1513 return callback(null);
1516 concurrency = numTasks;
1520 var runningTasks = 0;
1521 var hasError = false;
1523 var listeners = Object.create(null);
1525 var readyTasks = [];
1527 // for cycle detection:
1528 var readyToCheck = []; // tasks that have been identified as reachable
1529 // without the possibility of returning to an ancestor task
1530 var uncheckedDependencies = {};
1532 baseForOwn(tasks, function (task, key) {
1533 if (!isArray(task)) {
1535 enqueueTask(key, [task]);
1536 readyToCheck.push(key);
1540 var dependencies = task.slice(0, task.length - 1);
1541 var remainingDependencies = dependencies.length;
1542 if (remainingDependencies === 0) {
1543 enqueueTask(key, task);
1544 readyToCheck.push(key);
1547 uncheckedDependencies[key] = remainingDependencies;
1549 arrayEach(dependencies, function (dependencyName) {
1550 if (!tasks[dependencyName]) {
1551 throw new Error('async.auto task `' + key + '` has a non-existent dependency `' + dependencyName + '` in ' + dependencies.join(', '));
1553 addListener(dependencyName, function () {
1554 remainingDependencies--;
1555 if (remainingDependencies === 0) {
1556 enqueueTask(key, task);
1562 checkForDeadlocks();
1565 function enqueueTask(key, task) {
1566 readyTasks.push(function () {
1571 function processQueue() {
1572 if (readyTasks.length === 0 && runningTasks === 0) {
1573 return callback(null, results);
1575 while (readyTasks.length && runningTasks < concurrency) {
1576 var run = readyTasks.shift();
1581 function addListener(taskName, fn) {
1582 var taskListeners = listeners[taskName];
1583 if (!taskListeners) {
1584 taskListeners = listeners[taskName] = [];
1587 taskListeners.push(fn);
1590 function taskComplete(taskName) {
1591 var taskListeners = listeners[taskName] || [];
1592 arrayEach(taskListeners, function (fn) {
1598 function runTask(key, task) {
1599 if (hasError) return;
1601 var taskCallback = onlyOnce(rest(function (err, args) {
1603 if (args.length <= 1) {
1607 var safeResults = {};
1608 baseForOwn(results, function (val, rkey) {
1609 safeResults[rkey] = val;
1611 safeResults[key] = args;
1613 listeners = Object.create(null);
1615 callback(err, safeResults);
1617 results[key] = args;
1623 var taskFn = task[task.length - 1];
1624 if (task.length > 1) {
1625 taskFn(results, taskCallback);
1627 taskFn(taskCallback);
1631 function checkForDeadlocks() {
1633 // https://en.wikipedia.org/wiki/Topological_sorting#Kahn.27s_algorithm
1634 // http://connalle.blogspot.com/2013/10/topological-sortingkahn-algorithm.html
1637 while (readyToCheck.length) {
1638 currentTask = readyToCheck.pop();
1640 arrayEach(getDependents(currentTask), function (dependent) {
1641 if (--uncheckedDependencies[dependent] === 0) {
1642 readyToCheck.push(dependent);
1647 if (counter !== numTasks) {
1648 throw new Error('async.auto cannot execute tasks due to a recursive dependency');
1652 function getDependents(taskName) {
1654 baseForOwn(tasks, function (task, key) {
1655 if (isArray(task) && baseIndexOf(task, taskName, 0) >= 0) {
1664 * A specialized version of `_.map` for arrays without support for iteratee
1668 * @param {Array} [array] The array to iterate over.
1669 * @param {Function} iteratee The function invoked per iteration.
1670 * @returns {Array} Returns the new mapped array.
1672 function arrayMap(array, iteratee) {
1674 length = array == null ? 0 : array.length,
1675 result = Array(length);
1677 while (++index < length) {
1678 result[index] = iteratee(array[index], index, array);
1683 /** `Object#toString` result references. */
1684 var symbolTag = '[object Symbol]';
1687 * Checks if `value` is classified as a `Symbol` primitive or object.
1693 * @param {*} value The value to check.
1694 * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
1697 * _.isSymbol(Symbol.iterator);
1700 * _.isSymbol('abc');
1703 function isSymbol(value) {
1704 return typeof value == 'symbol' ||
1705 (isObjectLike(value) && baseGetTag(value) == symbolTag);
1708 /** Used as references for various `Number` constants. */
1709 var INFINITY = 1 / 0;
1711 /** Used to convert symbols to primitives and strings. */
1712 var symbolProto = Symbol$1 ? Symbol$1.prototype : undefined;
1713 var symbolToString = symbolProto ? symbolProto.toString : undefined;
1716 * The base implementation of `_.toString` which doesn't convert nullish
1717 * values to empty strings.
1720 * @param {*} value The value to process.
1721 * @returns {string} Returns the string.
1723 function baseToString(value) {
1724 // Exit early for strings to avoid a performance hit in some environments.
1725 if (typeof value == 'string') {
1728 if (isArray(value)) {
1729 // Recursively convert values (susceptible to call stack limits).
1730 return arrayMap(value, baseToString) + '';
1732 if (isSymbol(value)) {
1733 return symbolToString ? symbolToString.call(value) : '';
1735 var result = (value + '');
1736 return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
1740 * The base implementation of `_.slice` without an iteratee call guard.
1743 * @param {Array} array The array to slice.
1744 * @param {number} [start=0] The start position.
1745 * @param {number} [end=array.length] The end position.
1746 * @returns {Array} Returns the slice of `array`.
1748 function baseSlice(array, start, end) {
1750 length = array.length;
1753 start = -start > length ? 0 : (length + start);
1755 end = end > length ? length : end;
1759 length = start > end ? 0 : ((end - start) >>> 0);
1762 var result = Array(length);
1763 while (++index < length) {
1764 result[index] = array[index + start];
1770 * Casts `array` to a slice if it's needed.
1773 * @param {Array} array The array to inspect.
1774 * @param {number} start The start position.
1775 * @param {number} [end=array.length] The end position.
1776 * @returns {Array} Returns the cast slice.
1778 function castSlice(array, start, end) {
1779 var length = array.length;
1780 end = end === undefined ? length : end;
1781 return (!start && end >= length) ? array : baseSlice(array, start, end);
1785 * Used by `_.trim` and `_.trimEnd` to get the index of the last string symbol
1786 * that is not found in the character symbols.
1789 * @param {Array} strSymbols The string symbols to inspect.
1790 * @param {Array} chrSymbols The character symbols to find.
1791 * @returns {number} Returns the index of the last unmatched string symbol.
1793 function charsEndIndex(strSymbols, chrSymbols) {
1794 var index = strSymbols.length;
1796 while (index-- && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {}
1801 * Used by `_.trim` and `_.trimStart` to get the index of the first string symbol
1802 * that is not found in the character symbols.
1805 * @param {Array} strSymbols The string symbols to inspect.
1806 * @param {Array} chrSymbols The character symbols to find.
1807 * @returns {number} Returns the index of the first unmatched string symbol.
1809 function charsStartIndex(strSymbols, chrSymbols) {
1811 length = strSymbols.length;
1813 while (++index < length && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {}
1818 * Converts an ASCII `string` to an array.
1821 * @param {string} string The string to convert.
1822 * @returns {Array} Returns the converted array.
1824 function asciiToArray(string) {
1825 return string.split('');
1828 /** Used to compose unicode character classes. */
1829 var rsAstralRange = '\\ud800-\\udfff';
1830 var rsComboMarksRange = '\\u0300-\\u036f';
1831 var reComboHalfMarksRange = '\\ufe20-\\ufe2f';
1832 var rsComboSymbolsRange = '\\u20d0-\\u20ff';
1833 var rsComboRange = rsComboMarksRange + reComboHalfMarksRange + rsComboSymbolsRange;
1834 var rsVarRange = '\\ufe0e\\ufe0f';
1836 /** Used to compose unicode capture groups. */
1837 var rsZWJ = '\\u200d';
1839 /** Used to detect strings with [zero-width joiners or code points from the astral planes](http://eev.ee/blog/2015/09/12/dark-corners-of-unicode/). */
1840 var reHasUnicode = RegExp('[' + rsZWJ + rsAstralRange + rsComboRange + rsVarRange + ']');
1843 * Checks if `string` contains Unicode symbols.
1846 * @param {string} string The string to inspect.
1847 * @returns {boolean} Returns `true` if a symbol is found, else `false`.
1849 function hasUnicode(string) {
1850 return reHasUnicode.test(string);
1853 /** Used to compose unicode character classes. */
1854 var rsAstralRange$1 = '\\ud800-\\udfff';
1855 var rsComboMarksRange$1 = '\\u0300-\\u036f';
1856 var reComboHalfMarksRange$1 = '\\ufe20-\\ufe2f';
1857 var rsComboSymbolsRange$1 = '\\u20d0-\\u20ff';
1858 var rsComboRange$1 = rsComboMarksRange$1 + reComboHalfMarksRange$1 + rsComboSymbolsRange$1;
1859 var rsVarRange$1 = '\\ufe0e\\ufe0f';
1861 /** Used to compose unicode capture groups. */
1862 var rsAstral = '[' + rsAstralRange$1 + ']';
1863 var rsCombo = '[' + rsComboRange$1 + ']';
1864 var rsFitz = '\\ud83c[\\udffb-\\udfff]';
1865 var rsModifier = '(?:' + rsCombo + '|' + rsFitz + ')';
1866 var rsNonAstral = '[^' + rsAstralRange$1 + ']';
1867 var rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}';
1868 var rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]';
1869 var rsZWJ$1 = '\\u200d';
1871 /** Used to compose unicode regexes. */
1872 var reOptMod = rsModifier + '?';
1873 var rsOptVar = '[' + rsVarRange$1 + ']?';
1874 var rsOptJoin = '(?:' + rsZWJ$1 + '(?:' + [rsNonAstral, rsRegional, rsSurrPair].join('|') + ')' + rsOptVar + reOptMod + ')*';
1875 var rsSeq = rsOptVar + reOptMod + rsOptJoin;
1876 var rsSymbol = '(?:' + [rsNonAstral + rsCombo + '?', rsCombo, rsRegional, rsSurrPair, rsAstral].join('|') + ')';
1878 /** Used to match [string symbols](https://mathiasbynens.be/notes/javascript-unicode). */
1879 var reUnicode = RegExp(rsFitz + '(?=' + rsFitz + ')|' + rsSymbol + rsSeq, 'g');
1882 * Converts a Unicode `string` to an array.
1885 * @param {string} string The string to convert.
1886 * @returns {Array} Returns the converted array.
1888 function unicodeToArray(string) {
1889 return string.match(reUnicode) || [];
1893 * Converts `string` to an array.
1896 * @param {string} string The string to convert.
1897 * @returns {Array} Returns the converted array.
1899 function stringToArray(string) {
1900 return hasUnicode(string)
1901 ? unicodeToArray(string)
1902 : asciiToArray(string);
1906 * Converts `value` to a string. An empty string is returned for `null`
1907 * and `undefined` values. The sign of `-0` is preserved.
1913 * @param {*} value The value to convert.
1914 * @returns {string} Returns the converted string.
1923 * _.toString([1, 2, 3]);
1926 function toString(value) {
1927 return value == null ? '' : baseToString(value);
1930 /** Used to match leading and trailing whitespace. */
1931 var reTrim = /^\s+|\s+$/g;
1934 * Removes leading and trailing whitespace or specified characters from `string`.
1940 * @param {string} [string=''] The string to trim.
1941 * @param {string} [chars=whitespace] The characters to trim.
1942 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
1943 * @returns {string} Returns the trimmed string.
1949 * _.trim('-_-abc-_-', '_-');
1952 * _.map([' foo ', ' bar '], _.trim);
1953 * // => ['foo', 'bar']
1955 function trim(string, chars, guard) {
1956 string = toString(string);
1957 if (string && (guard || chars === undefined)) {
1958 return string.replace(reTrim, '');
1960 if (!string || !(chars = baseToString(chars))) {
1963 var strSymbols = stringToArray(string),
1964 chrSymbols = stringToArray(chars),
1965 start = charsStartIndex(strSymbols, chrSymbols),
1966 end = charsEndIndex(strSymbols, chrSymbols) + 1;
1968 return castSlice(strSymbols, start, end).join('');
1971 var FN_ARGS = /^(function)?\s*[^\(]*\(\s*([^\)]*)\)/m;
1972 var FN_ARG_SPLIT = /,/;
1973 var FN_ARG = /(=.+)?(\s*)$/;
1974 var STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg;
1976 function parseParams(func) {
1977 func = func.toString().replace(STRIP_COMMENTS, '');
1978 func = func.match(FN_ARGS)[2].replace(' ', '');
1979 func = func ? func.split(FN_ARG_SPLIT) : [];
1980 func = func.map(function (arg) {
1981 return trim(arg.replace(FN_ARG, ''));
1987 * A dependency-injected version of the [async.auto]{@link module:ControlFlow.auto} function. Dependent
1988 * tasks are specified as parameters to the function, after the usual callback
1989 * parameter, with the parameter names matching the names of the tasks it
1990 * depends on. This can provide even more readable task graphs which can be
1991 * easier to maintain.
1993 * If a final callback is specified, the task results are similarly injected,
1994 * specified as named parameters after the initial error parameter.
1996 * The autoInject function is purely syntactic sugar and its semantics are
1997 * otherwise equivalent to [async.auto]{@link module:ControlFlow.auto}.
2001 * @memberOf module:ControlFlow
2003 * @see [async.auto]{@link module:ControlFlow.auto}
2004 * @category Control Flow
2005 * @param {Object} tasks - An object, each of whose properties is a function of
2006 * the form 'func([dependencies...], callback). The object's key of a property
2007 * serves as the name of the task defined by that property, i.e. can be used
2008 * when specifying requirements for other tasks.
2009 * * The `callback` parameter is a `callback(err, result)` which must be called
2010 * when finished, passing an `error` (which can be `null`) and the result of
2011 * the function's execution. The remaining parameters name other tasks on
2012 * which the task is dependent, and the results from those tasks are the
2013 * arguments of those parameters.
2014 * @param {Function} [callback] - An optional callback which is called when all
2015 * the tasks have been completed. It receives the `err` argument if any `tasks`
2016 * pass an error to their callback, and a `results` object with any completed
2017 * task results, similar to `auto`.
2020 * // The example from `auto` can be rewritten as follows:
2021 * async.autoInject({
2022 * get_data: function(callback) {
2023 * // async code to get some data
2024 * callback(null, 'data', 'converted to array');
2026 * make_folder: function(callback) {
2027 * // async code to create a directory to store a file in
2028 * // this is run at the same time as getting the data
2029 * callback(null, 'folder');
2031 * write_file: function(get_data, make_folder, callback) {
2032 * // once there is some data and the directory exists,
2033 * // write the data to a file in the directory
2034 * callback(null, 'filename');
2036 * email_link: function(write_file, callback) {
2037 * // once the file is written let's email a link to it...
2038 * // write_file contains the filename returned by write_file.
2039 * callback(null, {'file':write_file, 'email':'user@example.com'});
2041 * }, function(err, results) {
2042 * console.log('err = ', err);
2043 * console.log('email_link = ', results.email_link);
2046 * // If you are using a JS minifier that mangles parameter names, `autoInject`
2047 * // will not work with plain functions, since the parameter names will be
2048 * // collapsed to a single letter identifier. To work around this, you can
2049 * // explicitly specify the names of the parameters your task function needs
2050 * // in an array, similar to Angular.js dependency injection.
2052 * // This still has an advantage over plain `auto`, since the results a task
2053 * // depends on are still spread into arguments.
2054 * async.autoInject({
2056 * write_file: ['get_data', 'make_folder', function(get_data, make_folder, callback) {
2057 * callback(null, 'filename');
2059 * email_link: ['write_file', function(write_file, callback) {
2060 * callback(null, {'file':write_file, 'email':'user@example.com'});
2063 * }, function(err, results) {
2064 * console.log('err = ', err);
2065 * console.log('email_link = ', results.email_link);
2068 function autoInject(tasks, callback) {
2071 baseForOwn(tasks, function (taskFn, key) {
2074 if (isArray(taskFn)) {
2075 params = taskFn.slice(0, -1);
2076 taskFn = taskFn[taskFn.length - 1];
2078 newTasks[key] = params.concat(params.length > 0 ? newTask : taskFn);
2079 } else if (taskFn.length === 1) {
2080 // no dependencies, use the function as-is
2081 newTasks[key] = taskFn;
2083 params = parseParams(taskFn);
2084 if (taskFn.length === 0 && params.length === 0) {
2085 throw new Error("autoInject task functions require explicit parameters.");
2090 newTasks[key] = params.concat(newTask);
2093 function newTask(results, taskCb) {
2094 var newArgs = arrayMap(params, function (name) {
2095 return results[name];
2097 newArgs.push(taskCb);
2098 taskFn.apply(null, newArgs);
2102 auto(newTasks, callback);
2105 var hasSetImmediate = typeof setImmediate === 'function' && setImmediate;
2106 var hasNextTick = typeof process === 'object' && typeof process.nextTick === 'function';
2108 function fallback(fn) {
2112 function wrap(defer) {
2113 return rest(function (fn, args) {
2115 fn.apply(null, args);
2122 if (hasSetImmediate) {
2123 _defer = setImmediate;
2124 } else if (hasNextTick) {
2125 _defer = process.nextTick;
2130 var setImmediate$1 = wrap(_defer);
2132 // Simple doubly linked list (https://en.wikipedia.org/wiki/Doubly_linked_list) implementation
2133 // used for queues. This implementation assumes that the node provided by the user can be modified
2134 // to adjust the next and last properties. We implement only the minimal functionality
2135 // for queue support.
2137 this.head = this.tail = null;
2141 function setInitial(dll, node) {
2143 dll.head = dll.tail = node;
2146 DLL.prototype.removeLink = function (node) {
2147 if (node.prev) node.prev.next = node.next;else this.head = node.next;
2148 if (node.next) node.next.prev = node.prev;else this.tail = node.prev;
2150 node.prev = node.next = null;
2155 DLL.prototype.empty = DLL;
2157 DLL.prototype.insertAfter = function (node, newNode) {
2158 newNode.prev = node;
2159 newNode.next = node.next;
2160 if (node.next) node.next.prev = newNode;else this.tail = newNode;
2161 node.next = newNode;
2165 DLL.prototype.insertBefore = function (node, newNode) {
2166 newNode.prev = node.prev;
2167 newNode.next = node;
2168 if (node.prev) node.prev.next = newNode;else this.head = newNode;
2169 node.prev = newNode;
2173 DLL.prototype.unshift = function (node) {
2174 if (this.head) this.insertBefore(this.head, node);else setInitial(this, node);
2177 DLL.prototype.push = function (node) {
2178 if (this.tail) this.insertAfter(this.tail, node);else setInitial(this, node);
2181 DLL.prototype.shift = function () {
2182 return this.head && this.removeLink(this.head);
2185 DLL.prototype.pop = function () {
2186 return this.tail && this.removeLink(this.tail);
2189 function queue(worker, concurrency, payload) {
2190 if (concurrency == null) {
2192 } else if (concurrency === 0) {
2193 throw new Error('Concurrency must not be zero');
2196 function _insert(data, insertAtFront, callback) {
2197 if (callback != null && typeof callback !== 'function') {
2198 throw new Error('task callback must be a function');
2201 if (!isArray(data)) {
2204 if (data.length === 0 && q.idle()) {
2205 // call drain immediately if there are no tasks
2206 return setImmediate$1(function () {
2211 for (var i = 0, l = data.length; i < l; i++) {
2214 callback: callback || noop
2217 if (insertAtFront) {
2218 q._tasks.unshift(item);
2220 q._tasks.push(item);
2223 setImmediate$1(q.process);
2226 function _next(tasks) {
2227 return rest(function (args) {
2230 for (var i = 0, l = tasks.length; i < l; i++) {
2231 var task = tasks[i];
2232 var index = baseIndexOf(workersList, task, 0);
2234 workersList.splice(index);
2237 task.callback.apply(task, args);
2239 if (args[0] != null) {
2240 q.error(args[0], task.data);
2244 if (workers <= q.concurrency - q.buffer) {
2256 var workersList = [];
2257 var isProcessing = false;
2260 concurrency: concurrency,
2264 buffer: concurrency / 4,
2270 push: function (data, callback) {
2271 _insert(data, false, callback);
2277 unshift: function (data, callback) {
2278 _insert(data, true, callback);
2280 process: function () {
2281 // Avoid trying to start too many processing operations. This can occur
2282 // when callbacks resolve synchronously (#1267).
2286 isProcessing = true;
2287 while (!q.paused && workers < q.concurrency && q._tasks.length) {
2290 var l = q._tasks.length;
2291 if (q.payload) l = Math.min(l, q.payload);
2292 for (var i = 0; i < l; i++) {
2293 var node = q._tasks.shift();
2295 data.push(node.data);
2298 if (q._tasks.length === 0) {
2302 workersList.push(tasks[0]);
2304 if (workers === q.concurrency) {
2308 var cb = onlyOnce(_next(tasks));
2311 isProcessing = false;
2313 length: function () {
2314 return q._tasks.length;
2316 running: function () {
2319 workersList: function () {
2323 return q._tasks.length + workers === 0;
2325 pause: function () {
2328 resume: function () {
2329 if (q.paused === false) {
2333 setImmediate$1(q.process);
2340 * A cargo of tasks for the worker function to complete. Cargo inherits all of
2341 * the same methods and event callbacks as [`queue`]{@link module:ControlFlow.queue}.
2342 * @typedef {Object} CargoObject
2343 * @memberOf module:ControlFlow
2344 * @property {Function} length - A function returning the number of items
2345 * waiting to be processed. Invoke like `cargo.length()`.
2346 * @property {number} payload - An `integer` for determining how many tasks
2347 * should be process per round. This property can be changed after a `cargo` is
2348 * created to alter the payload on-the-fly.
2349 * @property {Function} push - Adds `task` to the `queue`. The callback is
2350 * called once the `worker` has finished processing the task. Instead of a
2351 * single task, an array of `tasks` can be submitted. The respective callback is
2352 * used for every task in the list. Invoke like `cargo.push(task, [callback])`.
2353 * @property {Function} saturated - A callback that is called when the
2354 * `queue.length()` hits the concurrency and further tasks will be queued.
2355 * @property {Function} empty - A callback that is called when the last item
2356 * from the `queue` is given to a `worker`.
2357 * @property {Function} drain - A callback that is called when the last item
2358 * from the `queue` has returned from the `worker`.
2359 * @property {Function} idle - a function returning false if there are items
2360 * waiting or being processed, or true if not. Invoke like `cargo.idle()`.
2361 * @property {Function} pause - a function that pauses the processing of tasks
2362 * until `resume()` is called. Invoke like `cargo.pause()`.
2363 * @property {Function} resume - a function that resumes the processing of
2364 * queued tasks when the queue is paused. Invoke like `cargo.resume()`.
2365 * @property {Function} kill - a function that removes the `drain` callback and
2366 * empties remaining tasks from the queue forcing it to go idle. Invoke like `cargo.kill()`.
2370 * Creates a `cargo` object with the specified payload. Tasks added to the
2371 * cargo will be processed altogether (up to the `payload` limit). If the
2372 * `worker` is in progress, the task is queued until it becomes available. Once
2373 * the `worker` has completed some tasks, each callback of those tasks is
2374 * called. Check out [these](https://camo.githubusercontent.com/6bbd36f4cf5b35a0f11a96dcd2e97711ffc2fb37/68747470733a2f2f662e636c6f75642e6769746875622e636f6d2f6173736574732f313637363837312f36383130382f62626330636662302d356632392d313165322d393734662d3333393763363464633835382e676966) [animations](https://camo.githubusercontent.com/f4810e00e1c5f5f8addbe3e9f49064fd5d102699/68747470733a2f2f662e636c6f75642e6769746875622e636f6d2f6173736574732f313637363837312f36383130312f38346339323036362d356632392d313165322d383134662d3964336430323431336266642e676966)
2375 * for how `cargo` and `queue` work.
2377 * While [`queue`]{@link module:ControlFlow.queue} passes only one task to one of a group of workers
2378 * at a time, cargo passes an array of tasks to a single worker, repeating
2379 * when the worker is finished.
2383 * @memberOf module:ControlFlow
2385 * @see [async.queue]{@link module:ControlFlow.queue}
2386 * @category Control Flow
2387 * @param {Function} worker - An asynchronous function for processing an array
2388 * of queued tasks, which must call its `callback(err)` argument when finished,
2389 * with an optional `err` argument. Invoked with `(tasks, callback)`.
2390 * @param {number} [payload=Infinity] - An optional `integer` for determining
2391 * how many tasks should be processed per round; if omitted, the default is
2393 * @returns {module:ControlFlow.CargoObject} A cargo object to manage the tasks. Callbacks can
2394 * attached as certain properties to listen for specific events during the
2395 * lifecycle of the cargo and inner queue.
2398 * // create a cargo object with payload 2
2399 * var cargo = async.cargo(function(tasks, callback) {
2400 * for (var i=0; i<tasks.length; i++) {
2401 * console.log('hello ' + tasks[i].name);
2407 * cargo.push({name: 'foo'}, function(err) {
2408 * console.log('finished processing foo');
2410 * cargo.push({name: 'bar'}, function(err) {
2411 * console.log('finished processing bar');
2413 * cargo.push({name: 'baz'}, function(err) {
2414 * console.log('finished processing baz');
2417 function cargo(worker, payload) {
2418 return queue(worker, 1, payload);
2422 * The same as [`eachOf`]{@link module:Collections.eachOf} but runs only a single async operation at a time.
2424 * @name eachOfSeries
2426 * @memberOf module:Collections
2428 * @see [async.eachOf]{@link module:Collections.eachOf}
2429 * @alias forEachOfSeries
2430 * @category Collection
2431 * @param {Array|Iterable|Object} coll - A collection to iterate over.
2432 * @param {Function} iteratee - A function to apply to each item in `coll`. The
2433 * `key` is the item's key, or index in the case of an array. The iteratee is
2434 * passed a `callback(err)` which must be called once it has completed. If no
2435 * error has occurred, the callback should be run without arguments or with an
2436 * explicit `null` argument. Invoked with (item, key, callback).
2437 * @param {Function} [callback] - A callback which is called when all `iteratee`
2438 * functions have finished, or an error occurs. Invoked with (err).
2440 var eachOfSeries = doLimit(eachOfLimit, 1);
2443 * Reduces `coll` into a single value using an async `iteratee` to return each
2444 * successive step. `memo` is the initial state of the reduction. This function
2445 * only operates in series.
2447 * For performance reasons, it may make sense to split a call to this function
2448 * into a parallel map, and then use the normal `Array.prototype.reduce` on the
2449 * results. This function is for situations where each step in the reduction
2450 * needs to be async; if you can get the data before reducing it, then it's
2451 * probably a good idea to do so.
2455 * @memberOf module:Collections
2459 * @category Collection
2460 * @param {Array|Iterable|Object} coll - A collection to iterate over.
2461 * @param {*} memo - The initial state of the reduction.
2462 * @param {Function} iteratee - A function applied to each item in the
2463 * array to produce the next step in the reduction. The `iteratee` is passed a
2464 * `callback(err, reduction)` which accepts an optional error as its first
2465 * argument, and the state of the reduction as the second. If an error is
2466 * passed to the callback, the reduction is stopped and the main `callback` is
2467 * immediately called with the error. Invoked with (memo, item, callback).
2468 * @param {Function} [callback] - A callback which is called after all the
2469 * `iteratee` functions have finished. Result is the reduced value. Invoked with
2473 * async.reduce([1,2,3], 0, function(memo, item, callback) {
2474 * // pointless async:
2475 * process.nextTick(function() {
2476 * callback(null, memo + item)
2478 * }, function(err, result) {
2479 * // result is now equal to the last value of memo, which is 6
2482 function reduce(coll, memo, iteratee, callback) {
2483 callback = once(callback || noop);
2484 eachOfSeries(coll, function (x, i, callback) {
2485 iteratee(memo, x, function (err, v) {
2490 callback(err, memo);
2495 * Version of the compose function that is more natural to read. Each function
2496 * consumes the return value of the previous function. It is the equivalent of
2497 * [compose]{@link module:ControlFlow.compose} with the arguments reversed.
2499 * Each function is executed with the `this` binding of the composed function.
2503 * @memberOf module:ControlFlow
2505 * @see [async.compose]{@link module:ControlFlow.compose}
2506 * @category Control Flow
2507 * @param {...Function} functions - the asynchronous functions to compose
2508 * @returns {Function} a function that composes the `functions` in order
2511 * // Requires lodash (or underscore), express3 and dresende's orm2.
2512 * // Part of an app, that fetches cats of the logged user.
2513 * // This example uses `seq` function to avoid overnesting and error
2514 * // handling clutter.
2515 * app.get('/cats', function(request, response) {
2516 * var User = request.models.User;
2518 * _.bind(User.get, User), // 'User.get' has signature (id, callback(err, data))
2519 * function(user, fn) {
2520 * user.getCats(fn); // 'getCats' has signature (callback(err, data))
2522 * )(req.session.user_id, function (err, cats) {
2524 * console.error(err);
2525 * response.json({ status: 'error', message: err.message });
2527 * response.json({ status: 'ok', message: 'Cats found', data: cats });
2532 var seq$1 = rest(function seq(functions) {
2533 return rest(function (args) {
2536 var cb = args[args.length - 1];
2537 if (typeof cb == 'function') {
2543 reduce(functions, args, function (newargs, fn, cb) {
2544 fn.apply(that, newargs.concat(rest(function (err, nextargs) {
2547 }, function (err, results) {
2548 cb.apply(that, [err].concat(results));
2554 * Creates a function which is a composition of the passed asynchronous
2555 * functions. Each function consumes the return value of the function that
2556 * follows. Composing functions `f()`, `g()`, and `h()` would produce the result
2557 * of `f(g(h()))`, only this version uses callbacks to obtain the return values.
2559 * Each function is executed with the `this` binding of the composed function.
2563 * @memberOf module:ControlFlow
2565 * @category Control Flow
2566 * @param {...Function} functions - the asynchronous functions to compose
2567 * @returns {Function} an asynchronous function that is the composed
2568 * asynchronous `functions`
2571 * function add1(n, callback) {
2572 * setTimeout(function () {
2573 * callback(null, n + 1);
2577 * function mul3(n, callback) {
2578 * setTimeout(function () {
2579 * callback(null, n * 3);
2583 * var add1mul3 = async.compose(mul3, add1);
2584 * add1mul3(4, function (err, result) {
2585 * // result now equals 15
2588 var compose = rest(function (args) {
2589 return seq$1.apply(null, args.reverse());
2592 function concat$1(eachfn, arr, fn, callback) {
2594 eachfn(arr, function (x, index, cb) {
2595 fn(x, function (err, y) {
2596 result = result.concat(y || []);
2600 callback(err, result);
2605 * Applies `iteratee` to each item in `coll`, concatenating the results. Returns
2606 * the concatenated list. The `iteratee`s are called in parallel, and the
2607 * results are concatenated as they return. There is no guarantee that the
2608 * results array will be returned in the original order of `coll` passed to the
2609 * `iteratee` function.
2613 * @memberOf module:Collections
2615 * @category Collection
2616 * @param {Array|Iterable|Object} coll - A collection to iterate over.
2617 * @param {Function} iteratee - A function to apply to each item in `coll`.
2618 * The iteratee is passed a `callback(err, results)` which must be called once
2619 * it has completed with an error (which can be `null`) and an array of results.
2620 * Invoked with (item, callback).
2621 * @param {Function} [callback(err)] - A callback which is called after all the
2622 * `iteratee` functions have finished, or an error occurs. Results is an array
2623 * containing the concatenated results of the `iteratee` function. Invoked with
2627 * async.concat(['dir1','dir2','dir3'], fs.readdir, function(err, files) {
2628 * // files is now a list of filenames that exist in the 3 directories
2631 var concat = doParallel(concat$1);
2633 function doSeries(fn) {
2634 return function (obj, iteratee, callback) {
2635 return fn(eachOfSeries, obj, iteratee, callback);
2640 * The same as [`concat`]{@link module:Collections.concat} but runs only a single async operation at a time.
2642 * @name concatSeries
2644 * @memberOf module:Collections
2646 * @see [async.concat]{@link module:Collections.concat}
2647 * @category Collection
2648 * @param {Array|Iterable|Object} coll - A collection to iterate over.
2649 * @param {Function} iteratee - A function to apply to each item in `coll`.
2650 * The iteratee is passed a `callback(err, results)` which must be called once
2651 * it has completed with an error (which can be `null`) and an array of results.
2652 * Invoked with (item, callback).
2653 * @param {Function} [callback(err)] - A callback which is called after all the
2654 * `iteratee` functions have finished, or an error occurs. Results is an array
2655 * containing the concatenated results of the `iteratee` function. Invoked with
2658 var concatSeries = doSeries(concat$1);
2661 * Returns a function that when called, calls-back with the values provided.
2662 * Useful as the first function in a [`waterfall`]{@link module:ControlFlow.waterfall}, or for plugging values in to
2663 * [`auto`]{@link module:ControlFlow.auto}.
2667 * @memberOf module:Utils
2670 * @param {...*} arguments... - Any number of arguments to automatically invoke
2672 * @returns {Function} Returns a function that when invoked, automatically
2673 * invokes the callback with the previous given arguments.
2677 * async.constant(42),
2678 * function (value, next) {
2685 * async.constant(filename, "utf8"),
2687 * function (fileData, next) {
2694 * hostname: async.constant("https://server.net/"),
2695 * port: findFreePort,
2696 * launchServer: ["hostname", "port", function (options, cb) {
2697 * startServer(options, cb);
2702 var constant = rest(function (values) {
2703 var args = [null].concat(values);
2704 return initialParams(function (ignoredArgs, callback) {
2705 return callback.apply(this, args);
2709 function _createTester(check, getResult) {
2710 return function (eachfn, arr, iteratee, cb) {
2712 var testPassed = false;
2714 eachfn(arr, function (value, _, callback) {
2715 iteratee(value, function (err, result) {
2718 } else if (check(result) && !testResult) {
2720 testResult = getResult(true, value);
2721 callback(null, breakLoop);
2730 cb(null, testPassed ? testResult : getResult(false));
2736 function _findGetResult(v, x) {
2741 * Returns the first value in `coll` that passes an async truth test. The
2742 * `iteratee` is applied in parallel, meaning the first iteratee to return
2743 * `true` will fire the detect `callback` with that result. That means the
2744 * result might not be the first item in the original `coll` (in terms of order)
2745 * that passes the test.
2747 * If order within the original `coll` is important, then look at
2748 * [`detectSeries`]{@link module:Collections.detectSeries}.
2752 * @memberOf module:Collections
2755 * @category Collections
2756 * @param {Array|Iterable|Object} coll - A collection to iterate over.
2757 * @param {Function} iteratee - A truth test to apply to each item in `coll`.
2758 * The iteratee is passed a `callback(err, truthValue)` which must be called
2759 * with a boolean argument once it has completed. Invoked with (item, callback).
2760 * @param {Function} [callback] - A callback which is called as soon as any
2761 * iteratee returns `true`, or after all the `iteratee` functions have finished.
2762 * Result will be the first item in the array that passes the truth test
2763 * (iteratee) or the value `undefined` if none passed. Invoked with
2767 * async.detect(['file1','file2','file3'], function(filePath, callback) {
2768 * fs.access(filePath, function(err) {
2769 * callback(null, !err)
2771 * }, function(err, result) {
2772 * // result now equals the first file in the list that exists
2775 var detect = doParallel(_createTester(identity, _findGetResult));
2778 * The same as [`detect`]{@link module:Collections.detect} but runs a maximum of `limit` async operations at a
2783 * @memberOf module:Collections
2785 * @see [async.detect]{@link module:Collections.detect}
2787 * @category Collections
2788 * @param {Array|Iterable|Object} coll - A collection to iterate over.
2789 * @param {number} limit - The maximum number of async operations at a time.
2790 * @param {Function} iteratee - A truth test to apply to each item in `coll`.
2791 * The iteratee is passed a `callback(err, truthValue)` which must be called
2792 * with a boolean argument once it has completed. Invoked with (item, callback).
2793 * @param {Function} [callback] - A callback which is called as soon as any
2794 * iteratee returns `true`, or after all the `iteratee` functions have finished.
2795 * Result will be the first item in the array that passes the truth test
2796 * (iteratee) or the value `undefined` if none passed. Invoked with
2799 var detectLimit = doParallelLimit(_createTester(identity, _findGetResult));
2802 * The same as [`detect`]{@link module:Collections.detect} but runs only a single async operation at a time.
2804 * @name detectSeries
2806 * @memberOf module:Collections
2808 * @see [async.detect]{@link module:Collections.detect}
2810 * @category Collections
2811 * @param {Array|Iterable|Object} coll - A collection to iterate over.
2812 * @param {Function} iteratee - A truth test to apply to each item in `coll`.
2813 * The iteratee is passed a `callback(err, truthValue)` which must be called
2814 * with a boolean argument once it has completed. Invoked with (item, callback).
2815 * @param {Function} [callback] - A callback which is called as soon as any
2816 * iteratee returns `true`, or after all the `iteratee` functions have finished.
2817 * Result will be the first item in the array that passes the truth test
2818 * (iteratee) or the value `undefined` if none passed. Invoked with
2821 var detectSeries = doLimit(detectLimit, 1);
2823 function consoleFunc(name) {
2824 return rest(function (fn, args) {
2825 fn.apply(null, args.concat(rest(function (err, args) {
2826 if (typeof console === 'object') {
2828 if (console.error) {
2831 } else if (console[name]) {
2832 arrayEach(args, function (x) {
2842 * Logs the result of an `async` function to the `console` using `console.dir`
2843 * to display the properties of the resulting object. Only works in Node.js or
2844 * in browsers that support `console.dir` and `console.error` (such as FF and
2845 * Chrome). If multiple arguments are returned from the async function,
2846 * `console.dir` is called on each argument in order.
2850 * @memberOf module:Utils
2853 * @param {Function} function - The function you want to eventually apply all
2855 * @param {...*} arguments... - Any number of arguments to apply to the function.
2859 * var hello = function(name, callback) {
2860 * setTimeout(function() {
2861 * callback(null, {hello: name});
2865 * // in the node repl
2866 * node> async.dir(hello, 'world');
2869 var dir = consoleFunc('dir');
2872 * The post-check version of [`during`]{@link module:ControlFlow.during}. To reflect the difference in
2873 * the order of operations, the arguments `test` and `fn` are switched.
2875 * Also a version of [`doWhilst`]{@link module:ControlFlow.doWhilst} with asynchronous `test` function.
2878 * @memberOf module:ControlFlow
2880 * @see [async.during]{@link module:ControlFlow.during}
2881 * @category Control Flow
2882 * @param {Function} fn - A function which is called each time `test` passes.
2883 * The function is passed a `callback(err)`, which must be called once it has
2884 * completed with an optional `err` argument. Invoked with (callback).
2885 * @param {Function} test - asynchronous truth test to perform before each
2886 * execution of `fn`. Invoked with (...args, callback), where `...args` are the
2887 * non-error args from the previous callback of `fn`.
2888 * @param {Function} [callback] - A callback which is called after the test
2889 * function has failed and repeated execution of `fn` has stopped. `callback`
2890 * will be passed an error if one occured, otherwise `null`.
2892 function doDuring(fn, test, callback) {
2893 callback = onlyOnce(callback || noop);
2895 var next = rest(function (err, args) {
2896 if (err) return callback(err);
2898 test.apply(this, args);
2901 function check(err, truth) {
2902 if (err) return callback(err);
2903 if (!truth) return callback(null);
2911 * The post-check version of [`whilst`]{@link module:ControlFlow.whilst}. To reflect the difference in
2912 * the order of operations, the arguments `test` and `iteratee` are switched.
2914 * `doWhilst` is to `whilst` as `do while` is to `while` in plain JavaScript.
2918 * @memberOf module:ControlFlow
2920 * @see [async.whilst]{@link module:ControlFlow.whilst}
2921 * @category Control Flow
2922 * @param {Function} iteratee - A function which is called each time `test`
2923 * passes. The function is passed a `callback(err)`, which must be called once
2924 * it has completed with an optional `err` argument. Invoked with (callback).
2925 * @param {Function} test - synchronous truth test to perform after each
2926 * execution of `iteratee`. Invoked with the non-error callback results of
2928 * @param {Function} [callback] - A callback which is called after the test
2929 * function has failed and repeated execution of `iteratee` has stopped.
2930 * `callback` will be passed an error and any arguments passed to the final
2931 * `iteratee`'s callback. Invoked with (err, [results]);
2933 function doWhilst(iteratee, test, callback) {
2934 callback = onlyOnce(callback || noop);
2935 var next = rest(function (err, args) {
2936 if (err) return callback(err);
2937 if (test.apply(this, args)) return iteratee(next);
2938 callback.apply(null, [null].concat(args));
2944 * Like ['doWhilst']{@link module:ControlFlow.doWhilst}, except the `test` is inverted. Note the
2945 * argument ordering differs from `until`.
2949 * @memberOf module:ControlFlow
2951 * @see [async.doWhilst]{@link module:ControlFlow.doWhilst}
2952 * @category Control Flow
2953 * @param {Function} fn - A function which is called each time `test` fails.
2954 * The function is passed a `callback(err)`, which must be called once it has
2955 * completed with an optional `err` argument. Invoked with (callback).
2956 * @param {Function} test - synchronous truth test to perform after each
2957 * execution of `fn`. Invoked with the non-error callback results of `fn`.
2958 * @param {Function} [callback] - A callback which is called after the test
2959 * function has passed and repeated execution of `fn` has stopped. `callback`
2960 * will be passed an error and any arguments passed to the final `fn`'s
2961 * callback. Invoked with (err, [results]);
2963 function doUntil(fn, test, callback) {
2964 doWhilst(fn, function () {
2965 return !test.apply(this, arguments);
2970 * Like [`whilst`]{@link module:ControlFlow.whilst}, except the `test` is an asynchronous function that
2971 * is passed a callback in the form of `function (err, truth)`. If error is
2972 * passed to `test` or `fn`, the main callback is immediately called with the
2973 * value of the error.
2977 * @memberOf module:ControlFlow
2979 * @see [async.whilst]{@link module:ControlFlow.whilst}
2980 * @category Control Flow
2981 * @param {Function} test - asynchronous truth test to perform before each
2982 * execution of `fn`. Invoked with (callback).
2983 * @param {Function} fn - A function which is called each time `test` passes.
2984 * The function is passed a `callback(err)`, which must be called once it has
2985 * completed with an optional `err` argument. Invoked with (callback).
2986 * @param {Function} [callback] - A callback which is called after the test
2987 * function has failed and repeated execution of `fn` has stopped. `callback`
2988 * will be passed an error, if one occured, otherwise `null`.
2994 * function (callback) {
2995 * return callback(null, count < 5);
2997 * function (callback) {
2999 * setTimeout(callback, 1000);
3002 * // 5 seconds have passed
3006 function during(test, fn, callback) {
3007 callback = onlyOnce(callback || noop);
3009 function next(err) {
3010 if (err) return callback(err);
3014 function check(err, truth) {
3015 if (err) return callback(err);
3016 if (!truth) return callback(null);
3023 function _withoutIndex(iteratee) {
3024 return function (value, index, callback) {
3025 return iteratee(value, callback);
3030 * Applies the function `iteratee` to each item in `coll`, in parallel.
3031 * The `iteratee` is called with an item from the list, and a callback for when
3032 * it has finished. If the `iteratee` passes an error to its `callback`, the
3033 * main `callback` (for the `each` function) is immediately called with the
3036 * Note, that since this function applies `iteratee` to each item in parallel,
3037 * there is no guarantee that the iteratee functions will complete in order.
3041 * @memberOf module:Collections
3044 * @category Collection
3045 * @param {Array|Iterable|Object} coll - A collection to iterate over.
3046 * @param {Function} iteratee - A function to apply to each item
3047 * in `coll`. The iteratee is passed a `callback(err)` which must be called once
3048 * it has completed. If no error has occurred, the `callback` should be run
3049 * without arguments or with an explicit `null` argument. The array index is not
3050 * passed to the iteratee. Invoked with (item, callback). If you need the index,
3052 * @param {Function} [callback] - A callback which is called when all
3053 * `iteratee` functions have finished, or an error occurs. Invoked with (err).
3056 * // assuming openFiles is an array of file names and saveFile is a function
3057 * // to save the modified contents of that file:
3059 * async.each(openFiles, saveFile, function(err){
3060 * // if any of the saves produced an error, err would equal that error
3063 * // assuming openFiles is an array of file names
3064 * async.each(openFiles, function(file, callback) {
3066 * // Perform operation on file here.
3067 * console.log('Processing file ' + file);
3069 * if( file.length > 32 ) {
3070 * console.log('This file name is too long');
3071 * callback('File name too long');
3073 * // Do work to process file here
3074 * console.log('File processed');
3077 * }, function(err) {
3078 * // if any of the file processing produced an error, err would equal that error
3080 * // One of the iterations produced an error.
3081 * // All processing will now stop.
3082 * console.log('A file failed to process');
3084 * console.log('All files have been processed successfully');
3088 function eachLimit(coll, iteratee, callback) {
3089 eachOf(coll, _withoutIndex(iteratee), callback);
3093 * The same as [`each`]{@link module:Collections.each} but runs a maximum of `limit` async operations at a time.
3097 * @memberOf module:Collections
3099 * @see [async.each]{@link module:Collections.each}
3100 * @alias forEachLimit
3101 * @category Collection
3102 * @param {Array|Iterable|Object} coll - A collection to iterate over.
3103 * @param {number} limit - The maximum number of async operations at a time.
3104 * @param {Function} iteratee - A function to apply to each item in `coll`. The
3105 * iteratee is passed a `callback(err)` which must be called once it has
3106 * completed. If no error has occurred, the `callback` should be run without
3107 * arguments or with an explicit `null` argument. The array index is not passed
3108 * to the iteratee. Invoked with (item, callback). If you need the index, use
3110 * @param {Function} [callback] - A callback which is called when all
3111 * `iteratee` functions have finished, or an error occurs. Invoked with (err).
3113 function eachLimit$1(coll, limit, iteratee, callback) {
3114 _eachOfLimit(limit)(coll, _withoutIndex(iteratee), callback);
3118 * The same as [`each`]{@link module:Collections.each} but runs only a single async operation at a time.
3122 * @memberOf module:Collections
3124 * @see [async.each]{@link module:Collections.each}
3125 * @alias forEachSeries
3126 * @category Collection
3127 * @param {Array|Iterable|Object} coll - A collection to iterate over.
3128 * @param {Function} iteratee - A function to apply to each
3129 * item in `coll`. The iteratee is passed a `callback(err)` which must be called
3130 * once it has completed. If no error has occurred, the `callback` should be run
3131 * without arguments or with an explicit `null` argument. The array index is
3132 * not passed to the iteratee. Invoked with (item, callback). If you need the
3133 * index, use `eachOfSeries`.
3134 * @param {Function} [callback] - A callback which is called when all
3135 * `iteratee` functions have finished, or an error occurs. Invoked with (err).
3137 var eachSeries = doLimit(eachLimit$1, 1);
3140 * Wrap an async function and ensure it calls its callback on a later tick of
3141 * the event loop. If the function already calls its callback on a next tick,
3142 * no extra deferral is added. This is useful for preventing stack overflows
3143 * (`RangeError: Maximum call stack size exceeded`) and generally keeping
3144 * [Zalgo](http://blog.izs.me/post/59142742143/designing-apis-for-asynchrony)
3149 * @memberOf module:Utils
3152 * @param {Function} fn - an async function, one that expects a node-style
3153 * callback as its last argument.
3154 * @returns {Function} Returns a wrapped function with the exact same call
3155 * signature as the function passed in.
3158 * function sometimesAsync(arg, callback) {
3160 * return callback(null, cache[arg]); // this would be synchronous!!
3162 * doSomeIO(arg, callback); // this IO would be asynchronous
3166 * // this has a risk of stack overflows if many results are cached in a row
3167 * async.mapSeries(args, sometimesAsync, done);
3169 * // this will defer sometimesAsync's callback if necessary,
3170 * // preventing stack overflows
3171 * async.mapSeries(args, async.ensureAsync(sometimesAsync), done);
3173 function ensureAsync(fn) {
3174 return initialParams(function (args, callback) {
3176 args.push(function () {
3177 var innerArgs = arguments;
3179 setImmediate$1(function () {
3180 callback.apply(null, innerArgs);
3183 callback.apply(null, innerArgs);
3186 fn.apply(this, args);
3196 * Returns `true` if every element in `coll` satisfies an async test. If any
3197 * iteratee call returns `false`, the main `callback` is immediately called.
3201 * @memberOf module:Collections
3204 * @category Collection
3205 * @param {Array|Iterable|Object} coll - A collection to iterate over.
3206 * @param {Function} iteratee - A truth test to apply to each item in the
3207 * collection in parallel. The iteratee is passed a `callback(err, truthValue)`
3208 * which must be called with a boolean argument once it has completed. Invoked
3209 * with (item, callback).
3210 * @param {Function} [callback] - A callback which is called after all the
3211 * `iteratee` functions have finished. Result will be either `true` or `false`
3212 * depending on the values of the async tests. Invoked with (err, result).
3215 * async.every(['file1','file2','file3'], function(filePath, callback) {
3216 * fs.access(filePath, function(err) {
3217 * callback(null, !err)
3219 * }, function(err, result) {
3220 * // if result is true then every file exists
3223 var every = doParallel(_createTester(notId, notId));
3226 * The same as [`every`]{@link module:Collections.every} but runs a maximum of `limit` async operations at a time.
3230 * @memberOf module:Collections
3232 * @see [async.every]{@link module:Collections.every}
3234 * @category Collection
3235 * @param {Array|Iterable|Object} coll - A collection to iterate over.
3236 * @param {number} limit - The maximum number of async operations at a time.
3237 * @param {Function} iteratee - A truth test to apply to each item in the
3238 * collection in parallel. The iteratee is passed a `callback(err, truthValue)`
3239 * which must be called with a boolean argument once it has completed. Invoked
3240 * with (item, callback).
3241 * @param {Function} [callback] - A callback which is called after all the
3242 * `iteratee` functions have finished. Result will be either `true` or `false`
3243 * depending on the values of the async tests. Invoked with (err, result).
3245 var everyLimit = doParallelLimit(_createTester(notId, notId));
3248 * The same as [`every`]{@link module:Collections.every} but runs only a single async operation at a time.
3252 * @memberOf module:Collections
3254 * @see [async.every]{@link module:Collections.every}
3256 * @category Collection
3257 * @param {Array|Iterable|Object} coll - A collection to iterate over.
3258 * @param {Function} iteratee - A truth test to apply to each item in the
3259 * collection in parallel. The iteratee is passed a `callback(err, truthValue)`
3260 * which must be called with a boolean argument once it has completed. Invoked
3261 * with (item, callback).
3262 * @param {Function} [callback] - A callback which is called after all the
3263 * `iteratee` functions have finished. Result will be either `true` or `false`
3264 * depending on the values of the async tests. Invoked with (err, result).
3266 var everySeries = doLimit(everyLimit, 1);
3269 * The base implementation of `_.property` without support for deep paths.
3272 * @param {string} key The key of the property to get.
3273 * @returns {Function} Returns the new accessor function.
3275 function baseProperty(key) {
3276 return function(object) {
3277 return object == null ? undefined : object[key];
3281 function filterArray(eachfn, arr, iteratee, callback) {
3282 var truthValues = new Array(arr.length);
3283 eachfn(arr, function (x, index, callback) {
3284 iteratee(x, function (err, v) {
3285 truthValues[index] = !!v;
3289 if (err) return callback(err);
3291 for (var i = 0; i < arr.length; i++) {
3292 if (truthValues[i]) results.push(arr[i]);
3294 callback(null, results);
3298 function filterGeneric(eachfn, coll, iteratee, callback) {
3300 eachfn(coll, function (x, index, callback) {
3301 iteratee(x, function (err, v) {
3306 results.push({ index: index, value: x });
3315 callback(null, arrayMap(results.sort(function (a, b) {
3316 return a.index - b.index;
3317 }), baseProperty('value')));
3322 function _filter(eachfn, coll, iteratee, callback) {
3323 var filter = isArrayLike(coll) ? filterArray : filterGeneric;
3324 filter(eachfn, coll, iteratee, callback || noop);
3328 * Returns a new array of all the values in `coll` which pass an async truth
3329 * test. This operation is performed in parallel, but the results array will be
3330 * in the same order as the original.
3334 * @memberOf module:Collections
3337 * @category Collection
3338 * @param {Array|Iterable|Object} coll - A collection to iterate over.
3339 * @param {Function} iteratee - A truth test to apply to each item in `coll`.
3340 * The `iteratee` is passed a `callback(err, truthValue)`, which must be called
3341 * with a boolean argument once it has completed. Invoked with (item, callback).
3342 * @param {Function} [callback] - A callback which is called after all the
3343 * `iteratee` functions have finished. Invoked with (err, results).
3346 * async.filter(['file1','file2','file3'], function(filePath, callback) {
3347 * fs.access(filePath, function(err) {
3348 * callback(null, !err)
3350 * }, function(err, results) {
3351 * // results now equals an array of the existing files
3354 var filter = doParallel(_filter);
3357 * The same as [`filter`]{@link module:Collections.filter} but runs a maximum of `limit` async operations at a
3362 * @memberOf module:Collections
3364 * @see [async.filter]{@link module:Collections.filter}
3365 * @alias selectLimit
3366 * @category Collection
3367 * @param {Array|Iterable|Object} coll - A collection to iterate over.
3368 * @param {number} limit - The maximum number of async operations at a time.
3369 * @param {Function} iteratee - A truth test to apply to each item in `coll`.
3370 * The `iteratee` is passed a `callback(err, truthValue)`, which must be called
3371 * with a boolean argument once it has completed. Invoked with (item, callback).
3372 * @param {Function} [callback] - A callback which is called after all the
3373 * `iteratee` functions have finished. Invoked with (err, results).
3375 var filterLimit = doParallelLimit(_filter);
3378 * The same as [`filter`]{@link module:Collections.filter} but runs only a single async operation at a time.
3380 * @name filterSeries
3382 * @memberOf module:Collections
3384 * @see [async.filter]{@link module:Collections.filter}
3385 * @alias selectSeries
3386 * @category Collection
3387 * @param {Array|Iterable|Object} coll - A collection to iterate over.
3388 * @param {Function} iteratee - A truth test to apply to each item in `coll`.
3389 * The `iteratee` is passed a `callback(err, truthValue)`, which must be called
3390 * with a boolean argument once it has completed. Invoked with (item, callback).
3391 * @param {Function} [callback] - A callback which is called after all the
3392 * `iteratee` functions have finished. Invoked with (err, results)
3394 var filterSeries = doLimit(filterLimit, 1);
3397 * Calls the asynchronous function `fn` with a callback parameter that allows it
3398 * to call itself again, in series, indefinitely.
3400 * If an error is passed to the
3401 * callback then `errback` is called with the error, and execution stops,
3402 * otherwise it will never be called.
3406 * @memberOf module:ControlFlow
3408 * @category Control Flow
3409 * @param {Function} fn - a function to call repeatedly. Invoked with (next).
3410 * @param {Function} [errback] - when `fn` passes an error to it's callback,
3411 * this function will be called, and execution stops. Invoked with (err).
3416 * // next is suitable for passing to things that need a callback(err [, whatever]);
3417 * // it will result in this function being called again.
3420 * // if next is called with a value in its first parameter, it will appear
3421 * // in here as 'err', and execution will stop.
3425 function forever(fn, errback) {
3426 var done = onlyOnce(errback || noop);
3427 var task = ensureAsync(fn);
3429 function next(err) {
3430 if (err) return done(err);
3437 * Logs the result of an `async` function to the `console`. Only works in
3438 * Node.js or in browsers that support `console.log` and `console.error` (such
3439 * as FF and Chrome). If multiple arguments are returned from the async
3440 * function, `console.log` is called on each argument in order.
3444 * @memberOf module:Utils
3447 * @param {Function} function - The function you want to eventually apply all
3449 * @param {...*} arguments... - Any number of arguments to apply to the function.
3453 * var hello = function(name, callback) {
3454 * setTimeout(function() {
3455 * callback(null, 'hello ' + name);
3459 * // in the node repl
3460 * node> async.log(hello, 'world');
3463 var log = consoleFunc('log');
3466 * The same as [`mapValues`]{@link module:Collections.mapValues} but runs a maximum of `limit` async operations at a
3469 * @name mapValuesLimit
3471 * @memberOf module:Collections
3473 * @see [async.mapValues]{@link module:Collections.mapValues}
3474 * @category Collection
3475 * @param {Object} obj - A collection to iterate over.
3476 * @param {number} limit - The maximum number of async operations at a time.
3477 * @param {Function} iteratee - A function to apply to each value in `obj`.
3478 * The iteratee is passed a `callback(err, transformed)` which must be called
3479 * once it has completed with an error (which can be `null`) and a
3480 * transformed value. Invoked with (value, key, callback).
3481 * @param {Function} [callback] - A callback which is called when all `iteratee`
3482 * functions have finished, or an error occurs. `result` is a new object consisting
3483 * of each key from `obj`, with each transformed value on the right-hand side.
3484 * Invoked with (err, result).
3486 function mapValuesLimit(obj, limit, iteratee, callback) {
3487 callback = once(callback || noop);
3489 eachOfLimit(obj, limit, function (val, key, next) {
3490 iteratee(val, key, function (err, result) {
3491 if (err) return next(err);
3492 newObj[key] = result;
3496 callback(err, newObj);
3501 * A relative of [`map`]{@link module:Collections.map}, designed for use with objects.
3503 * Produces a new Object by mapping each value of `obj` through the `iteratee`
3504 * function. The `iteratee` is called each `value` and `key` from `obj` and a
3505 * callback for when it has finished processing. Each of these callbacks takes
3506 * two arguments: an `error`, and the transformed item from `obj`. If `iteratee`
3507 * passes an error to its callback, the main `callback` (for the `mapValues`
3508 * function) is immediately called with the error.
3510 * Note, the order of the keys in the result is not guaranteed. The keys will
3511 * be roughly in the order they complete, (but this is very engine-specific)
3515 * @memberOf module:Collections
3517 * @category Collection
3518 * @param {Object} obj - A collection to iterate over.
3519 * @param {Function} iteratee - A function to apply to each value and key in
3520 * `coll`. The iteratee is passed a `callback(err, transformed)` which must be
3521 * called once it has completed with an error (which can be `null`) and a
3522 * transformed value. Invoked with (value, key, callback).
3523 * @param {Function} [callback] - A callback which is called when all `iteratee`
3524 * functions have finished, or an error occurs. `result` is a new object consisting
3525 * of each key from `obj`, with each transformed value on the right-hand side.
3526 * Invoked with (err, result).
3533 * }, function (file, key, callback) {
3534 * fs.stat(file, callback);
3535 * }, function(err, result) {
3536 * // result is now a map of stats for each file, e.g.
3538 * // f1: [stats for file1],
3539 * // f2: [stats for file2],
3540 * // f3: [stats for file3]
3545 var mapValues = doLimit(mapValuesLimit, Infinity);
3548 * The same as [`mapValues`]{@link module:Collections.mapValues} but runs only a single async operation at a time.
3550 * @name mapValuesSeries
3552 * @memberOf module:Collections
3554 * @see [async.mapValues]{@link module:Collections.mapValues}
3555 * @category Collection
3556 * @param {Object} obj - A collection to iterate over.
3557 * @param {Function} iteratee - A function to apply to each value in `obj`.
3558 * The iteratee is passed a `callback(err, transformed)` which must be called
3559 * once it has completed with an error (which can be `null`) and a
3560 * transformed value. Invoked with (value, key, callback).
3561 * @param {Function} [callback] - A callback which is called when all `iteratee`
3562 * functions have finished, or an error occurs. `result` is a new object consisting
3563 * of each key from `obj`, with each transformed value on the right-hand side.
3564 * Invoked with (err, result).
3566 var mapValuesSeries = doLimit(mapValuesLimit, 1);
3568 function has(obj, key) {
3573 * Caches the results of an `async` function. When creating a hash to store
3574 * function results against, the callback is omitted from the hash and an
3575 * optional hash function can be used.
3577 * If no hash function is specified, the first argument is used as a hash key,
3578 * which may work reasonably if it is a string or a data type that converts to a
3579 * distinct string. Note that objects and arrays will not behave reasonably.
3580 * Neither will cases where the other arguments are significant. In such cases,
3581 * specify your own hash function.
3583 * The cache of results is exposed as the `memo` property of the function
3584 * returned by `memoize`.
3588 * @memberOf module:Utils
3591 * @param {Function} fn - The function to proxy and cache results from.
3592 * @param {Function} hasher - An optional function for generating a custom hash
3593 * for storing results. It has all the arguments applied to it apart from the
3594 * callback, and must be synchronous.
3595 * @returns {Function} a memoized version of `fn`
3598 * var slow_fn = function(name, callback) {
3600 * callback(null, result);
3602 * var fn = async.memoize(slow_fn);
3604 * // fn can now be used as if it were slow_fn
3605 * fn('some name', function() {
3609 function memoize(fn, hasher) {
3610 var memo = Object.create(null);
3611 var queues = Object.create(null);
3612 hasher = hasher || identity;
3613 var memoized = initialParams(function memoized(args, callback) {
3614 var key = hasher.apply(null, args);
3615 if (has(memo, key)) {
3616 setImmediate$1(function () {
3617 callback.apply(null, memo[key]);
3619 } else if (has(queues, key)) {
3620 queues[key].push(callback);
3622 queues[key] = [callback];
3623 fn.apply(null, args.concat(rest(function (args) {
3625 var q = queues[key];
3627 for (var i = 0, l = q.length; i < l; i++) {
3628 q[i].apply(null, args);
3633 memoized.memo = memo;
3634 memoized.unmemoized = fn;
3639 * Calls `callback` on a later loop around the event loop. In Node.js this just
3640 * calls `setImmediate`. In the browser it will use `setImmediate` if
3641 * available, otherwise `setTimeout(callback, 0)`, which means other higher
3642 * priority events may precede the execution of `callback`.
3644 * This is used internally for browser-compatibility purposes.
3648 * @memberOf module:Utils
3650 * @alias setImmediate
3652 * @param {Function} callback - The function to call on a later loop around
3653 * the event loop. Invoked with (args...).
3654 * @param {...*} args... - any number of additional arguments to pass to the
3655 * callback on the next tick.
3658 * var call_order = [];
3659 * async.nextTick(function() {
3660 * call_order.push('two');
3661 * // call_order now equals ['one','two']
3663 * call_order.push('one');
3665 * async.setImmediate(function (a, b, c) {
3666 * // a, b, and c equal 1, 2, and 3
3672 _defer$1 = process.nextTick;
3673 } else if (hasSetImmediate) {
3674 _defer$1 = setImmediate;
3676 _defer$1 = fallback;
3679 var nextTick = wrap(_defer$1);
3681 function _parallel(eachfn, tasks, callback) {
3682 callback = callback || noop;
3683 var results = isArrayLike(tasks) ? [] : {};
3685 eachfn(tasks, function (task, key, callback) {
3686 task(rest(function (err, args) {
3687 if (args.length <= 1) {
3690 results[key] = args;
3694 callback(err, results);
3699 * Run the `tasks` collection of functions in parallel, without waiting until
3700 * the previous function has completed. If any of the functions pass an error to
3701 * its callback, the main `callback` is immediately called with the value of the
3702 * error. Once the `tasks` have completed, the results are passed to the final
3703 * `callback` as an array.
3705 * **Note:** `parallel` is about kicking-off I/O tasks in parallel, not about
3706 * parallel execution of code. If your tasks do not use any timers or perform
3707 * any I/O, they will actually be executed in series. Any synchronous setup
3708 * sections for each task will happen one after the other. JavaScript remains
3711 * It is also possible to use an object instead of an array. Each property will
3712 * be run as a function and the results will be passed to the final `callback`
3713 * as an object instead of an array. This can be a more readable way of handling
3714 * results from {@link async.parallel}.
3718 * @memberOf module:ControlFlow
3720 * @category Control Flow
3721 * @param {Array|Iterable|Object} tasks - A collection containing functions to run.
3722 * Each function is passed a `callback(err, result)` which it must call on
3723 * completion with an error `err` (which can be `null`) and an optional `result`
3725 * @param {Function} [callback] - An optional callback to run once all the
3726 * functions have completed successfully. This function gets a results array
3727 * (or object) containing all the result arguments passed to the task callbacks.
3728 * Invoked with (err, results).
3731 * function(callback) {
3732 * setTimeout(function() {
3733 * callback(null, 'one');
3736 * function(callback) {
3737 * setTimeout(function() {
3738 * callback(null, 'two');
3742 * // optional callback
3743 * function(err, results) {
3744 * // the results array will equal ['one','two'] even though
3745 * // the second function had a shorter timeout.
3748 * // an example using an object instead of an array
3750 * one: function(callback) {
3751 * setTimeout(function() {
3752 * callback(null, 1);
3755 * two: function(callback) {
3756 * setTimeout(function() {
3757 * callback(null, 2);
3760 * }, function(err, results) {
3761 * // results is now equals to: {one: 1, two: 2}
3764 function parallelLimit(tasks, callback) {
3765 _parallel(eachOf, tasks, callback);
3769 * The same as [`parallel`]{@link module:ControlFlow.parallel} but runs a maximum of `limit` async operations at a
3772 * @name parallelLimit
3774 * @memberOf module:ControlFlow
3776 * @see [async.parallel]{@link module:ControlFlow.parallel}
3777 * @category Control Flow
3778 * @param {Array|Collection} tasks - A collection containing functions to run.
3779 * Each function is passed a `callback(err, result)` which it must call on
3780 * completion with an error `err` (which can be `null`) and an optional `result`
3782 * @param {number} limit - The maximum number of async operations at a time.
3783 * @param {Function} [callback] - An optional callback to run once all the
3784 * functions have completed successfully. This function gets a results array
3785 * (or object) containing all the result arguments passed to the task callbacks.
3786 * Invoked with (err, results).
3788 function parallelLimit$1(tasks, limit, callback) {
3789 _parallel(_eachOfLimit(limit), tasks, callback);
3793 * A queue of tasks for the worker function to complete.
3794 * @typedef {Object} QueueObject
3795 * @memberOf module:ControlFlow
3796 * @property {Function} length - a function returning the number of items
3797 * waiting to be processed. Invoke with `queue.length()`.
3798 * @property {boolean} started - a boolean indicating whether or not any
3799 * items have been pushed and processed by the queue.
3800 * @property {Function} running - a function returning the number of items
3801 * currently being processed. Invoke with `queue.running()`.
3802 * @property {Function} workersList - a function returning the array of items
3803 * currently being processed. Invoke with `queue.workersList()`.
3804 * @property {Function} idle - a function returning false if there are items
3805 * waiting or being processed, or true if not. Invoke with `queue.idle()`.
3806 * @property {number} concurrency - an integer for determining how many `worker`
3807 * functions should be run in parallel. This property can be changed after a
3808 * `queue` is created to alter the concurrency on-the-fly.
3809 * @property {Function} push - add a new task to the `queue`. Calls `callback`
3810 * once the `worker` has finished processing the task. Instead of a single task,
3811 * a `tasks` array can be submitted. The respective callback is used for every
3812 * task in the list. Invoke with `queue.push(task, [callback])`,
3813 * @property {Function} unshift - add a new task to the front of the `queue`.
3814 * Invoke with `queue.unshift(task, [callback])`.
3815 * @property {Function} saturated - a callback that is called when the number of
3816 * running workers hits the `concurrency` limit, and further tasks will be
3818 * @property {Function} unsaturated - a callback that is called when the number
3819 * of running workers is less than the `concurrency` & `buffer` limits, and
3820 * further tasks will not be queued.
3821 * @property {number} buffer - A minimum threshold buffer in order to say that
3822 * the `queue` is `unsaturated`.
3823 * @property {Function} empty - a callback that is called when the last item
3824 * from the `queue` is given to a `worker`.
3825 * @property {Function} drain - a callback that is called when the last item
3826 * from the `queue` has returned from the `worker`.
3827 * @property {Function} error - a callback that is called when a task errors.
3828 * Has the signature `function(error, task)`.
3829 * @property {boolean} paused - a boolean for determining whether the queue is
3830 * in a paused state.
3831 * @property {Function} pause - a function that pauses the processing of tasks
3832 * until `resume()` is called. Invoke with `queue.pause()`.
3833 * @property {Function} resume - a function that resumes the processing of
3834 * queued tasks when the queue is paused. Invoke with `queue.resume()`.
3835 * @property {Function} kill - a function that removes the `drain` callback and
3836 * empties remaining tasks from the queue forcing it to go idle. Invoke with `queue.kill()`.
3840 * Creates a `queue` object with the specified `concurrency`. Tasks added to the
3841 * `queue` are processed in parallel (up to the `concurrency` limit). If all
3842 * `worker`s are in progress, the task is queued until one becomes available.
3843 * Once a `worker` completes a `task`, that `task`'s callback is called.
3847 * @memberOf module:ControlFlow
3849 * @category Control Flow
3850 * @param {Function} worker - An asynchronous function for processing a queued
3851 * task, which must call its `callback(err)` argument when finished, with an
3852 * optional `error` as an argument. If you want to handle errors from an
3853 * individual task, pass a callback to `q.push()`. Invoked with
3855 * @param {number} [concurrency=1] - An `integer` for determining how many
3856 * `worker` functions should be run in parallel. If omitted, the concurrency
3857 * defaults to `1`. If the concurrency is `0`, an error is thrown.
3858 * @returns {module:ControlFlow.QueueObject} A queue object to manage the tasks. Callbacks can
3859 * attached as certain properties to listen for specific events during the
3860 * lifecycle of the queue.
3863 * // create a queue object with concurrency 2
3864 * var q = async.queue(function(task, callback) {
3865 * console.log('hello ' + task.name);
3869 * // assign a callback
3870 * q.drain = function() {
3871 * console.log('all items have been processed');
3874 * // add some items to the queue
3875 * q.push({name: 'foo'}, function(err) {
3876 * console.log('finished processing foo');
3878 * q.push({name: 'bar'}, function (err) {
3879 * console.log('finished processing bar');
3882 * // add some items to the queue (batch-wise)
3883 * q.push([{name: 'baz'},{name: 'bay'},{name: 'bax'}], function(err) {
3884 * console.log('finished processing item');
3887 * // add some items to the front of the queue
3888 * q.unshift({name: 'bar'}, function (err) {
3889 * console.log('finished processing bar');
3892 var queue$1 = function (worker, concurrency) {
3893 return queue(function (items, cb) {
3894 worker(items[0], cb);
3899 * The same as [async.queue]{@link module:ControlFlow.queue} only tasks are assigned a priority and
3900 * completed in ascending priority order.
3902 * @name priorityQueue
3904 * @memberOf module:ControlFlow
3906 * @see [async.queue]{@link module:ControlFlow.queue}
3907 * @category Control Flow
3908 * @param {Function} worker - An asynchronous function for processing a queued
3909 * task, which must call its `callback(err)` argument when finished, with an
3910 * optional `error` as an argument. If you want to handle errors from an
3911 * individual task, pass a callback to `q.push()`. Invoked with
3913 * @param {number} concurrency - An `integer` for determining how many `worker`
3914 * functions should be run in parallel. If omitted, the concurrency defaults to
3915 * `1`. If the concurrency is `0`, an error is thrown.
3916 * @returns {module:ControlFlow.QueueObject} A priorityQueue object to manage the tasks. There are two
3917 * differences between `queue` and `priorityQueue` objects:
3918 * * `push(task, priority, [callback])` - `priority` should be a number. If an
3919 * array of `tasks` is given, all tasks will be assigned the same priority.
3920 * * The `unshift` method was removed.
3922 var priorityQueue = function (worker, concurrency) {
3923 // Start with a normal queue
3924 var q = queue$1(worker, concurrency);
3926 // Override push to accept second parameter representing priority
3927 q.push = function (data, priority, callback) {
3928 if (callback == null) callback = noop;
3929 if (typeof callback !== 'function') {
3930 throw new Error('task callback must be a function');
3933 if (!isArray(data)) {
3936 if (data.length === 0) {
3937 // call drain immediately if there are no tasks
3938 return setImmediate$1(function () {
3943 priority = priority || 0;
3944 var nextNode = q._tasks.head;
3945 while (nextNode && priority >= nextNode.priority) {
3946 nextNode = nextNode.next;
3949 for (var i = 0, l = data.length; i < l; i++) {
3957 q._tasks.insertBefore(nextNode, item);
3959 q._tasks.push(item);
3962 setImmediate$1(q.process);
3965 // Remove unshift function
3972 * Runs the `tasks` array of functions in parallel, without waiting until the
3973 * previous function has completed. Once any of the `tasks` complete or pass an
3974 * error to its callback, the main `callback` is immediately called. It's
3975 * equivalent to `Promise.race()`.
3979 * @memberOf module:ControlFlow
3981 * @category Control Flow
3982 * @param {Array} tasks - An array containing functions to run. Each function
3983 * is passed a `callback(err, result)` which it must call on completion with an
3984 * error `err` (which can be `null`) and an optional `result` value.
3985 * @param {Function} callback - A callback to run once any of the functions have
3986 * completed. This function gets an error or result from the first function that
3987 * completed. Invoked with (err, result).
3988 * @returns undefined
3992 * function(callback) {
3993 * setTimeout(function() {
3994 * callback(null, 'one');
3997 * function(callback) {
3998 * setTimeout(function() {
3999 * callback(null, 'two');
4004 * function(err, result) {
4005 * // the result will be equal to 'two' as it finishes earlier
4008 function race(tasks, callback) {
4009 callback = once(callback || noop);
4010 if (!isArray(tasks)) return callback(new TypeError('First argument to race must be an array of functions'));
4011 if (!tasks.length) return callback();
4012 for (var i = 0, l = tasks.length; i < l; i++) {
4017 var slice = Array.prototype.slice;
4020 * Same as [`reduce`]{@link module:Collections.reduce}, only operates on `array` in reverse order.
4024 * @memberOf module:Collections
4026 * @see [async.reduce]{@link module:Collections.reduce}
4028 * @category Collection
4029 * @param {Array} array - A collection to iterate over.
4030 * @param {*} memo - The initial state of the reduction.
4031 * @param {Function} iteratee - A function applied to each item in the
4032 * array to produce the next step in the reduction. The `iteratee` is passed a
4033 * `callback(err, reduction)` which accepts an optional error as its first
4034 * argument, and the state of the reduction as the second. If an error is
4035 * passed to the callback, the reduction is stopped and the main `callback` is
4036 * immediately called with the error. Invoked with (memo, item, callback).
4037 * @param {Function} [callback] - A callback which is called after all the
4038 * `iteratee` functions have finished. Result is the reduced value. Invoked with
4041 function reduceRight(array, memo, iteratee, callback) {
4042 var reversed = slice.call(array).reverse();
4043 reduce(reversed, memo, iteratee, callback);
4047 * Wraps the function in another function that always returns data even when it
4050 * The object returned has either the property `error` or `value`.
4054 * @memberOf module:Utils
4057 * @param {Function} fn - The function you want to wrap
4058 * @returns {Function} - A function that always passes null to it's callback as
4059 * the error. The second argument to the callback will be an `object` with
4060 * either an `error` or a `value` property.
4064 * async.reflect(function(callback) {
4065 * // do some stuff ...
4066 * callback(null, 'one');
4068 * async.reflect(function(callback) {
4069 * // do some more stuff but error ...
4070 * callback('bad stuff happened');
4072 * async.reflect(function(callback) {
4073 * // do some more stuff ...
4074 * callback(null, 'two');
4077 * // optional callback
4078 * function(err, results) {
4080 * // results[0].value = 'one'
4081 * // results[1].error = 'bad stuff happened'
4082 * // results[2].value = 'two'
4085 function reflect(fn) {
4086 return initialParams(function reflectOn(args, reflectCallback) {
4087 args.push(rest(function callback(err, cbArgs) {
4089 reflectCallback(null, {
4094 if (cbArgs.length === 1) {
4096 } else if (cbArgs.length > 1) {
4099 reflectCallback(null, {
4105 return fn.apply(this, args);
4109 function reject$1(eachfn, arr, iteratee, callback) {
4110 _filter(eachfn, arr, function (value, cb) {
4111 iteratee(value, function (err, v) {
4118 * The opposite of [`filter`]{@link module:Collections.filter}. Removes values that pass an `async` truth test.
4122 * @memberOf module:Collections
4124 * @see [async.filter]{@link module:Collections.filter}
4125 * @category Collection
4126 * @param {Array|Iterable|Object} coll - A collection to iterate over.
4127 * @param {Function} iteratee - A truth test to apply to each item in `coll`.
4128 * The `iteratee` is passed a `callback(err, truthValue)`, which must be called
4129 * with a boolean argument once it has completed. Invoked with (item, callback).
4130 * @param {Function} [callback] - A callback which is called after all the
4131 * `iteratee` functions have finished. Invoked with (err, results).
4134 * async.reject(['file1','file2','file3'], function(filePath, callback) {
4135 * fs.access(filePath, function(err) {
4136 * callback(null, !err)
4138 * }, function(err, results) {
4139 * // results now equals an array of missing files
4140 * createFiles(results);
4143 var reject = doParallel(reject$1);
4146 * A helper function that wraps an array or an object of functions with reflect.
4150 * @memberOf module:Utils
4152 * @see [async.reflect]{@link module:Utils.reflect}
4154 * @param {Array} tasks - The array of functions to wrap in `async.reflect`.
4155 * @returns {Array} Returns an array of functions, each function wrapped in
4160 * function(callback) {
4161 * setTimeout(function() {
4162 * callback(null, 'one');
4165 * function(callback) {
4166 * // do some more stuff but error ...
4167 * callback(new Error('bad stuff happened'));
4169 * function(callback) {
4170 * setTimeout(function() {
4171 * callback(null, 'two');
4176 * async.parallel(async.reflectAll(tasks),
4177 * // optional callback
4178 * function(err, results) {
4180 * // results[0].value = 'one'
4181 * // results[1].error = Error('bad stuff happened')
4182 * // results[2].value = 'two'
4185 * // an example using an object instead of an array
4187 * one: function(callback) {
4188 * setTimeout(function() {
4189 * callback(null, 'one');
4192 * two: function(callback) {
4195 * three: function(callback) {
4196 * setTimeout(function() {
4197 * callback(null, 'three');
4202 * async.parallel(async.reflectAll(tasks),
4203 * // optional callback
4204 * function(err, results) {
4206 * // results.one.value = 'one'
4207 * // results.two.error = 'two'
4208 * // results.three.value = 'three'
4211 function reflectAll(tasks) {
4213 if (isArray(tasks)) {
4214 results = arrayMap(tasks, reflect);
4217 baseForOwn(tasks, function (task, key) {
4218 results[key] = reflect.call(this, task);
4225 * The same as [`reject`]{@link module:Collections.reject} but runs a maximum of `limit` async operations at a
4230 * @memberOf module:Collections
4232 * @see [async.reject]{@link module:Collections.reject}
4233 * @category Collection
4234 * @param {Array|Iterable|Object} coll - A collection to iterate over.
4235 * @param {number} limit - The maximum number of async operations at a time.
4236 * @param {Function} iteratee - A truth test to apply to each item in `coll`.
4237 * The `iteratee` is passed a `callback(err, truthValue)`, which must be called
4238 * with a boolean argument once it has completed. Invoked with (item, callback).
4239 * @param {Function} [callback] - A callback which is called after all the
4240 * `iteratee` functions have finished. Invoked with (err, results).
4242 var rejectLimit = doParallelLimit(reject$1);
4245 * The same as [`reject`]{@link module:Collections.reject} but runs only a single async operation at a time.
4247 * @name rejectSeries
4249 * @memberOf module:Collections
4251 * @see [async.reject]{@link module:Collections.reject}
4252 * @category Collection
4253 * @param {Array|Iterable|Object} coll - A collection to iterate over.
4254 * @param {Function} iteratee - A truth test to apply to each item in `coll`.
4255 * The `iteratee` is passed a `callback(err, truthValue)`, which must be called
4256 * with a boolean argument once it has completed. Invoked with (item, callback).
4257 * @param {Function} [callback] - A callback which is called after all the
4258 * `iteratee` functions have finished. Invoked with (err, results).
4260 var rejectSeries = doLimit(rejectLimit, 1);
4263 * Creates a function that returns `value`.
4269 * @param {*} value The value to return from the new function.
4270 * @returns {Function} Returns the new constant function.
4273 * var objects = _.times(2, _.constant({ 'a': 1 }));
4275 * console.log(objects);
4276 * // => [{ 'a': 1 }, { 'a': 1 }]
4278 * console.log(objects[0] === objects[1]);
4281 function constant$1(value) {
4288 * Attempts to get a successful response from `task` no more than `times` times
4289 * before returning an error. If the task is successful, the `callback` will be
4290 * passed the result of the successful task. If all attempts fail, the callback
4291 * will be passed the error and result (if any) of the final attempt.
4295 * @memberOf module:ControlFlow
4297 * @category Control Flow
4298 * @param {Object|number} [opts = {times: 5, interval: 0}| 5] - Can be either an
4299 * object with `times` and `interval` or a number.
4300 * * `times` - The number of attempts to make before giving up. The default
4302 * * `interval` - The time to wait between retries, in milliseconds. The
4303 * default is `0`. The interval may also be specified as a function of the
4304 * retry count (see example).
4305 * * `errorFilter` - An optional synchronous function that is invoked on
4306 * erroneous result. If it returns `true` the retry attempts will continue;
4307 * if the function returns `false` the retry flow is aborted with the current
4308 * attempt's error and result being returned to the final callback.
4309 * Invoked with (err).
4310 * * If `opts` is a number, the number specifies the number of times to retry,
4311 * with the default interval of `0`.
4312 * @param {Function} task - A function which receives two arguments: (1) a
4313 * `callback(err, result)` which must be called when finished, passing `err`
4314 * (which can be `null`) and the `result` of the function's execution, and (2)
4315 * a `results` object, containing the results of the previously executed
4316 * functions (if nested inside another control flow). Invoked with
4317 * (callback, results).
4318 * @param {Function} [callback] - An optional callback which is called when the
4319 * task has succeeded, or after the final failed attempt. It receives the `err`
4320 * and `result` arguments of the last attempt at completing the `task`. Invoked
4321 * with (err, results).
4324 * // The `retry` function can be used as a stand-alone control flow by passing
4325 * // a callback, as shown below:
4327 * // try calling apiMethod 3 times
4328 * async.retry(3, apiMethod, function(err, result) {
4329 * // do something with the result
4332 * // try calling apiMethod 3 times, waiting 200 ms between each retry
4333 * async.retry({times: 3, interval: 200}, apiMethod, function(err, result) {
4334 * // do something with the result
4337 * // try calling apiMethod 10 times with exponential backoff
4338 * // (i.e. intervals of 100, 200, 400, 800, 1600, ... milliseconds)
4341 * interval: function(retryCount) {
4342 * return 50 * Math.pow(2, retryCount);
4344 * }, apiMethod, function(err, result) {
4345 * // do something with the result
4348 * // try calling apiMethod the default 5 times no delay between each retry
4349 * async.retry(apiMethod, function(err, result) {
4350 * // do something with the result
4353 * // try calling apiMethod only when error condition satisfies, all other
4354 * // errors will abort the retry control flow and return to final callback
4356 * errorFilter: function(err) {
4357 * return err.message === 'Temporary error'; // only retry on a specific error
4359 * }, apiMethod, function(err, result) {
4360 * // do something with the result
4363 * // It can also be embedded within other control flow functions to retry
4364 * // individual methods that are not as reliable, like this:
4366 * users: api.getUsers.bind(api),
4367 * payments: async.retry(3, api.getPayments.bind(api))
4368 * }, function(err, results) {
4369 * // do something with the results
4373 function retry(opts, task, callback) {
4374 var DEFAULT_TIMES = 5;
4375 var DEFAULT_INTERVAL = 0;
4378 times: DEFAULT_TIMES,
4379 intervalFunc: constant$1(DEFAULT_INTERVAL)
4382 function parseTimes(acc, t) {
4383 if (typeof t === 'object') {
4384 acc.times = +t.times || DEFAULT_TIMES;
4386 acc.intervalFunc = typeof t.interval === 'function' ? t.interval : constant$1(+t.interval || DEFAULT_INTERVAL);
4388 acc.errorFilter = t.errorFilter;
4389 } else if (typeof t === 'number' || typeof t === 'string') {
4390 acc.times = +t || DEFAULT_TIMES;
4392 throw new Error("Invalid arguments for async.retry");
4396 if (arguments.length < 3 && typeof opts === 'function') {
4397 callback = task || noop;
4400 parseTimes(options, opts);
4401 callback = callback || noop;
4404 if (typeof task !== 'function') {
4405 throw new Error("Invalid arguments for async.retry");
4409 function retryAttempt() {
4410 task(function (err) {
4411 if (err && attempt++ < options.times && (typeof options.errorFilter != 'function' || options.errorFilter(err))) {
4412 setTimeout(retryAttempt, options.intervalFunc(attempt));
4414 callback.apply(null, arguments);
4423 * A close relative of [`retry`]{@link module:ControlFlow.retry}. This method wraps a task and makes it
4424 * retryable, rather than immediately calling it with retries.
4428 * @memberOf module:ControlFlow
4430 * @see [async.retry]{@link module:ControlFlow.retry}
4431 * @category Control Flow
4432 * @param {Object|number} [opts = {times: 5, interval: 0}| 5] - optional
4433 * options, exactly the same as from `retry`
4434 * @param {Function} task - the asynchronous function to wrap
4435 * @returns {Functions} The wrapped function, which when invoked, will retry on
4436 * an error, based on the parameters specified in `opts`.
4440 * dep1: async.retryable(3, getFromFlakyService),
4441 * process: ["dep1", async.retryable(3, function (results, cb) {
4442 * maybeProcessData(results.dep1, cb);
4446 var retryable = function (opts, task) {
4451 return initialParams(function (args, callback) {
4452 function taskFn(cb) {
4453 task.apply(null, args.concat(cb));
4456 if (opts) retry(opts, taskFn, callback);else retry(taskFn, callback);
4461 * Run the functions in the `tasks` collection in series, each one running once
4462 * the previous function has completed. If any functions in the series pass an
4463 * error to its callback, no more functions are run, and `callback` is
4464 * immediately called with the value of the error. Otherwise, `callback`
4465 * receives an array of results when `tasks` have completed.
4467 * It is also possible to use an object instead of an array. Each property will
4468 * be run as a function, and the results will be passed to the final `callback`
4469 * as an object instead of an array. This can be a more readable way of handling
4470 * results from {@link async.series}.
4472 * **Note** that while many implementations preserve the order of object
4473 * properties, the [ECMAScript Language Specification](http://www.ecma-international.org/ecma-262/5.1/#sec-8.6)
4474 * explicitly states that
4476 * > The mechanics and order of enumerating the properties is not specified.
4478 * So if you rely on the order in which your series of functions are executed,
4479 * and want this to work on all platforms, consider using an array.
4483 * @memberOf module:ControlFlow
4485 * @category Control Flow
4486 * @param {Array|Iterable|Object} tasks - A collection containing functions to run, each
4487 * function is passed a `callback(err, result)` it must call on completion with
4488 * an error `err` (which can be `null`) and an optional `result` value.
4489 * @param {Function} [callback] - An optional callback to run once all the
4490 * functions have completed. This function gets a results array (or object)
4491 * containing all the result arguments passed to the `task` callbacks. Invoked
4492 * with (err, result).
4495 * function(callback) {
4496 * // do some stuff ...
4497 * callback(null, 'one');
4499 * function(callback) {
4500 * // do some more stuff ...
4501 * callback(null, 'two');
4504 * // optional callback
4505 * function(err, results) {
4506 * // results is now equal to ['one', 'two']
4510 * one: function(callback) {
4511 * setTimeout(function() {
4512 * callback(null, 1);
4515 * two: function(callback){
4516 * setTimeout(function() {
4517 * callback(null, 2);
4520 * }, function(err, results) {
4521 * // results is now equal to: {one: 1, two: 2}
4524 function series(tasks, callback) {
4525 _parallel(eachOfSeries, tasks, callback);
4529 * Returns `true` if at least one element in the `coll` satisfies an async test.
4530 * If any iteratee call returns `true`, the main `callback` is immediately
4535 * @memberOf module:Collections
4538 * @category Collection
4539 * @param {Array|Iterable|Object} coll - A collection to iterate over.
4540 * @param {Function} iteratee - A truth test to apply to each item in the array
4541 * in parallel. The iteratee is passed a `callback(err, truthValue)` which must
4542 * be called with a boolean argument once it has completed. Invoked with
4544 * @param {Function} [callback] - A callback which is called as soon as any
4545 * iteratee returns `true`, or after all the iteratee functions have finished.
4546 * Result will be either `true` or `false` depending on the values of the async
4547 * tests. Invoked with (err, result).
4550 * async.some(['file1','file2','file3'], function(filePath, callback) {
4551 * fs.access(filePath, function(err) {
4552 * callback(null, !err)
4554 * }, function(err, result) {
4555 * // if result is true then at least one of the files exists
4558 var some = doParallel(_createTester(Boolean, identity));
4561 * The same as [`some`]{@link module:Collections.some} but runs a maximum of `limit` async operations at a time.
4565 * @memberOf module:Collections
4567 * @see [async.some]{@link module:Collections.some}
4569 * @category Collection
4570 * @param {Array|Iterable|Object} coll - A collection to iterate over.
4571 * @param {number} limit - The maximum number of async operations at a time.
4572 * @param {Function} iteratee - A truth test to apply to each item in the array
4573 * in parallel. The iteratee is passed a `callback(err, truthValue)` which must
4574 * be called with a boolean argument once it has completed. Invoked with
4576 * @param {Function} [callback] - A callback which is called as soon as any
4577 * iteratee returns `true`, or after all the iteratee functions have finished.
4578 * Result will be either `true` or `false` depending on the values of the async
4579 * tests. Invoked with (err, result).
4581 var someLimit = doParallelLimit(_createTester(Boolean, identity));
4584 * The same as [`some`]{@link module:Collections.some} but runs only a single async operation at a time.
4588 * @memberOf module:Collections
4590 * @see [async.some]{@link module:Collections.some}
4592 * @category Collection
4593 * @param {Array|Iterable|Object} coll - A collection to iterate over.
4594 * @param {Function} iteratee - A truth test to apply to each item in the array
4595 * in parallel. The iteratee is passed a `callback(err, truthValue)` which must
4596 * be called with a boolean argument once it has completed. Invoked with
4598 * @param {Function} [callback] - A callback which is called as soon as any
4599 * iteratee returns `true`, or after all the iteratee functions have finished.
4600 * Result will be either `true` or `false` depending on the values of the async
4601 * tests. Invoked with (err, result).
4603 var someSeries = doLimit(someLimit, 1);
4606 * Sorts a list by the results of running each `coll` value through an async
4611 * @memberOf module:Collections
4613 * @category Collection
4614 * @param {Array|Iterable|Object} coll - A collection to iterate over.
4615 * @param {Function} iteratee - A function to apply to each item in `coll`.
4616 * The iteratee is passed a `callback(err, sortValue)` which must be called once
4617 * it has completed with an error (which can be `null`) and a value to use as
4618 * the sort criteria. Invoked with (item, callback).
4619 * @param {Function} callback - A callback which is called after all the
4620 * `iteratee` functions have finished, or an error occurs. Results is the items
4621 * from the original `coll` sorted by the values returned by the `iteratee`
4622 * calls. Invoked with (err, results).
4625 * async.sortBy(['file1','file2','file3'], function(file, callback) {
4626 * fs.stat(file, function(err, stats) {
4627 * callback(err, stats.mtime);
4629 * }, function(err, results) {
4630 * // results is now the original array of files sorted by
4634 * // By modifying the callback parameter the
4635 * // sorting order can be influenced:
4637 * // ascending order
4638 * async.sortBy([1,9,3,5], function(x, callback) {
4639 * callback(null, x);
4640 * }, function(err,result) {
4641 * // result callback
4644 * // descending order
4645 * async.sortBy([1,9,3,5], function(x, callback) {
4646 * callback(null, x*-1); //<- x*-1 instead of x, turns the order around
4647 * }, function(err,result) {
4648 * // result callback
4651 function sortBy(coll, iteratee, callback) {
4652 map(coll, function (x, callback) {
4653 iteratee(x, function (err, criteria) {
4654 if (err) return callback(err);
4655 callback(null, { value: x, criteria: criteria });
4657 }, function (err, results) {
4658 if (err) return callback(err);
4659 callback(null, arrayMap(results.sort(comparator), baseProperty('value')));
4662 function comparator(left, right) {
4663 var a = left.criteria,
4665 return a < b ? -1 : a > b ? 1 : 0;
4670 * Sets a time limit on an asynchronous function. If the function does not call
4671 * its callback within the specified milliseconds, it will be called with a
4672 * timeout error. The code property for the error object will be `'ETIMEDOUT'`.
4676 * @memberOf module:Utils
4679 * @param {Function} asyncFn - The asynchronous function you want to set the
4681 * @param {number} milliseconds - The specified time limit.
4682 * @param {*} [info] - Any variable you want attached (`string`, `object`, etc)
4683 * to timeout Error for more information..
4684 * @returns {Function} Returns a wrapped function that can be used with any of
4685 * the control flow functions. Invoke this function with the same
4686 * parameters as you would `asyncFunc`.
4689 * function myFunction(foo, callback) {
4690 * doAsyncTask(foo, function(err, data) {
4692 * if (err) return callback(err);
4694 * // do some stuff ...
4696 * // return processed data
4697 * return callback(null, data);
4701 * var wrapped = async.timeout(myFunction, 1000);
4703 * // call `wrapped` as you would `myFunction`
4704 * wrapped({ bar: 'bar' }, function(err, data) {
4705 * // if `myFunction` takes < 1000 ms to execute, `err`
4706 * // and `data` will have their expected values
4708 * // else `err` will be an Error with the code 'ETIMEDOUT'
4711 function timeout(asyncFn, milliseconds, info) {
4712 var originalCallback, timer;
4713 var timedOut = false;
4715 function injectedCallback() {
4717 originalCallback.apply(null, arguments);
4718 clearTimeout(timer);
4722 function timeoutCallback() {
4723 var name = asyncFn.name || 'anonymous';
4724 var error = new Error('Callback function "' + name + '" timed out.');
4725 error.code = 'ETIMEDOUT';
4730 originalCallback(error);
4733 return initialParams(function (args, origCallback) {
4734 originalCallback = origCallback;
4735 // setup timer and call original function
4736 timer = setTimeout(timeoutCallback, milliseconds);
4737 asyncFn.apply(null, args.concat(injectedCallback));
4741 /* Built-in method references for those with the same name as other `lodash` methods. */
4742 var nativeCeil = Math.ceil;
4743 var nativeMax$1 = Math.max;
4746 * The base implementation of `_.range` and `_.rangeRight` which doesn't
4750 * @param {number} start The start of the range.
4751 * @param {number} end The end of the range.
4752 * @param {number} step The value to increment or decrement by.
4753 * @param {boolean} [fromRight] Specify iterating from right to left.
4754 * @returns {Array} Returns the range of numbers.
4756 function baseRange(start, end, step, fromRight) {
4758 length = nativeMax$1(nativeCeil((end - start) / (step || 1)), 0),
4759 result = Array(length);
4762 result[fromRight ? length : ++index] = start;
4769 * The same as [times]{@link module:ControlFlow.times} but runs a maximum of `limit` async operations at a
4774 * @memberOf module:ControlFlow
4776 * @see [async.times]{@link module:ControlFlow.times}
4777 * @category Control Flow
4778 * @param {number} count - The number of times to run the function.
4779 * @param {number} limit - The maximum number of async operations at a time.
4780 * @param {Function} iteratee - The function to call `n` times. Invoked with the
4781 * iteration index and a callback (n, next).
4782 * @param {Function} callback - see [async.map]{@link module:Collections.map}.
4784 function timeLimit(count, limit, iteratee, callback) {
4785 mapLimit(baseRange(0, count, 1), limit, iteratee, callback);
4789 * Calls the `iteratee` function `n` times, and accumulates results in the same
4790 * manner you would use with [map]{@link module:Collections.map}.
4794 * @memberOf module:ControlFlow
4796 * @see [async.map]{@link module:Collections.map}
4797 * @category Control Flow
4798 * @param {number} n - The number of times to run the function.
4799 * @param {Function} iteratee - The function to call `n` times. Invoked with the
4800 * iteration index and a callback (n, next).
4801 * @param {Function} callback - see {@link module:Collections.map}.
4804 * // Pretend this is some complicated async factory
4805 * var createUser = function(id, callback) {
4811 * // generate 5 users
4812 * async.times(5, function(n, next) {
4813 * createUser(n, function(err, user) {
4816 * }, function(err, users) {
4817 * // we should now have 5 users
4820 var times = doLimit(timeLimit, Infinity);
4823 * The same as [times]{@link module:ControlFlow.times} but runs only a single async operation at a time.
4827 * @memberOf module:ControlFlow
4829 * @see [async.times]{@link module:ControlFlow.times}
4830 * @category Control Flow
4831 * @param {number} n - The number of times to run the function.
4832 * @param {Function} iteratee - The function to call `n` times. Invoked with the
4833 * iteration index and a callback (n, next).
4834 * @param {Function} callback - see {@link module:Collections.map}.
4836 var timesSeries = doLimit(timeLimit, 1);
4839 * A relative of `reduce`. Takes an Object or Array, and iterates over each
4840 * element in series, each step potentially mutating an `accumulator` value.
4841 * The type of the accumulator defaults to the type of collection passed in.
4845 * @memberOf module:Collections
4847 * @category Collection
4848 * @param {Array|Iterable|Object} coll - A collection to iterate over.
4849 * @param {*} [accumulator] - The initial state of the transform. If omitted,
4850 * it will default to an empty Object or Array, depending on the type of `coll`
4851 * @param {Function} iteratee - A function applied to each item in the
4852 * collection that potentially modifies the accumulator. The `iteratee` is
4853 * passed a `callback(err)` which accepts an optional error as its first
4854 * argument. If an error is passed to the callback, the transform is stopped
4855 * and the main `callback` is immediately called with the error.
4856 * Invoked with (accumulator, item, key, callback).
4857 * @param {Function} [callback] - A callback which is called after all the
4858 * `iteratee` functions have finished. Result is the transformed accumulator.
4859 * Invoked with (err, result).
4862 * async.transform([1,2,3], function(acc, item, index, callback) {
4863 * // pointless async:
4864 * process.nextTick(function() {
4865 * acc.push(item * 2)
4868 * }, function(err, result) {
4869 * // result is now equal to [2, 4, 6]
4874 * async.transform({a: 1, b: 2, c: 3}, function (obj, val, key, callback) {
4875 * setImmediate(function () {
4876 * obj[key] = val * 2;
4879 * }, function (err, result) {
4880 * // result is equal to {a: 2, b: 4, c: 6}
4883 function transform(coll, accumulator, iteratee, callback) {
4884 if (arguments.length === 3) {
4885 callback = iteratee;
4886 iteratee = accumulator;
4887 accumulator = isArray(coll) ? [] : {};
4889 callback = once(callback || noop);
4891 eachOf(coll, function (v, k, cb) {
4892 iteratee(accumulator, v, k, cb);
4894 callback(err, accumulator);
4899 * Undoes a [memoize]{@link module:Utils.memoize}d function, reverting it to the original,
4900 * unmemoized form. Handy for testing.
4904 * @memberOf module:Utils
4906 * @see [async.memoize]{@link module:Utils.memoize}
4908 * @param {Function} fn - the memoized function
4909 * @returns {Function} a function that calls the original unmemoized function
4911 function unmemoize(fn) {
4912 return function () {
4913 return (fn.unmemoized || fn).apply(null, arguments);
4918 * Repeatedly call `iteratee`, while `test` returns `true`. Calls `callback` when
4919 * stopped, or an error occurs.
4923 * @memberOf module:ControlFlow
4925 * @category Control Flow
4926 * @param {Function} test - synchronous truth test to perform before each
4927 * execution of `iteratee`. Invoked with ().
4928 * @param {Function} iteratee - A function which is called each time `test` passes.
4929 * The function is passed a `callback(err)`, which must be called once it has
4930 * completed with an optional `err` argument. Invoked with (callback).
4931 * @param {Function} [callback] - A callback which is called after the test
4932 * function has failed and repeated execution of `iteratee` has stopped. `callback`
4933 * will be passed an error and any arguments passed to the final `iteratee`'s
4934 * callback. Invoked with (err, [results]);
4935 * @returns undefined
4940 * function() { return count < 5; },
4941 * function(callback) {
4943 * setTimeout(function() {
4944 * callback(null, count);
4947 * function (err, n) {
4948 * // 5 seconds have passed, n = 5
4952 function whilst(test, iteratee, callback) {
4953 callback = onlyOnce(callback || noop);
4954 if (!test()) return callback(null);
4955 var next = rest(function (err, args) {
4956 if (err) return callback(err);
4957 if (test()) return iteratee(next);
4958 callback.apply(null, [null].concat(args));
4964 * Repeatedly call `fn` until `test` returns `true`. Calls `callback` when
4965 * stopped, or an error occurs. `callback` will be passed an error and any
4966 * arguments passed to the final `fn`'s callback.
4968 * The inverse of [whilst]{@link module:ControlFlow.whilst}.
4972 * @memberOf module:ControlFlow
4974 * @see [async.whilst]{@link module:ControlFlow.whilst}
4975 * @category Control Flow
4976 * @param {Function} test - synchronous truth test to perform before each
4977 * execution of `fn`. Invoked with ().
4978 * @param {Function} fn - A function which is called each time `test` fails.
4979 * The function is passed a `callback(err)`, which must be called once it has
4980 * completed with an optional `err` argument. Invoked with (callback).
4981 * @param {Function} [callback] - A callback which is called after the test
4982 * function has passed and repeated execution of `fn` has stopped. `callback`
4983 * will be passed an error and any arguments passed to the final `fn`'s
4984 * callback. Invoked with (err, [results]);
4986 function until(test, fn, callback) {
4987 whilst(function () {
4988 return !test.apply(this, arguments);
4993 * Runs the `tasks` array of functions in series, each passing their results to
4994 * the next in the array. However, if any of the `tasks` pass an error to their
4995 * own callback, the next function is not executed, and the main `callback` is
4996 * immediately called with the error.
5000 * @memberOf module:ControlFlow
5002 * @category Control Flow
5003 * @param {Array} tasks - An array of functions to run, each function is passed
5004 * a `callback(err, result1, result2, ...)` it must call on completion. The
5005 * first argument is an error (which can be `null`) and any further arguments
5006 * will be passed as arguments in order to the next task.
5007 * @param {Function} [callback] - An optional callback to run once all the
5008 * functions have completed. This will be passed the results of the last task's
5009 * callback. Invoked with (err, [results]).
5010 * @returns undefined
5014 * function(callback) {
5015 * callback(null, 'one', 'two');
5017 * function(arg1, arg2, callback) {
5018 * // arg1 now equals 'one' and arg2 now equals 'two'
5019 * callback(null, 'three');
5021 * function(arg1, callback) {
5022 * // arg1 now equals 'three'
5023 * callback(null, 'done');
5025 * ], function (err, result) {
5026 * // result now equals 'done'
5029 * // Or, with named functions:
5034 * ], function (err, result) {
5035 * // result now equals 'done'
5037 * function myFirstFunction(callback) {
5038 * callback(null, 'one', 'two');
5040 * function mySecondFunction(arg1, arg2, callback) {
5041 * // arg1 now equals 'one' and arg2 now equals 'two'
5042 * callback(null, 'three');
5044 * function myLastFunction(arg1, callback) {
5045 * // arg1 now equals 'three'
5046 * callback(null, 'done');
5049 var waterfall = function (tasks, callback) {
5050 callback = once(callback || noop);
5051 if (!isArray(tasks)) return callback(new Error('First argument to waterfall must be an array of functions'));
5052 if (!tasks.length) return callback();
5055 function nextTask(args) {
5056 if (taskIndex === tasks.length) {
5057 return callback.apply(null, [null].concat(args));
5060 var taskCallback = onlyOnce(rest(function (err, args) {
5062 return callback.apply(null, [err].concat(args));
5067 args.push(taskCallback);
5069 var task = tasks[taskIndex++];
5070 task.apply(null, args);
5077 * Async is a utility module which provides straight-forward, powerful functions
5078 * for working with asynchronous JavaScript. Although originally designed for
5079 * use with [Node.js](http://nodejs.org) and installable via
5080 * `npm install --save async`, it can also be used directly in the browser.
5085 * A collection of `async` functions for manipulating collections, such as
5086 * arrays and objects.
5087 * @module Collections
5091 * A collection of `async` functions for controlling the flow through a script.
5092 * @module ControlFlow
5096 * A collection of `async` utility functions.
5100 applyEach: applyEach,
5101 applyEachSeries: applyEachSeries,
5105 autoInject: autoInject,
5109 concatSeries: concatSeries,
5112 detectLimit: detectLimit,
5113 detectSeries: detectSeries,
5120 eachLimit: eachLimit$1,
5122 eachOfLimit: eachOfLimit,
5123 eachOfSeries: eachOfSeries,
5124 eachSeries: eachSeries,
5125 ensureAsync: ensureAsync,
5127 everyLimit: everyLimit,
5128 everySeries: everySeries,
5130 filterLimit: filterLimit,
5131 filterSeries: filterSeries,
5136 mapSeries: mapSeries,
5137 mapValues: mapValues,
5138 mapValuesLimit: mapValuesLimit,
5139 mapValuesSeries: mapValuesSeries,
5142 parallel: parallelLimit,
5143 parallelLimit: parallelLimit$1,
5144 priorityQueue: priorityQueue,
5148 reduceRight: reduceRight,
5150 reflectAll: reflectAll,
5152 rejectLimit: rejectLimit,
5153 rejectSeries: rejectSeries,
5155 retryable: retryable,
5158 setImmediate: setImmediate$1,
5160 someLimit: someLimit,
5161 someSeries: someSeries,
5165 timesLimit: timeLimit,
5166 timesSeries: timesSeries,
5167 transform: transform,
5168 unmemoize: unmemoize,
5170 waterfall: waterfall,
5177 forEachSeries: eachSeries,
5178 forEachLimit: eachLimit$1,
5180 forEachOfSeries: eachOfSeries,
5181 forEachOfLimit: eachOfLimit,
5186 selectLimit: filterLimit,
5187 selectSeries: filterSeries,
5191 exports['default'] = index;
5192 exports.applyEach = applyEach;
5193 exports.applyEachSeries = applyEachSeries;
5194 exports.apply = apply$2;
5195 exports.asyncify = asyncify;
5196 exports.auto = auto;
5197 exports.autoInject = autoInject;
5198 exports.cargo = cargo;
5199 exports.compose = compose;
5200 exports.concat = concat;
5201 exports.concatSeries = concatSeries;
5202 exports.constant = constant;
5203 exports.detect = detect;
5204 exports.detectLimit = detectLimit;
5205 exports.detectSeries = detectSeries;
5207 exports.doDuring = doDuring;
5208 exports.doUntil = doUntil;
5209 exports.doWhilst = doWhilst;
5210 exports.during = during;
5211 exports.each = eachLimit;
5212 exports.eachLimit = eachLimit$1;
5213 exports.eachOf = eachOf;
5214 exports.eachOfLimit = eachOfLimit;
5215 exports.eachOfSeries = eachOfSeries;
5216 exports.eachSeries = eachSeries;
5217 exports.ensureAsync = ensureAsync;
5218 exports.every = every;
5219 exports.everyLimit = everyLimit;
5220 exports.everySeries = everySeries;
5221 exports.filter = filter;
5222 exports.filterLimit = filterLimit;
5223 exports.filterSeries = filterSeries;
5224 exports.forever = forever;
5227 exports.mapLimit = mapLimit;
5228 exports.mapSeries = mapSeries;
5229 exports.mapValues = mapValues;
5230 exports.mapValuesLimit = mapValuesLimit;
5231 exports.mapValuesSeries = mapValuesSeries;
5232 exports.memoize = memoize;
5233 exports.nextTick = nextTick;
5234 exports.parallel = parallelLimit;
5235 exports.parallelLimit = parallelLimit$1;
5236 exports.priorityQueue = priorityQueue;
5237 exports.queue = queue$1;
5238 exports.race = race;
5239 exports.reduce = reduce;
5240 exports.reduceRight = reduceRight;
5241 exports.reflect = reflect;
5242 exports.reflectAll = reflectAll;
5243 exports.reject = reject;
5244 exports.rejectLimit = rejectLimit;
5245 exports.rejectSeries = rejectSeries;
5246 exports.retry = retry;
5247 exports.retryable = retryable;
5248 exports.seq = seq$1;
5249 exports.series = series;
5250 exports.setImmediate = setImmediate$1;
5251 exports.some = some;
5252 exports.someLimit = someLimit;
5253 exports.someSeries = someSeries;
5254 exports.sortBy = sortBy;
5255 exports.timeout = timeout;
5256 exports.times = times;
5257 exports.timesLimit = timeLimit;
5258 exports.timesSeries = timesSeries;
5259 exports.transform = transform;
5260 exports.unmemoize = unmemoize;
5261 exports.until = until;
5262 exports.waterfall = waterfall;
5263 exports.whilst = whilst;
5264 exports.all = every;
5265 exports.allLimit = everyLimit;
5266 exports.allSeries = everySeries;
5268 exports.anyLimit = someLimit;
5269 exports.anySeries = someSeries;
5270 exports.find = detect;
5271 exports.findLimit = detectLimit;
5272 exports.findSeries = detectSeries;
5273 exports.forEach = eachLimit;
5274 exports.forEachSeries = eachSeries;
5275 exports.forEachLimit = eachLimit$1;
5276 exports.forEachOf = eachOf;
5277 exports.forEachOfSeries = eachOfSeries;
5278 exports.forEachOfLimit = eachOfLimit;
5279 exports.inject = reduce;
5280 exports.foldl = reduce;
5281 exports.foldr = reduceRight;
5282 exports.select = filter;
5283 exports.selectLimit = filterLimit;
5284 exports.selectSeries = filterSeries;
5285 exports.wrapSync = asyncify;
5287 Object.defineProperty(exports, '__esModule', { value: true });