summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGraeme Yeates <yeatesgraeme@gmail.com>2016-07-22 16:36:35 -0400
committerGraeme Yeates <yeatesgraeme@gmail.com>2016-07-22 16:36:35 -0400
commit9832edf1d2be8959963422166c6f2f24437390cf (patch)
tree47bd609f35c21abad8c03219b5ac191f27196335
parentd5f9b2c304f3659de46be45ca39b1ccb13b227da (diff)
downloadasync-9832edf1d2be8959963422166c6f2f24437390cf.tar.gz
Update built files
-rw-r--r--dist/async.js10134
-rw-r--r--dist/async.min.js2
-rw-r--r--dist/async.min.map2
3 files changed, 5118 insertions, 5020 deletions
diff --git a/dist/async.js b/dist/async.js
index 92ed24a..609d9cd 100644
--- a/dist/async.js
+++ b/dist/async.js
@@ -1,5117 +1,5215 @@
(function (global, factory) {
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
- typeof define === 'function' && define.amd ? define(['exports'], factory) :
- (factory((global.async = global.async || {})));
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
+ typeof define === 'function' && define.amd ? define(['exports'], factory) :
+ (factory((global.async = global.async || {})));
}(this, function (exports) { 'use strict';
- /**
- * A faster alternative to `Function#apply`, this function invokes `func`
- * with the `this` binding of `thisArg` and the arguments of `args`.
- *
- * @private
- * @param {Function} func The function to invoke.
- * @param {*} thisArg The `this` binding of `func`.
- * @param {Array} args The arguments to invoke `func` with.
- * @returns {*} Returns the result of `func`.
- */
- function apply(func, thisArg, args) {
- var length = args.length;
- switch (length) {
- case 0: return func.call(thisArg);
- case 1: return func.call(thisArg, args[0]);
- case 2: return func.call(thisArg, args[0], args[1]);
- case 3: return func.call(thisArg, args[0], args[1], args[2]);
- }
- return func.apply(thisArg, args);
- }
-
- /**
- * Checks if `value` is the
- * [language type](http://www.ecma-international.org/ecma-262/6.0/#sec-ecmascript-language-types)
- * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
- *
- * @static
- * @memberOf _
- * @since 0.1.0
- * @category Lang
- * @param {*} value The value to check.
- * @returns {boolean} Returns `true` if `value` is an object, else `false`.
- * @example
- *
- * _.isObject({});
- * // => true
- *
- * _.isObject([1, 2, 3]);
- * // => true
- *
- * _.isObject(_.noop);
- * // => true
- *
- * _.isObject(null);
- * // => false
- */
- function isObject(value) {
- var type = typeof value;
- return !!value && (type == 'object' || type == 'function');
- }
-
- var funcTag = '[object Function]';
- var genTag = '[object GeneratorFunction]';
- /** Used for built-in method references. */
- var objectProto = Object.prototype;
-
- /**
- * Used to resolve the
- * [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
- * of values.
- */
- var objectToString = objectProto.toString;
-
- /**
- * Checks if `value` is classified as a `Function` object.
- *
- * @static
- * @memberOf _
- * @since 0.1.0
- * @category Lang
- * @param {*} value The value to check.
- * @returns {boolean} Returns `true` if `value` is correctly classified,
- * else `false`.
- * @example
- *
- * _.isFunction(_);
- * // => true
- *
- * _.isFunction(/abc/);
- * // => false
- */
- function isFunction(value) {
- // The use of `Object#toString` avoids issues with the `typeof` operator
- // in Safari 8 which returns 'object' for typed array and weak map constructors,
- // and PhantomJS 1.9 which returns 'function' for `NodeList` instances.
- var tag = isObject(value) ? objectToString.call(value) : '';
- return tag == funcTag || tag == genTag;
- }
-
- /**
- * Checks if `value` is object-like. A value is object-like if it's not `null`
- * and has a `typeof` result of "object".
- *
- * @static
- * @memberOf _
- * @since 4.0.0
- * @category Lang
- * @param {*} value The value to check.
- * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
- * @example
- *
- * _.isObjectLike({});
- * // => true
- *
- * _.isObjectLike([1, 2, 3]);
- * // => true
- *
- * _.isObjectLike(_.noop);
- * // => false
- *
- * _.isObjectLike(null);
- * // => false
- */
- function isObjectLike(value) {
- return !!value && typeof value == 'object';
- }
-
- /** `Object#toString` result references. */
- var symbolTag = '[object Symbol]';
-
- /** Used for built-in method references. */
- var objectProto$1 = Object.prototype;
-
- /**
- * Used to resolve the
- * [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
- * of values.
- */
- var objectToString$1 = objectProto$1.toString;
-
- /**
- * Checks if `value` is classified as a `Symbol` primitive or object.
- *
- * @static
- * @memberOf _
- * @since 4.0.0
- * @category Lang
- * @param {*} value The value to check.
- * @returns {boolean} Returns `true` if `value` is correctly classified,
- * else `false`.
- * @example
- *
- * _.isSymbol(Symbol.iterator);
- * // => true
- *
- * _.isSymbol('abc');
- * // => false
- */
- function isSymbol(value) {
- return typeof value == 'symbol' ||
- (isObjectLike(value) && objectToString$1.call(value) == symbolTag);
- }
-
- /** Used as references for various `Number` constants. */
- var NAN = 0 / 0;
-
- /** Used to match leading and trailing whitespace. */
- var reTrim = /^\s+|\s+$/g;
-
- /** Used to detect bad signed hexadecimal string values. */
- var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
-
- /** Used to detect binary string values. */
- var reIsBinary = /^0b[01]+$/i;
-
- /** Used to detect octal string values. */
- var reIsOctal = /^0o[0-7]+$/i;
-
- /** Built-in method references without a dependency on `root`. */
- var freeParseInt = parseInt;
-
- /**
- * Converts `value` to a number.
- *
- * @static
- * @memberOf _
- * @since 4.0.0
- * @category Lang
- * @param {*} value The value to process.
- * @returns {number} Returns the number.
- * @example
- *
- * _.toNumber(3.2);
- * // => 3.2
- *
- * _.toNumber(Number.MIN_VALUE);
- * // => 5e-324
- *
- * _.toNumber(Infinity);
- * // => Infinity
- *
- * _.toNumber('3.2');
- * // => 3.2
- */
- function toNumber(value) {
- if (typeof value == 'number') {
- return value;
- }
- if (isSymbol(value)) {
- return NAN;
+ /**
+ * A faster alternative to `Function#apply`, this function invokes `func`
+ * with the `this` binding of `thisArg` and the arguments of `args`.
+ *
+ * @private
+ * @param {Function} func The function to invoke.
+ * @param {*} thisArg The `this` binding of `func`.
+ * @param {Array} args The arguments to invoke `func` with.
+ * @returns {*} Returns the result of `func`.
+ */
+ function apply(func, thisArg, args) {
+ var length = args.length;
+ switch (length) {
+ case 0: return func.call(thisArg);
+ case 1: return func.call(thisArg, args[0]);
+ case 2: return func.call(thisArg, args[0], args[1]);
+ case 3: return func.call(thisArg, args[0], args[1], args[2]);
+ }
+ return func.apply(thisArg, args);
}
- if (isObject(value)) {
- var other = isFunction(value.valueOf) ? value.valueOf() : value;
- value = isObject(other) ? (other + '') : other;
+
+ /**
+ * Checks if `value` is the
+ * [language type](http://www.ecma-international.org/ecma-262/6.0/#sec-ecmascript-language-types)
+ * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
+ *
+ * @static
+ * @memberOf _
+ * @since 0.1.0
+ * @category Lang
+ * @param {*} value The value to check.
+ * @returns {boolean} Returns `true` if `value` is an object, else `false`.
+ * @example
+ *
+ * _.isObject({});
+ * // => true
+ *
+ * _.isObject([1, 2, 3]);
+ * // => true
+ *
+ * _.isObject(_.noop);
+ * // => true
+ *
+ * _.isObject(null);
+ * // => false
+ */
+ function isObject(value) {
+ var type = typeof value;
+ return !!value && (type == 'object' || type == 'function');
}
- if (typeof value != 'string') {
- return value === 0 ? value : +value;
+
+ var funcTag = '[object Function]';
+ var genTag = '[object GeneratorFunction]';
+ /** Used for built-in method references. */
+ var objectProto = Object.prototype;
+
+ /**
+ * Used to resolve the
+ * [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
+ * of values.
+ */
+ var objectToString = objectProto.toString;
+
+ /**
+ * Checks if `value` is classified as a `Function` object.
+ *
+ * @static
+ * @memberOf _
+ * @since 0.1.0
+ * @category Lang
+ * @param {*} value The value to check.
+ * @returns {boolean} Returns `true` if `value` is correctly classified,
+ * else `false`.
+ * @example
+ *
+ * _.isFunction(_);
+ * // => true
+ *
+ * _.isFunction(/abc/);
+ * // => false
+ */
+ function isFunction(value) {
+ // The use of `Object#toString` avoids issues with the `typeof` operator
+ // in Safari 8 which returns 'object' for typed array and weak map constructors,
+ // and PhantomJS 1.9 which returns 'function' for `NodeList` instances.
+ var tag = isObject(value) ? objectToString.call(value) : '';
+ return tag == funcTag || tag == genTag;
}
- value = value.replace(reTrim, '');
- var isBinary = reIsBinary.test(value);
- return (isBinary || reIsOctal.test(value))
- ? freeParseInt(value.slice(2), isBinary ? 2 : 8)
- : (reIsBadHex.test(value) ? NAN : +value);
- }
-
- var INFINITY = 1 / 0;
- var MAX_INTEGER = 1.7976931348623157e+308;
- /**
- * Converts `value` to a finite number.
- *
- * @static
- * @memberOf _
- * @since 4.12.0
- * @category Lang
- * @param {*} value The value to convert.
- * @returns {number} Returns the converted number.
- * @example
- *
- * _.toFinite(3.2);
- * // => 3.2
- *
- * _.toFinite(Number.MIN_VALUE);
- * // => 5e-324
- *
- * _.toFinite(Infinity);
- * // => 1.7976931348623157e+308
- *
- * _.toFinite('3.2');
- * // => 3.2
- */
- function toFinite(value) {
- if (!value) {
- return value === 0 ? value : 0;
+
+ /**
+ * Checks if `value` is object-like. A value is object-like if it's not `null`
+ * and has a `typeof` result of "object".
+ *
+ * @static
+ * @memberOf _
+ * @since 4.0.0
+ * @category Lang
+ * @param {*} value The value to check.
+ * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
+ * @example
+ *
+ * _.isObjectLike({});
+ * // => true
+ *
+ * _.isObjectLike([1, 2, 3]);
+ * // => true
+ *
+ * _.isObjectLike(_.noop);
+ * // => false
+ *
+ * _.isObjectLike(null);
+ * // => false
+ */
+ function isObjectLike(value) {
+ return !!value && typeof value == 'object';
}
- value = toNumber(value);
- if (value === INFINITY || value === -INFINITY) {
- var sign = (value < 0 ? -1 : 1);
- return sign * MAX_INTEGER;
+
+ /** `Object#toString` result references. */
+ var symbolTag = '[object Symbol]';
+
+ /** Used for built-in method references. */
+ var objectProto$1 = Object.prototype;
+
+ /**
+ * Used to resolve the
+ * [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
+ * of values.
+ */
+ var objectToString$1 = objectProto$1.toString;
+
+ /**
+ * Checks if `value` is classified as a `Symbol` primitive or object.
+ *
+ * @static
+ * @memberOf _
+ * @since 4.0.0
+ * @category Lang
+ * @param {*} value The value to check.
+ * @returns {boolean} Returns `true` if `value` is correctly classified,
+ * else `false`.
+ * @example
+ *
+ * _.isSymbol(Symbol.iterator);
+ * // => true
+ *
+ * _.isSymbol('abc');
+ * // => false
+ */
+ function isSymbol(value) {
+ return typeof value == 'symbol' ||
+ (isObjectLike(value) && objectToString$1.call(value) == symbolTag);
}
- return value === value ? value : 0;
- }
-
- /**
- * Converts `value` to an integer.
- *
- * **Note:** This method is loosely based on
- * [`ToInteger`](http://www.ecma-international.org/ecma-262/6.0/#sec-tointeger).
- *
- * @static
- * @memberOf _
- * @since 4.0.0
- * @category Lang
- * @param {*} value The value to convert.
- * @returns {number} Returns the converted integer.
- * @example
- *
- * _.toInteger(3.2);
- * // => 3
- *
- * _.toInteger(Number.MIN_VALUE);
- * // => 0
- *
- * _.toInteger(Infinity);
- * // => 1.7976931348623157e+308
- *
- * _.toInteger('3.2');
- * // => 3
- */
- function toInteger(value) {
- var result = toFinite(value),
- remainder = result % 1;
-
- return result === result ? (remainder ? result - remainder : result) : 0;
- }
-
- /** Used as the `TypeError` message for "Functions" methods. */
- var FUNC_ERROR_TEXT = 'Expected a function';
-
- /* Built-in method references for those with the same name as other `lodash` methods. */
- var nativeMax = Math.max;
-
- /**
- * Creates a function that invokes `func` with the `this` binding of the
- * created function and arguments from `start` and beyond provided as
- * an array.
- *
- * **Note:** This method is based on the
- * [rest parameter](https://mdn.io/rest_parameters).
- *
- * @static
- * @memberOf _
- * @since 4.0.0
- * @category Function
- * @param {Function} func The function to apply a rest parameter to.
- * @param {number} [start=func.length-1] The start position of the rest parameter.
- * @returns {Function} Returns the new function.
- * @example
- *
- * var say = _.rest(function(what, names) {
- * return what + ' ' + _.initial(names).join(', ') +
- * (_.size(names) > 1 ? ', & ' : '') + _.last(names);
- * });
- *
- * say('hello', 'fred', 'barney', 'pebbles');
- * // => 'hello fred, barney, & pebbles'
- */
- function rest(func, start) {
- if (typeof func != 'function') {
- throw new TypeError(FUNC_ERROR_TEXT);
+
+ /** Used as references for various `Number` constants. */
+ var NAN = 0 / 0;
+
+ /** Used to match leading and trailing whitespace. */
+ var reTrim = /^\s+|\s+$/g;
+
+ /** Used to detect bad signed hexadecimal string values. */
+ var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
+
+ /** Used to detect binary string values. */
+ var reIsBinary = /^0b[01]+$/i;
+
+ /** Used to detect octal string values. */
+ var reIsOctal = /^0o[0-7]+$/i;
+
+ /** Built-in method references without a dependency on `root`. */
+ var freeParseInt = parseInt;
+
+ /**
+ * Converts `value` to a number.
+ *
+ * @static
+ * @memberOf _
+ * @since 4.0.0
+ * @category Lang
+ * @param {*} value The value to process.
+ * @returns {number} Returns the number.
+ * @example
+ *
+ * _.toNumber(3.2);
+ * // => 3.2
+ *
+ * _.toNumber(Number.MIN_VALUE);
+ * // => 5e-324
+ *
+ * _.toNumber(Infinity);
+ * // => Infinity
+ *
+ * _.toNumber('3.2');
+ * // => 3.2
+ */
+ function toNumber(value) {
+ if (typeof value == 'number') {
+ return value;
+ }
+ if (isSymbol(value)) {
+ return NAN;
+ }
+ if (isObject(value)) {
+ var other = isFunction(value.valueOf) ? value.valueOf() : value;
+ value = isObject(other) ? (other + '') : other;
+ }
+ if (typeof value != 'string') {
+ return value === 0 ? value : +value;
+ }
+ value = value.replace(reTrim, '');
+ var isBinary = reIsBinary.test(value);
+ return (isBinary || reIsOctal.test(value))
+ ? freeParseInt(value.slice(2), isBinary ? 2 : 8)
+ : (reIsBadHex.test(value) ? NAN : +value);
}
- start = nativeMax(start === undefined ? (func.length - 1) : toInteger(start), 0);
- return function() {
- var args = arguments,
- index = -1,
- length = nativeMax(args.length - start, 0),
- array = Array(length);
- while (++index < length) {
- array[index] = args[start + index];
+ var INFINITY = 1 / 0;
+ var MAX_INTEGER = 1.7976931348623157e+308;
+ /**
+ * Converts `value` to a finite number.
+ *
+ * @static
+ * @memberOf _
+ * @since 4.12.0
+ * @category Lang
+ * @param {*} value The value to convert.
+ * @returns {number} Returns the converted number.
+ * @example
+ *
+ * _.toFinite(3.2);
+ * // => 3.2
+ *
+ * _.toFinite(Number.MIN_VALUE);
+ * // => 5e-324
+ *
+ * _.toFinite(Infinity);
+ * // => 1.7976931348623157e+308
+ *
+ * _.toFinite('3.2');
+ * // => 3.2
+ */
+ function toFinite(value) {
+ if (!value) {
+ return value === 0 ? value : 0;
}
- switch (start) {
- case 0: return func.call(this, array);
- case 1: return func.call(this, args[0], array);
- case 2: return func.call(this, args[0], args[1], array);
+ value = toNumber(value);
+ if (value === INFINITY || value === -INFINITY) {
+ var sign = (value < 0 ? -1 : 1);
+ return sign * MAX_INTEGER;
}
- var otherArgs = Array(start + 1);
- index = -1;
- while (++index < start) {
- otherArgs[index] = args[index];
+ return value === value ? value : 0;
+ }
+
+ /**
+ * Converts `value` to an integer.
+ *
+ * **Note:** This method is loosely based on
+ * [`ToInteger`](http://www.ecma-international.org/ecma-262/6.0/#sec-tointeger).
+ *
+ * @static
+ * @memberOf _
+ * @since 4.0.0
+ * @category Lang
+ * @param {*} value The value to convert.
+ * @returns {number} Returns the converted integer.
+ * @example
+ *
+ * _.toInteger(3.2);
+ * // => 3
+ *
+ * _.toInteger(Number.MIN_VALUE);
+ * // => 0
+ *
+ * _.toInteger(Infinity);
+ * // => 1.7976931348623157e+308
+ *
+ * _.toInteger('3.2');
+ * // => 3
+ */
+ function toInteger(value) {
+ var result = toFinite(value),
+ remainder = result % 1;
+
+ return result === result ? (remainder ? result - remainder : result) : 0;
+ }
+
+ /** Used as the `TypeError` message for "Functions" methods. */
+ var FUNC_ERROR_TEXT = 'Expected a function';
+
+ /* Built-in method references for those with the same name as other `lodash` methods. */
+ var nativeMax = Math.max;
+
+ /**
+ * Creates a function that invokes `func` with the `this` binding of the
+ * created function and arguments from `start` and beyond provided as
+ * an array.
+ *
+ * **Note:** This method is based on the
+ * [rest parameter](https://mdn.io/rest_parameters).
+ *
+ * @static
+ * @memberOf _
+ * @since 4.0.0
+ * @category Function
+ * @param {Function} func The function to apply a rest parameter to.
+ * @param {number} [start=func.length-1] The start position of the rest parameter.
+ * @returns {Function} Returns the new function.
+ * @example
+ *
+ * var say = _.rest(function(what, names) {
+ * return what + ' ' + _.initial(names).join(', ') +
+ * (_.size(names) > 1 ? ', & ' : '') + _.last(names);
+ * });
+ *
+ * say('hello', 'fred', 'barney', 'pebbles');
+ * // => 'hello fred, barney, & pebbles'
+ */
+ function rest(func, start) {
+ if (typeof func != 'function') {
+ throw new TypeError(FUNC_ERROR_TEXT);
}
- otherArgs[start] = array;
- return apply(func, this, otherArgs);
- };
- }
-
- function initialParams (fn) {
- return rest(function (args /*..., callback*/) {
- var callback = args.pop();
- fn.call(this, args, callback);
- });
- }
-
- function applyEach$1(eachfn) {
- return rest(function (fns, args) {
- var go = initialParams(function (args, callback) {
- var that = this;
- return eachfn(fns, function (fn, cb) {
- fn.apply(that, args.concat([cb]));
- }, callback);
- });
- if (args.length) {
- return go.apply(this, args);
- } else {
- return go;
- }
- });
- }
-
- /**
- * A method that returns `undefined`.
- *
- * @static
- * @memberOf _
- * @since 2.3.0
- * @category Util
- * @example
- *
- * _.times(2, _.noop);
- * // => [undefined, undefined]
- */
- function noop() {
- // No operation performed.
- }
-
- function once(fn) {
- return function () {
- if (fn === null) return;
- var callFn = fn;
- fn = null;
- callFn.apply(this, arguments);
+ start = nativeMax(start === undefined ? (func.length - 1) : toInteger(start), 0);
+ return function() {
+ var args = arguments,
+ index = -1,
+ length = nativeMax(args.length - start, 0),
+ array = Array(length);
+
+ while (++index < length) {
+ array[index] = args[start + index];
+ }
+ switch (start) {
+ case 0: return func.call(this, array);
+ case 1: return func.call(this, args[0], array);
+ case 2: return func.call(this, args[0], args[1], array);
+ }
+ var otherArgs = Array(start + 1);
+ index = -1;
+ while (++index < start) {
+ otherArgs[index] = args[index];
+ }
+ otherArgs[start] = array;
+ return apply(func, this, otherArgs);
};
- }
-
- /**
- * The base implementation of `_.property` without support for deep paths.
- *
- * @private
- * @param {string} key The key of the property to get.
- * @returns {Function} Returns the new accessor function.
- */
- function baseProperty(key) {
- return function(object) {
- return object == null ? undefined : object[key];
- };
- }
-
- /**
- * Gets the "length" property value of `object`.
- *
- * **Note:** This function is used to avoid a
- * [JIT bug](https://bugs.webkit.org/show_bug.cgi?id=142792) that affects
- * Safari on at least iOS 8.1-8.3 ARM64.
- *
- * @private
- * @param {Object} object The object to query.
- * @returns {*} Returns the "length" value.
- */
- var getLength = baseProperty('length');
-
- /** Used as references for various `Number` constants. */
- var MAX_SAFE_INTEGER = 9007199254740991;
-
- /**
- * Checks if `value` is a valid array-like length.
- *
- * **Note:** This function is loosely based on
- * [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength).
- *
- * @static
- * @memberOf _
- * @since 4.0.0
- * @category Lang
- * @param {*} value The value to check.
- * @returns {boolean} Returns `true` if `value` is a valid length,
- * else `false`.
- * @example
- *
- * _.isLength(3);
- * // => true
- *
- * _.isLength(Number.MIN_VALUE);
- * // => false
- *
- * _.isLength(Infinity);
- * // => false
- *
- * _.isLength('3');
- * // => false
- */
- function isLength(value) {
- return typeof value == 'number' &&
- value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
- }
-
- /**
- * Checks if `value` is array-like. A value is considered array-like if it's
- * not a function and has a `value.length` that's an integer greater than or
- * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
- *
- * @static
- * @memberOf _
- * @since 4.0.0
- * @category Lang
- * @param {*} value The value to check.
- * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
- * @example
- *
- * _.isArrayLike([1, 2, 3]);
- * // => true
- *
- * _.isArrayLike(document.body.children);
- * // => true
- *
- * _.isArrayLike('abc');
- * // => true
- *
- * _.isArrayLike(_.noop);
- * // => false
- */
- function isArrayLike(value) {
- return value != null && isLength(getLength(value)) && !isFunction(value);
- }
-
- var iteratorSymbol = typeof Symbol === 'function' && Symbol.iterator;
-
- function getIterator (coll) {
- return iteratorSymbol && coll[iteratorSymbol] && coll[iteratorSymbol]();
- }
-
- /* Built-in method references for those with the same name as other `lodash` methods. */
- var nativeGetPrototype = Object.getPrototypeOf;
-
- /**
- * Gets the `[[Prototype]]` of `value`.
- *
- * @private
- * @param {*} value The value to query.
- * @returns {null|Object} Returns the `[[Prototype]]`.
- */
- function getPrototype(value) {
- return nativeGetPrototype(Object(value));
- }
-
- /** Used for built-in method references. */
- var objectProto$2 = Object.prototype;
-
- /** Used to check objects for own properties. */
- var hasOwnProperty = objectProto$2.hasOwnProperty;
-
- /**
- * The base implementation of `_.has` without support for deep paths.
- *
- * @private
- * @param {Object} [object] The object to query.
- * @param {Array|string} key The key to check.
- * @returns {boolean} Returns `true` if `key` exists, else `false`.
- */
- function baseHas(object, key) {
- // Avoid a bug in IE 10-11 where objects with a [[Prototype]] of `null`,
- // that are composed entirely of index properties, return `false` for
- // `hasOwnProperty` checks of them.
- return object != null &&
- (hasOwnProperty.call(object, key) ||
- (typeof object == 'object' && key in object && getPrototype(object) === null));
- }
-
- /* Built-in method references for those with the same name as other `lodash` methods. */
- var nativeKeys = Object.keys;
-
- /**
- * The base implementation of `_.keys` which doesn't skip the constructor
- * property of prototypes or treat sparse arrays as dense.
- *
- * @private
- * @param {Object} object The object to query.
- * @returns {Array} Returns the array of property names.
- */
- function baseKeys(object) {
- return nativeKeys(Object(object));
- }
-
- /**
- * The base implementation of `_.times` without support for iteratee shorthands
- * or max array length checks.
- *
- * @private
- * @param {number} n The number of times to invoke `iteratee`.
- * @param {Function} iteratee The function invoked per iteration.
- * @returns {Array} Returns the array of results.
- */
- function baseTimes(n, iteratee) {
- var index = -1,
- result = Array(n);
-
- while (++index < n) {
- result[index] = iteratee(index);
}
- return result;
- }
-
- /**
- * This method is like `_.isArrayLike` except that it also checks if `value`
- * is an object.
- *
- * @static
- * @memberOf _
- * @since 4.0.0
- * @category Lang
- * @param {*} value The value to check.
- * @returns {boolean} Returns `true` if `value` is an array-like object,
- * else `false`.
- * @example
- *
- * _.isArrayLikeObject([1, 2, 3]);
- * // => true
- *
- * _.isArrayLikeObject(document.body.children);
- * // => true
- *
- * _.isArrayLikeObject('abc');
- * // => false
- *
- * _.isArrayLikeObject(_.noop);
- * // => false
- */
- function isArrayLikeObject(value) {
- return isObjectLike(value) && isArrayLike(value);
- }
-
- /** `Object#toString` result references. */
- var argsTag = '[object Arguments]';
-
- /** Used for built-in method references. */
- var objectProto$3 = Object.prototype;
-
- /** Used to check objects for own properties. */
- var hasOwnProperty$1 = objectProto$3.hasOwnProperty;
-
- /**
- * Used to resolve the
- * [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
- * of values.
- */
- var objectToString$2 = objectProto$3.toString;
-
- /** Built-in value references. */
- var propertyIsEnumerable = objectProto$3.propertyIsEnumerable;
-
- /**
- * Checks if `value` is likely an `arguments` object.
- *
- * @static
- * @memberOf _
- * @since 0.1.0
- * @category Lang
- * @param {*} value The value to check.
- * @returns {boolean} Returns `true` if `value` is correctly classified,
- * else `false`.
- * @example
- *
- * _.isArguments(function() { return arguments; }());
- * // => true
- *
- * _.isArguments([1, 2, 3]);
- * // => false
- */
- function isArguments(value) {
- // Safari 8.1 incorrectly makes `arguments.callee` enumerable in strict mode.
- return isArrayLikeObject(value) && hasOwnProperty$1.call(value, 'callee') &&
- (!propertyIsEnumerable.call(value, 'callee') || objectToString$2.call(value) == argsTag);
- }
-
- /**
- * Checks if `value` is classified as an `Array` object.
- *
- * @static
- * @memberOf _
- * @since 0.1.0
- * @type {Function}
- * @category Lang
- * @param {*} value The value to check.
- * @returns {boolean} Returns `true` if `value` is correctly classified,
- * else `false`.
- * @example
- *
- * _.isArray([1, 2, 3]);
- * // => true
- *
- * _.isArray(document.body.children);
- * // => false
- *
- * _.isArray('abc');
- * // => false
- *
- * _.isArray(_.noop);
- * // => false
- */
- var isArray = Array.isArray;
-
- /** `Object#toString` result references. */
- var stringTag = '[object String]';
-
- /** Used for built-in method references. */
- var objectProto$4 = Object.prototype;
-
- /**
- * Used to resolve the
- * [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
- * of values.
- */
- var objectToString$3 = objectProto$4.toString;
-
- /**
- * Checks if `value` is classified as a `String` primitive or object.
- *
- * @static
- * @since 0.1.0
- * @memberOf _
- * @category Lang
- * @param {*} value The value to check.
- * @returns {boolean} Returns `true` if `value` is correctly classified,
- * else `false`.
- * @example
- *
- * _.isString('abc');
- * // => true
- *
- * _.isString(1);
- * // => false
- */
- function isString(value) {
- return typeof value == 'string' ||
- (!isArray(value) && isObjectLike(value) && objectToString$3.call(value) == stringTag);
- }
-
- /**
- * Creates an array of index keys for `object` values of arrays,
- * `arguments` objects, and strings, otherwise `null` is returned.
- *
- * @private
- * @param {Object} object The object to query.
- * @returns {Array|null} Returns index keys, else `null`.
- */
- function indexKeys(object) {
- var length = object ? object.length : undefined;
- if (isLength(length) &&
- (isArray(object) || isString(object) || isArguments(object))) {
- return baseTimes(length, String);
+
+ function initialParams (fn) {
+ return rest(function (args /*..., callback*/) {
+ var callback = args.pop();
+ fn.call(this, args, callback);
+ });
+ }
+
+ function applyEach$1(eachfn) {
+ return rest(function (fns, args) {
+ var go = initialParams(function (args, callback) {
+ var that = this;
+ return eachfn(fns, function (fn, cb) {
+ fn.apply(that, args.concat([cb]));
+ }, callback);
+ });
+ if (args.length) {
+ return go.apply(this, args);
+ } else {
+ return go;
+ }
+ });
+ }
+
+ /**
+ * The base implementation of `_.property` without support for deep paths.
+ *
+ * @private
+ * @param {string} key The key of the property to get.
+ * @returns {Function} Returns the new accessor function.
+ */
+ function baseProperty(key) {
+ return function(object) {
+ return object == null ? undefined : object[key];
+ };
+ }
+
+ /**
+ * Gets the "length" property value of `object`.
+ *
+ * **Note:** This function is used to avoid a
+ * [JIT bug](https://bugs.webkit.org/show_bug.cgi?id=142792) that affects
+ * Safari on at least iOS 8.1-8.3 ARM64.
+ *
+ * @private
+ * @param {Object} object The object to query.
+ * @returns {*} Returns the "length" value.
+ */
+ var getLength = baseProperty('length');
+
+ /** Used as references for various `Number` constants. */
+ var MAX_SAFE_INTEGER = 9007199254740991;
+
+ /**
+ * Checks if `value` is a valid array-like length.
+ *
+ * **Note:** This function is loosely based on
+ * [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength).
+ *
+ * @static
+ * @memberOf _
+ * @since 4.0.0
+ * @category Lang
+ * @param {*} value The value to check.
+ * @returns {boolean} Returns `true` if `value` is a valid length,
+ * else `false`.
+ * @example
+ *
+ * _.isLength(3);
+ * // => true
+ *
+ * _.isLength(Number.MIN_VALUE);
+ * // => false
+ *
+ * _.isLength(Infinity);
+ * // => false
+ *
+ * _.isLength('3');
+ * // => false
+ */
+ function isLength(value) {
+ return typeof value == 'number' &&
+ value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
+ }
+
+ /**
+ * Checks if `value` is array-like. A value is considered array-like if it's
+ * not a function and has a `value.length` that's an integer greater than or
+ * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
+ *
+ * @static
+ * @memberOf _
+ * @since 4.0.0
+ * @category Lang
+ * @param {*} value The value to check.
+ * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
+ * @example
+ *
+ * _.isArrayLike([1, 2, 3]);
+ * // => true
+ *
+ * _.isArrayLike(document.body.children);
+ * // => true
+ *
+ * _.isArrayLike('abc');
+ * // => true
+ *
+ * _.isArrayLike(_.noop);
+ * // => false
+ */
+ function isArrayLike(value) {
+ return value != null && isLength(getLength(value)) && !isFunction(value);
+ }
+
+ /**
+ * A method that returns `undefined`.
+ *
+ * @static
+ * @memberOf _
+ * @since 2.3.0
+ * @category Util
+ * @example
+ *
+ * _.times(2, _.noop);
+ * // => [undefined, undefined]
+ */
+ function noop() {
+ // No operation performed.
+ }
+
+ function once(fn) {
+ return function () {
+ if (fn === null) return;
+ var callFn = fn;
+ fn = null;
+ callFn.apply(this, arguments);
+ };
+ }
+
+ var iteratorSymbol = typeof Symbol === 'function' && Symbol.iterator;
+
+ function getIterator (coll) {
+ return iteratorSymbol && coll[iteratorSymbol] && coll[iteratorSymbol]();
+ }
+
+ /* Built-in method references for those with the same name as other `lodash` methods. */
+ var nativeGetPrototype = Object.getPrototypeOf;
+
+ /**
+ * Gets the `[[Prototype]]` of `value`.
+ *
+ * @private
+ * @param {*} value The value to query.
+ * @returns {null|Object} Returns the `[[Prototype]]`.
+ */
+ function getPrototype(value) {
+ return nativeGetPrototype(Object(value));
+ }
+
+ /** Used for built-in method references. */
+ var objectProto$2 = Object.prototype;
+
+ /** Used to check objects for own properties. */
+ var hasOwnProperty = objectProto$2.hasOwnProperty;
+
+ /**
+ * The base implementation of `_.has` without support for deep paths.
+ *
+ * @private
+ * @param {Object} [object] The object to query.
+ * @param {Array|string} key The key to check.
+ * @returns {boolean} Returns `true` if `key` exists, else `false`.
+ */
+ function baseHas(object, key) {
+ // Avoid a bug in IE 10-11 where objects with a [[Prototype]] of `null`,
+ // that are composed entirely of index properties, return `false` for
+ // `hasOwnProperty` checks of them.
+ return object != null &&
+ (hasOwnProperty.call(object, key) ||
+ (typeof object == 'object' && key in object && getPrototype(object) === null));
}
- return null;
- }
-
- /** Used as references for various `Number` constants. */
- var MAX_SAFE_INTEGER$1 = 9007199254740991;
-
- /** Used to detect unsigned integer values. */
- var reIsUint = /^(?:0|[1-9]\d*)$/;
-
- /**
- * Checks if `value` is a valid array-like index.
- *
- * @private
- * @param {*} value The value to check.
- * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
- * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
- */
- function isIndex(value, length) {
- length = length == null ? MAX_SAFE_INTEGER$1 : length;
- return !!length &&
- (typeof value == 'number' || reIsUint.test(value)) &&
- (value > -1 && value % 1 == 0 && value < length);
- }
-
- /** Used for built-in method references. */
- var objectProto$5 = Object.prototype;
-
- /**
- * Checks if `value` is likely a prototype object.
- *
- * @private
- * @param {*} value The value to check.
- * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
- */
- function isPrototype(value) {
- var Ctor = value && value.constructor,
- proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto$5;
-
- return value === proto;
- }
-
- /**
- * Creates an array of the own enumerable property names of `object`.
- *
- * **Note:** Non-object values are coerced to objects. See the
- * [ES spec](http://ecma-international.org/ecma-262/6.0/#sec-object.keys)
- * for more details.
- *
- * @static
- * @since 0.1.0
- * @memberOf _
- * @category Object
- * @param {Object} object The object to query.
- * @returns {Array} Returns the array of property names.
- * @example
- *
- * function Foo() {
- * this.a = 1;
- * this.b = 2;
- * }
- *
- * Foo.prototype.c = 3;
- *
- * _.keys(new Foo);
- * // => ['a', 'b'] (iteration order is not guaranteed)
- *
- * _.keys('hi');
- * // => ['0', '1']
- */
- function keys(object) {
- var isProto = isPrototype(object);
- if (!(isProto || isArrayLike(object))) {
- return baseKeys(object);
+
+ /* Built-in method references for those with the same name as other `lodash` methods. */
+ var nativeKeys = Object.keys;
+
+ /**
+ * The base implementation of `_.keys` which doesn't skip the constructor
+ * property of prototypes or treat sparse arrays as dense.
+ *
+ * @private
+ * @param {Object} object The object to query.
+ * @returns {Array} Returns the array of property names.
+ */
+ function baseKeys(object) {
+ return nativeKeys(Object(object));
}
- var indexes = indexKeys(object),
- skipIndexes = !!indexes,
- result = indexes || [],
- length = result.length;
-
- for (var key in object) {
- if (baseHas(object, key) &&
- !(skipIndexes && (key == 'length' || isIndex(key, length))) &&
- !(isProto && key == 'constructor')) {
- result.push(key);
+
+ /**
+ * The base implementation of `_.times` without support for iteratee shorthands
+ * or max array length checks.
+ *
+ * @private
+ * @param {number} n The number of times to invoke `iteratee`.
+ * @param {Function} iteratee The function invoked per iteration.
+ * @returns {Array} Returns the array of results.
+ */
+ function baseTimes(n, iteratee) {
+ var index = -1,
+ result = Array(n);
+
+ while (++index < n) {
+ result[index] = iteratee(index);
}
+ return result;
+ }
+
+ /**
+ * This method is like `_.isArrayLike` except that it also checks if `value`
+ * is an object.
+ *
+ * @static
+ * @memberOf _
+ * @since 4.0.0
+ * @category Lang
+ * @param {*} value The value to check.
+ * @returns {boolean} Returns `true` if `value` is an array-like object,
+ * else `false`.
+ * @example
+ *
+ * _.isArrayLikeObject([1, 2, 3]);
+ * // => true
+ *
+ * _.isArrayLikeObject(document.body.children);
+ * // => true
+ *
+ * _.isArrayLikeObject('abc');
+ * // => false
+ *
+ * _.isArrayLikeObject(_.noop);
+ * // => false
+ */
+ function isArrayLikeObject(value) {
+ return isObjectLike(value) && isArrayLike(value);
}
- return result;
- }
-
- function iterator(coll) {
- var i = -1;
- var len;
- if (isArrayLike(coll)) {
- len = coll.length;
- return function next() {
- i++;
- return i < len ? { value: coll[i], key: i } : null;
- };
+
+ /** `Object#toString` result references. */
+ var argsTag = '[object Arguments]';
+
+ /** Used for built-in method references. */
+ var objectProto$3 = Object.prototype;
+
+ /** Used to check objects for own properties. */
+ var hasOwnProperty$1 = objectProto$3.hasOwnProperty;
+
+ /**
+ * Used to resolve the
+ * [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
+ * of values.
+ */
+ var objectToString$2 = objectProto$3.toString;
+
+ /** Built-in value references. */
+ var propertyIsEnumerable = objectProto$3.propertyIsEnumerable;
+
+ /**
+ * Checks if `value` is likely an `arguments` object.
+ *
+ * @static
+ * @memberOf _
+ * @since 0.1.0
+ * @category Lang
+ * @param {*} value The value to check.
+ * @returns {boolean} Returns `true` if `value` is correctly classified,
+ * else `false`.
+ * @example
+ *
+ * _.isArguments(function() { return arguments; }());
+ * // => true
+ *
+ * _.isArguments([1, 2, 3]);
+ * // => false
+ */
+ function isArguments(value) {
+ // Safari 8.1 incorrectly makes `arguments.callee` enumerable in strict mode.
+ return isArrayLikeObject(value) && hasOwnProperty$1.call(value, 'callee') &&
+ (!propertyIsEnumerable.call(value, 'callee') || objectToString$2.call(value) == argsTag);
+ }
+
+ /**
+ * Checks if `value` is classified as an `Array` object.
+ *
+ * @static
+ * @memberOf _
+ * @since 0.1.0
+ * @type {Function}
+ * @category Lang
+ * @param {*} value The value to check.
+ * @returns {boolean} Returns `true` if `value` is correctly classified,
+ * else `false`.
+ * @example
+ *
+ * _.isArray([1, 2, 3]);
+ * // => true
+ *
+ * _.isArray(document.body.children);
+ * // => false
+ *
+ * _.isArray('abc');
+ * // => false
+ *
+ * _.isArray(_.noop);
+ * // => false
+ */
+ var isArray = Array.isArray;
+
+ /** `Object#toString` result references. */
+ var stringTag = '[object String]';
+
+ /** Used for built-in method references. */
+ var objectProto$4 = Object.prototype;
+
+ /**
+ * Used to resolve the
+ * [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
+ * of values.
+ */
+ var objectToString$3 = objectProto$4.toString;
+
+ /**
+ * Checks if `value` is classified as a `String` primitive or object.
+ *
+ * @static
+ * @since 0.1.0
+ * @memberOf _
+ * @category Lang
+ * @param {*} value The value to check.
+ * @returns {boolean} Returns `true` if `value` is correctly classified,
+ * else `false`.
+ * @example
+ *
+ * _.isString('abc');
+ * // => true
+ *
+ * _.isString(1);
+ * // => false
+ */
+ function isString(value) {
+ return typeof value == 'string' ||
+ (!isArray(value) && isObjectLike(value) && objectToString$3.call(value) == stringTag);
+ }
+
+ /**
+ * Creates an array of index keys for `object` values of arrays,
+ * `arguments` objects, and strings, otherwise `null` is returned.
+ *
+ * @private
+ * @param {Object} object The object to query.
+ * @returns {Array|null} Returns index keys, else `null`.
+ */
+ function indexKeys(object) {
+ var length = object ? object.length : undefined;
+ if (isLength(length) &&
+ (isArray(object) || isString(object) || isArguments(object))) {
+ return baseTimes(length, String);
}
+ return null;
+ }
- var iterate = getIterator(coll);
- if (iterate) {
- return function next() {
- var item = iterate.next();
- if (item.done) return null;
- i++;
- return { value: item.value, key: i };
- };
+ /** Used as references for various `Number` constants. */
+ var MAX_SAFE_INTEGER$1 = 9007199254740991;
+
+ /** Used to detect unsigned integer values. */
+ var reIsUint = /^(?:0|[1-9]\d*)$/;
+
+ /**
+ * Checks if `value` is a valid array-like index.
+ *
+ * @private
+ * @param {*} value The value to check.
+ * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
+ * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
+ */
+ function isIndex(value, length) {
+ length = length == null ? MAX_SAFE_INTEGER$1 : length;
+ return !!length &&
+ (typeof value == 'number' || reIsUint.test(value)) &&
+ (value > -1 && value % 1 == 0 && value < length);
+ }
+
+ /** Used for built-in method references. */
+ var objectProto$5 = Object.prototype;
+
+ /**
+ * Checks if `value` is likely a prototype object.
+ *
+ * @private
+ * @param {*} value The value to check.
+ * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
+ */
+ function isPrototype(value) {
+ var Ctor = value && value.constructor,
+ proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto$5;
+
+ return value === proto;
+ }
+
+ /**
+ * Creates an array of the own enumerable property names of `object`.
+ *
+ * **Note:** Non-object values are coerced to objects. See the
+ * [ES spec](http://ecma-international.org/ecma-262/6.0/#sec-object.keys)
+ * for more details.
+ *
+ * @static
+ * @since 0.1.0
+ * @memberOf _
+ * @category Object
+ * @param {Object} object The object to query.
+ * @returns {Array} Returns the array of property names.
+ * @example
+ *
+ * function Foo() {
+ * this.a = 1;
+ * this.b = 2;
+ * }
+ *
+ * Foo.prototype.c = 3;
+ *
+ * _.keys(new Foo);
+ * // => ['a', 'b'] (iteration order is not guaranteed)
+ *
+ * _.keys('hi');
+ * // => ['0', '1']
+ */
+ function keys(object) {
+ var isProto = isPrototype(object);
+ if (!(isProto || isArrayLike(object))) {
+ return baseKeys(object);
+ }
+ var indexes = indexKeys(object),
+ skipIndexes = !!indexes,
+ result = indexes || [],
+ length = result.length;
+
+ for (var key in object) {
+ if (baseHas(object, key) &&
+ !(skipIndexes && (key == 'length' || isIndex(key, length))) &&
+ !(isProto && key == 'constructor')) {
+ result.push(key);
+ }
}
+ return result;
+ }
- var okeys = keys(coll);
- len = okeys.length;
- return function next() {
- i++;
- var key = okeys[i];
- return i < len ? { value: coll[key], key: key } : null;
- };
- }
-
- function onlyOnce(fn) {
- return function () {
- if (fn === null) throw new Error("Callback was already called.");
- var callFn = fn;
- fn = null;
- callFn.apply(this, arguments);
- };
- }
-
- function _eachOfLimit(limit) {
- return function (obj, iteratee, callback) {
- callback = once(callback || noop);
- obj = obj || [];
- var nextElem = iterator(obj);
- if (limit <= 0) {
- return callback(null);
- }
- var done = false;
- var running = 0;
- var errored = false;
-
- (function replenish() {
- if (done && running <= 0) {
- return callback(null);
- }
-
- while (running < limit && !errored) {
- var elem = nextElem();
- if (elem === null) {
- done = true;
- if (running <= 0) {
- callback(null);
- }
- return;
- }
- running += 1;
- /* eslint {no-loop-func: 0} */
- iteratee(elem.value, elem.key, onlyOnce(function (err) {
- running -= 1;
- if (err) {
- callback(err);
- errored = true;
- } else {
- replenish();
- }
- }));
- }
- })();
- };
- }
+ function createArrayIterator(coll) {
+ var i = -1;
+ var len = coll.length;
+ return function next() {
+ return ++i < len ? { value: coll[i], key: i } : null;
+ };
+ }
- function doParallelLimit(fn) {
- return function (obj, limit, iteratee, callback) {
- return fn(_eachOfLimit(limit), obj, iteratee, callback);
- };
- }
-
- function _asyncMap(eachfn, arr, iteratee, callback) {
- callback = once(callback || noop);
- arr = arr || [];
- var results = [];
- var counter = 0;
-
- eachfn(arr, function (value, _, callback) {
- var index = counter++;
- iteratee(value, function (err, v) {
- results[index] = v;
- callback(err);
- });
- }, function (err) {
- callback(err, results);
- });
- }
-
- /**
- * The same as [`map`]{@link module:Collections.map} but runs a maximum of `limit` async operations at a time.
- *
- * @name mapLimit
- * @static
- * @memberOf module:Collections
- * @method
- * @see [async.map]{@link module:Collections.map}
- * @category Collection
- * @param {Array|Iterable|Object} coll - A collection to iterate over.
- * @param {number} limit - The maximum number of async operations at a time.
- * @param {Function} iteratee - A function to apply to each item in `coll`.
- * The iteratee is passed a `callback(err, transformed)` which must be called
- * once it has completed with an error (which can be `null`) and a transformed
- * item. Invoked with (item, callback).
- * @param {Function} [callback] - A callback which is called when all `iteratee`
- * functions have finished, or an error occurs. Results is an array of the
- * transformed items from the `coll`. Invoked with (err, results).
- */
- var mapLimit = doParallelLimit(_asyncMap);
-
- function doLimit(fn, limit) {
- return function (iterable, iteratee, callback) {
- return fn(iterable, limit, iteratee, callback);
- };
- }
-
- /**
- * Produces a new collection of values by mapping each value in `coll` through
- * the `iteratee` function. The `iteratee` is called with an item from `coll`
- * and a callback for when it has finished processing. Each of these callback
- * takes 2 arguments: an `error`, and the transformed item from `coll`. If
- * `iteratee` passes an error to its callback, the main `callback` (for the
- * `map` function) is immediately called with the error.
- *
- * Note, that since this function applies the `iteratee` to each item in
- * parallel, there is no guarantee that the `iteratee` functions will complete
- * in order. However, the results array will be in the same order as the
- * original `coll`.
- *
- * If `map` is passed an Object, the results will be an Array. The results
- * will roughly be in the order of the original Objects' keys (but this can
- * vary across JavaScript engines)
- *
- * @name map
- * @static
- * @memberOf module:Collections
- * @method
- * @category Collection
- * @param {Array|Iterable|Object} coll - A collection to iterate over.
- * @param {Function} iteratee - A function to apply to each item in `coll`.
- * The iteratee is passed a `callback(err, transformed)` which must be called
- * once it has completed with an error (which can be `null`) and a
- * transformed item. Invoked with (item, callback).
- * @param {Function} [callback] - A callback which is called when all `iteratee`
- * functions have finished, or an error occurs. Results is an Array of the
- * transformed items from the `coll`. Invoked with (err, results).
- * @example
- *
- * async.map(['file1','file2','file3'], fs.stat, function(err, results) {
- * // results is now an array of stats for each file
- * });
- */
- var map = doLimit(mapLimit, Infinity);
-
- /**
- * Applies the provided arguments to each function in the array, calling
- * `callback` after all functions have completed. If you only provide the first
- * argument, then it will return a function which lets you pass in the
- * arguments as if it were a single function call.
- *
- * @name applyEach
- * @static
- * @memberOf module:ControlFlow
- * @method
- * @category Control Flow
- * @param {Array|Iterable|Object} fns - A collection of asynchronous functions to all
- * call with the same arguments
- * @param {...*} [args] - any number of separate arguments to pass to the
- * function.
- * @param {Function} [callback] - the final argument should be the callback,
- * called when all functions have completed processing.
- * @returns {Function} - If only the first argument is provided, it will return
- * a function which lets you pass in the arguments as if it were a single
- * function call.
- * @example
- *
- * async.applyEach([enableSearch, updateSchema], 'bucket', callback);
- *
- * // partial application example:
- * async.each(
- * buckets,
- * async.applyEach([enableSearch, updateSchema]),
- * callback
- * );
- */
- var applyEach = applyEach$1(map);
-
- /**
- * The same as [`map`]{@link module:Collections.map} but runs only a single async operation at a time.
- *
- * @name mapSeries
- * @static
- * @memberOf module:Collections
- * @method
- * @see [async.map]{@link module:Collections.map}
- * @category Collection
- * @param {Array|Iterable|Object} coll - A collection to iterate over.
- * @param {Function} iteratee - A function to apply to each item in `coll`.
- * The iteratee is passed a `callback(err, transformed)` which must be called
- * once it has completed with an error (which can be `null`) and a
- * transformed item. Invoked with (item, callback).
- * @param {Function} [callback] - A callback which is called when all `iteratee`
- * functions have finished, or an error occurs. Results is an array of the
- * transformed items from the `coll`. Invoked with (err, results).
- */
- var mapSeries = doLimit(mapLimit, 1);
-
- /**
- * The same as [`applyEach`]{@link module:ControlFlow.applyEach} but runs only a single async operation at a time.
- *
- * @name applyEachSeries
- * @static
- * @memberOf module:ControlFlow
- * @method
- * @see [async.applyEach]{@link module:ControlFlow.applyEach}
- * @category Control Flow
- * @param {Array|Iterable|Object} fns - A collection of asynchronous functions to all
- * call with the same arguments
- * @param {...*} [args] - any number of separate arguments to pass to the
- * function.
- * @param {Function} [callback] - the final argument should be the callback,
- * called when all functions have completed processing.
- * @returns {Function} - If only the first argument is provided, it will return
- * a function which lets you pass in the arguments as if it were a single
- * function call.
- */
- var applyEachSeries = applyEach$1(mapSeries);
-
- /**
- * Creates a continuation function with some arguments already applied.
- *
- * Useful as a shorthand when combined with other control flow functions. Any
- * arguments passed to the returned function are added to the arguments
- * originally passed to apply.
- *
- * @name apply
- * @static
- * @memberOf module:Utils
- * @method
- * @category Util
- * @param {Function} function - The function you want to eventually apply all
- * arguments to. Invokes with (arguments...).
- * @param {...*} arguments... - Any number of arguments to automatically apply
- * when the continuation is called.
- * @example
- *
- * // using apply
- * async.parallel([
- * async.apply(fs.writeFile, 'testfile1', 'test1'),
- * async.apply(fs.writeFile, 'testfile2', 'test2')
- * ]);
- *
- *
- * // the same process without using apply
- * async.parallel([
- * function(callback) {
- * fs.writeFile('testfile1', 'test1', callback);
- * },
- * function(callback) {
- * fs.writeFile('testfile2', 'test2', callback);
- * }
- * ]);
- *
- * // It's possible to pass any number of additional arguments when calling the
- * // continuation:
- *
- * node> var fn = async.apply(sys.puts, 'one');
- * node> fn('two', 'three');
- * one
- * two
- * three
- */
- var apply$1 = rest(function (fn, args) {
- return rest(function (callArgs) {
- return fn.apply(null, args.concat(callArgs));
- });
- });
-
- /**
- * Take a sync function and make it async, passing its return value to a
- * callback. This is useful for plugging sync functions into a waterfall,
- * series, or other async functions. Any arguments passed to the generated
- * function will be passed to the wrapped function (except for the final
- * callback argument). Errors thrown will be passed to the callback.
- *
- * If the function passed to `asyncify` returns a Promise, that promises's
- * resolved/rejected state will be used to call the callback, rather than simply
- * the synchronous return value.
- *
- * This also means you can asyncify ES2016 `async` functions.
- *
- * @name asyncify
- * @static
- * @memberOf module:Utils
- * @method
- * @alias wrapSync
- * @category Util
- * @param {Function} func - The synchronous function to convert to an
- * asynchronous function.
- * @returns {Function} An asynchronous wrapper of the `func`. To be invoked with
- * (callback).
- * @example
- *
- * // passing a regular synchronous function
- * async.waterfall([
- * async.apply(fs.readFile, filename, "utf8"),
- * async.asyncify(JSON.parse),
- * function (data, next) {
- * // data is the result of parsing the text.
- * // If there was a parsing error, it would have been caught.
- * }
- * ], callback);
- *
- * // passing a function returning a promise
- * async.waterfall([
- * async.apply(fs.readFile, filename, "utf8"),
- * async.asyncify(function (contents) {
- * return db.model.create(contents);
- * }),
- * function (model, next) {
- * // `model` is the instantiated model object.
- * // If there was an error, this function would be skipped.
- * }
- * ], callback);
- *
- * // es6 example
- * var q = async.queue(async.asyncify(async function(file) {
- * var intermediateStep = await processFile(file);
- * return await somePromise(intermediateStep)
- * }));
- *
- * q.push(files);
- */
- function asyncify(func) {
- return initialParams(function (args, callback) {
- var result;
- try {
- result = func.apply(this, args);
- } catch (e) {
- return callback(e);
- }
- // if result is Promise object
- if (isObject(result) && typeof result.then === 'function') {
- result.then(function (value) {
- callback(null, value);
- }, function (err) {
- callback(err.message ? err : new Error(err));
- });
- } else {
- callback(null, result);
- }
- });
- }
-
- /**
- * A specialized version of `_.forEach` for arrays without support for
- * iteratee shorthands.
- *
- * @private
- * @param {Array} [array] The array to iterate over.
- * @param {Function} iteratee The function invoked per iteration.
- * @returns {Array} Returns `array`.
- */
- function arrayEach(array, iteratee) {
- var index = -1,
- length = array ? array.length : 0;
-
- while (++index < length) {
- if (iteratee(array[index], index, array) === false) {
- break;
+ function createES2015Iterator(iterator) {
+ var i = -1;
+ return function next() {
+ var item = iterator.next();
+ if (item.done) return null;
+ i++;
+ return { value: item.value, key: i };
+ };
+ }
+
+ function createObjectIterator(obj) {
+ var okeys = keys(obj);
+ var i = -1;
+ var len = okeys.length;
+ return function next() {
+ var key = okeys[++i];
+ return i < len ? { value: obj[key], key: key } : null;
+ };
+ }
+
+ function iterator(coll) {
+ if (isArrayLike(coll)) {
+ return createArrayIterator(coll);
+ }
+
+ var iterator = getIterator(coll);
+ return iterator ? createES2015Iterator(iterator) : createObjectIterator(coll);
+ }
+
+ function onlyOnce(fn) {
+ return function () {
+ if (fn === null) throw new Error("Callback was already called.");
+ var callFn = fn;
+ fn = null;
+ callFn.apply(this, arguments);
+ };
+ }
+
+ function _eachOfLimit(limit) {
+ return function (obj, iteratee, callback) {
+ callback = once(callback || noop);
+ if (limit <= 0 || !obj) {
+ return callback(null);
+ }
+ var nextElem = iterator(obj);
+ var done = false;
+ var running = 0;
+
+ function iterateeCallback(err) {
+ running -= 1;
+ if (err) {
+ done = true;
+ callback(err);
+ } else if (done && running <= 0) {
+ return callback(null);
+ } else {
+ replenish();
+ }
+ }
+
+ function replenish() {
+ while (running < limit && !done) {
+ var elem = nextElem();
+ if (elem === null) {
+ done = true;
+ if (running <= 0) {
+ callback(null);
+ }
+ return;
+ }
+ running += 1;
+ iteratee(elem.value, elem.key, onlyOnce(iterateeCallback));
+ }
+ }
+
+ replenish();
+ };
+ }
+
+ /**
+ * The same as [`eachOf`]{@link module:Collections.eachOf} but runs a maximum of `limit` async operations at a
+ * time.
+ *
+ * @name eachOfLimit
+ * @static
+ * @memberOf module:Collections
+ * @method
+ * @see [async.eachOf]{@link module:Collections.eachOf}
+ * @alias forEachOfLimit
+ * @category Collection
+ * @param {Array|Iterable|Object} coll - A collection to iterate over.
+ * @param {number} limit - The maximum number of async operations at a time.
+ * @param {Function} iteratee - A function to apply to each
+ * item in `coll`. The `key` is the item's key, or index in the case of an
+ * array. The iteratee is passed a `callback(err)` which must be called once it
+ * has completed. If no error has occurred, the callback should be run without
+ * arguments or with an explicit `null` argument. Invoked with
+ * (item, key, callback).
+ * @param {Function} [callback] - A callback which is called when all
+ * `iteratee` functions have finished, or an error occurs. Invoked with (err).
+ */
+ function eachOfLimit(coll, limit, iteratee, callback) {
+ _eachOfLimit(limit)(coll, iteratee, callback);
+ }
+
+ function doLimit(fn, limit) {
+ return function (iterable, iteratee, callback) {
+ return fn(iterable, limit, iteratee, callback);
+ };
+ }
+
+ /** Used as the `TypeError` message for "Functions" methods. */
+ var FUNC_ERROR_TEXT$1 = 'Expected a function';
+
+ /**
+ * Creates a function that invokes `func`, with the `this` binding and arguments
+ * of the created function, while it's called less than `n` times. Subsequent
+ * calls to the created function return the result of the last `func` invocation.
+ *
+ * @static
+ * @memberOf _
+ * @since 3.0.0
+ * @category Function
+ * @param {number} n The number of calls at which `func` is no longer invoked.
+ * @param {Function} func The function to restrict.
+ * @returns {Function} Returns the new restricted function.
+ * @example
+ *
+ * jQuery(element).on('click', _.before(5, addContactToList));
+ * // => allows adding up to 4 contacts to the list
+ */
+ function before(n, func) {
+ var result;
+ if (typeof func != 'function') {
+ throw new TypeError(FUNC_ERROR_TEXT$1);
}
+ n = toInteger(n);
+ return function() {
+ if (--n > 0) {
+ result = func.apply(this, arguments);
+ }
+ if (n <= 1) {
+ func = undefined;
+ }
+ return result;
+ };
+ }
+
+ /**
+ * Creates a function that is restricted to invoking `func` once. Repeat calls
+ * to the function return the value of the first invocation. The `func` is
+ * invoked with the `this` binding and arguments of the created function.
+ *
+ * @static
+ * @memberOf _
+ * @since 0.1.0
+ * @category Function
+ * @param {Function} func The function to restrict.
+ * @returns {Function} Returns the new restricted function.
+ * @example
+ *
+ * var initialize = _.once(createApplication);
+ * initialize();
+ * initialize();
+ * // `initialize` invokes `createApplication` once
+ */
+ function once$1(func) {
+ return before(2, func);
+ }
+
+ // eachOf implementation optimized for array-likes
+ function eachOfArrayLike(coll, iteratee, callback) {
+ callback = once$1(callback || noop);
+ var index = 0,
+ completed = 0,
+ length = coll.length;
+ if (length === 0) {
+ callback(null);
+ }
+
+ function iteratorCallback(err) {
+ if (err) {
+ callback(err);
+ } else if (++completed === length) {
+ callback(null);
+ }
+ }
+
+ for (; index < length; index++) {
+ iteratee(coll[index], index, onlyOnce(iteratorCallback));
+ }
}
- return array;
- }
-
- /**
- * Creates a base function for methods like `_.forIn` and `_.forOwn`.
- *
- * @private
- * @param {boolean} [fromRight] Specify iterating from right to left.
- * @returns {Function} Returns the new base function.
- */
- function createBaseFor(fromRight) {
- return function(object, iteratee, keysFunc) {
+
+ // a generic version of eachOf which can handle array, object, and iterator cases.
+ var eachOfGeneric = doLimit(eachOfLimit, Infinity);
+
+ /**
+ * Like [`each`]{@link module:Collections.each}, except that it passes the key (or index) as the second argument
+ * to the iteratee.
+ *
+ * @name eachOf
+ * @static
+ * @memberOf module:Collections
+ * @method
+ * @alias forEachOf
+ * @category Collection
+ * @see [async.each]{@link module:Collections.each}
+ * @param {Array|Iterable|Object} coll - A collection to iterate over.
+ * @param {Function} iteratee - A function to apply to each
+ * item in `coll`. The `key` is the item's key, or index in the case of an
+ * array. The iteratee is passed a `callback(err)` which must be called once it
+ * has completed. If no error has occurred, the callback should be run without
+ * arguments or with an explicit `null` argument. Invoked with
+ * (item, key, callback).
+ * @param {Function} [callback] - A callback which is called when all
+ * `iteratee` functions have finished, or an error occurs. Invoked with (err).
+ * @example
+ *
+ * var obj = {dev: "/dev.json", test: "/test.json", prod: "/prod.json"};
+ * var configs = {};
+ *
+ * async.forEachOf(obj, function (value, key, callback) {
+ * fs.readFile(__dirname + value, "utf8", function (err, data) {
+ * if (err) return callback(err);
+ * try {
+ * configs[key] = JSON.parse(data);
+ * } catch (e) {
+ * return callback(e);
+ * }
+ * callback();
+ * });
+ * }, function (err) {
+ * if (err) console.error(err.message);
+ * // configs is now a map of JSON data
+ * doSomethingWith(configs);
+ * });
+ */
+ function eachOf (coll, iteratee, callback) {
+ var eachOfImplementation = isArrayLike(coll) ? eachOfArrayLike : eachOfGeneric;
+ eachOfImplementation(coll, iteratee, callback);
+ }
+
+ function doParallel(fn) {
+ return function (obj, iteratee, callback) {
+ return fn(eachOf, obj, iteratee, callback);
+ };
+ }
+
+ function _asyncMap(eachfn, arr, iteratee, callback) {
+ callback = once(callback || noop);
+ arr = arr || [];
+ var results = [];
+ var counter = 0;
+
+ eachfn(arr, function (value, _, callback) {
+ var index = counter++;
+ iteratee(value, function (err, v) {
+ results[index] = v;
+ callback(err);
+ });
+ }, function (err) {
+ callback(err, results);
+ });
+ }
+
+ /**
+ * Produces a new collection of values by mapping each value in `coll` through
+ * the `iteratee` function. The `iteratee` is called with an item from `coll`
+ * and a callback for when it has finished processing. Each of these callback
+ * takes 2 arguments: an `error`, and the transformed item from `coll`. If
+ * `iteratee` passes an error to its callback, the main `callback` (for the
+ * `map` function) is immediately called with the error.
+ *
+ * Note, that since this function applies the `iteratee` to each item in
+ * parallel, there is no guarantee that the `iteratee` functions will complete
+ * in order. However, the results array will be in the same order as the
+ * original `coll`.
+ *
+ * If `map` is passed an Object, the results will be an Array. The results
+ * will roughly be in the order of the original Objects' keys (but this can
+ * vary across JavaScript engines)
+ *
+ * @name map
+ * @static
+ * @memberOf module:Collections
+ * @method
+ * @category Collection
+ * @param {Array|Iterable|Object} coll - A collection to iterate over.
+ * @param {Function} iteratee - A function to apply to each item in `coll`.
+ * The iteratee is passed a `callback(err, transformed)` which must be called
+ * once it has completed with an error (which can be `null`) and a
+ * transformed item. Invoked with (item, callback).
+ * @param {Function} [callback] - A callback which is called when all `iteratee`
+ * functions have finished, or an error occurs. Results is an Array of the
+ * transformed items from the `coll`. Invoked with (err, results).
+ * @example
+ *
+ * async.map(['file1','file2','file3'], fs.stat, function(err, results) {
+ * // results is now an array of stats for each file
+ * });
+ */
+ var map = doParallel(_asyncMap);
+
+ /**
+ * Applies the provided arguments to each function in the array, calling
+ * `callback` after all functions have completed. If you only provide the first
+ * argument, then it will return a function which lets you pass in the
+ * arguments as if it were a single function call.
+ *
+ * @name applyEach
+ * @static
+ * @memberOf module:ControlFlow
+ * @method
+ * @category Control Flow
+ * @param {Array|Iterable|Object} fns - A collection of asynchronous functions to all
+ * call with the same arguments
+ * @param {...*} [args] - any number of separate arguments to pass to the
+ * function.
+ * @param {Function} [callback] - the final argument should be the callback,
+ * called when all functions have completed processing.
+ * @returns {Function} - If only the first argument is provided, it will return
+ * a function which lets you pass in the arguments as if it were a single
+ * function call.
+ * @example
+ *
+ * async.applyEach([enableSearch, updateSchema], 'bucket', callback);
+ *
+ * // partial application example:
+ * async.each(
+ * buckets,
+ * async.applyEach([enableSearch, updateSchema]),
+ * callback
+ * );
+ */
+ var applyEach = applyEach$1(map);
+
+ function doParallelLimit(fn) {
+ return function (obj, limit, iteratee, callback) {
+ return fn(_eachOfLimit(limit), obj, iteratee, callback);
+ };
+ }
+
+ /**
+ * The same as [`map`]{@link module:Collections.map} but runs a maximum of `limit` async operations at a time.
+ *
+ * @name mapLimit
+ * @static
+ * @memberOf module:Collections
+ * @method
+ * @see [async.map]{@link module:Collections.map}
+ * @category Collection
+ * @param {Array|Iterable|Object} coll - A collection to iterate over.
+ * @param {number} limit - The maximum number of async operations at a time.
+ * @param {Function} iteratee - A function to apply to each item in `coll`.
+ * The iteratee is passed a `callback(err, transformed)` which must be called
+ * once it has completed with an error (which can be `null`) and a transformed
+ * item. Invoked with (item, callback).
+ * @param {Function} [callback] - A callback which is called when all `iteratee`
+ * functions have finished, or an error occurs. Results is an array of the
+ * transformed items from the `coll`. Invoked with (err, results).
+ */
+ var mapLimit = doParallelLimit(_asyncMap);
+
+ /**
+ * The same as [`map`]{@link module:Collections.map} but runs only a single async operation at a time.
+ *
+ * @name mapSeries
+ * @static
+ * @memberOf module:Collections
+ * @method
+ * @see [async.map]{@link module:Collections.map}
+ * @category Collection
+ * @param {Array|Iterable|Object} coll - A collection to iterate over.
+ * @param {Function} iteratee - A function to apply to each item in `coll`.
+ * The iteratee is passed a `callback(err, transformed)` which must be called
+ * once it has completed with an error (which can be `null`) and a
+ * transformed item. Invoked with (item, callback).
+ * @param {Function} [callback] - A callback which is called when all `iteratee`
+ * functions have finished, or an error occurs. Results is an array of the
+ * transformed items from the `coll`. Invoked with (err, results).
+ */
+ var mapSeries = doLimit(mapLimit, 1);
+
+ /**
+ * The same as [`applyEach`]{@link module:ControlFlow.applyEach} but runs only a single async operation at a time.
+ *
+ * @name applyEachSeries
+ * @static
+ * @memberOf module:ControlFlow
+ * @method
+ * @see [async.applyEach]{@link module:ControlFlow.applyEach}
+ * @category Control Flow
+ * @param {Array|Iterable|Object} fns - A collection of asynchronous functions to all
+ * call with the same arguments
+ * @param {...*} [args] - any number of separate arguments to pass to the
+ * function.
+ * @param {Function} [callback] - the final argument should be the callback,
+ * called when all functions have completed processing.
+ * @returns {Function} - If only the first argument is provided, it will return
+ * a function which lets you pass in the arguments as if it were a single
+ * function call.
+ */
+ var applyEachSeries = applyEach$1(mapSeries);
+
+ /**
+ * Creates a continuation function with some arguments already applied.
+ *
+ * Useful as a shorthand when combined with other control flow functions. Any
+ * arguments passed to the returned function are added to the arguments
+ * originally passed to apply.
+ *
+ * @name apply
+ * @static
+ * @memberOf module:Utils
+ * @method
+ * @category Util
+ * @param {Function} function - The function you want to eventually apply all
+ * arguments to. Invokes with (arguments...).
+ * @param {...*} arguments... - Any number of arguments to automatically apply
+ * when the continuation is called.
+ * @example
+ *
+ * // using apply
+ * async.parallel([
+ * async.apply(fs.writeFile, 'testfile1', 'test1'),
+ * async.apply(fs.writeFile, 'testfile2', 'test2')
+ * ]);
+ *
+ *
+ * // the same process without using apply
+ * async.parallel([
+ * function(callback) {
+ * fs.writeFile('testfile1', 'test1', callback);
+ * },
+ * function(callback) {
+ * fs.writeFile('testfile2', 'test2', callback);
+ * }
+ * ]);
+ *
+ * // It's possible to pass any number of additional arguments when calling the
+ * // continuation:
+ *
+ * node> var fn = async.apply(sys.puts, 'one');
+ * node> fn('two', 'three');
+ * one
+ * two
+ * three
+ */
+ var apply$1 = rest(function (fn, args) {
+ return rest(function (callArgs) {
+ return fn.apply(null, args.concat(callArgs));
+ });
+ });
+
+ /**
+ * Take a sync function and make it async, passing its return value to a
+ * callback. This is useful for plugging sync functions into a waterfall,
+ * series, or other async functions. Any arguments passed to the generated
+ * function will be passed to the wrapped function (except for the final
+ * callback argument). Errors thrown will be passed to the callback.
+ *
+ * If the function passed to `asyncify` returns a Promise, that promises's
+ * resolved/rejected state will be used to call the callback, rather than simply
+ * the synchronous return value.
+ *
+ * This also means you can asyncify ES2016 `async` functions.
+ *
+ * @name asyncify
+ * @static
+ * @memberOf module:Utils
+ * @method
+ * @alias wrapSync
+ * @category Util
+ * @param {Function} func - The synchronous function to convert to an
+ * asynchronous function.
+ * @returns {Function} An asynchronous wrapper of the `func`. To be invoked with
+ * (callback).
+ * @example
+ *
+ * // passing a regular synchronous function
+ * async.waterfall([
+ * async.apply(fs.readFile, filename, "utf8"),
+ * async.asyncify(JSON.parse),
+ * function (data, next) {
+ * // data is the result of parsing the text.
+ * // If there was a parsing error, it would have been caught.
+ * }
+ * ], callback);
+ *
+ * // passing a function returning a promise
+ * async.waterfall([
+ * async.apply(fs.readFile, filename, "utf8"),
+ * async.asyncify(function (contents) {
+ * return db.model.create(contents);
+ * }),
+ * function (model, next) {
+ * // `model` is the instantiated model object.
+ * // If there was an error, this function would be skipped.
+ * }
+ * ], callback);
+ *
+ * // es6 example
+ * var q = async.queue(async.asyncify(async function(file) {
+ * var intermediateStep = await processFile(file);
+ * return await somePromise(intermediateStep)
+ * }));
+ *
+ * q.push(files);
+ */
+ function asyncify(func) {
+ return initialParams(function (args, callback) {
+ var result;
+ try {
+ result = func.apply(this, args);
+ } catch (e) {
+ return callback(e);
+ }
+ // if result is Promise object
+ if (isObject(result) && typeof result.then === 'function') {
+ result.then(function (value) {
+ callback(null, value);
+ }, function (err) {
+ callback(err.message ? err : new Error(err));
+ });
+ } else {
+ callback(null, result);
+ }
+ });
+ }
+
+ /**
+ * A specialized version of `_.forEach` for arrays without support for
+ * iteratee shorthands.
+ *
+ * @private
+ * @param {Array} [array] The array to iterate over.
+ * @param {Function} iteratee The function invoked per iteration.
+ * @returns {Array} Returns `array`.
+ */
+ function arrayEach(array, iteratee) {
var index = -1,
- iterable = Object(object),
- props = keysFunc(object),
- length = props.length;
+ length = array ? array.length : 0;
- while (length--) {
- var key = props[fromRight ? length : ++index];
- if (iteratee(iterable[key], key, iterable) === false) {
+ while (++index < length) {
+ if (iteratee(array[index], index, array) === false) {
break;
}
}
- return object;
- };
- }
-
- /**
- * The base implementation of `baseForOwn` which iterates over `object`
- * properties returned by `keysFunc` and invokes `iteratee` for each property.
- * Iteratee functions may exit iteration early by explicitly returning `false`.
- *
- * @private
- * @param {Object} object The object to iterate over.
- * @param {Function} iteratee The function invoked per iteration.
- * @param {Function} keysFunc The function to get the keys of `object`.
- * @returns {Object} Returns `object`.
- */
- var baseFor = createBaseFor();
-
- /**
- * The base implementation of `_.forOwn` without support for iteratee shorthands.
- *
- * @private
- * @param {Object} object The object to iterate over.
- * @param {Function} iteratee The function invoked per iteration.
- * @returns {Object} Returns `object`.
- */
- function baseForOwn(object, iteratee) {
- return object && baseFor(object, iteratee, keys);
- }
-
- /**
- * Gets the index at which the first occurrence of `NaN` is found in `array`.
- *
- * @private
- * @param {Array} array The array to search.
- * @param {number} fromIndex The index to search from.
- * @param {boolean} [fromRight] Specify iterating from right to left.
- * @returns {number} Returns the index of the matched `NaN`, else `-1`.
- */
- function indexOfNaN(array, fromIndex, fromRight) {
- var length = array.length,
- index = fromIndex + (fromRight ? 1 : -1);
-
- while ((fromRight ? index-- : ++index < length)) {
- var other = array[index];
- if (other !== other) {
- return index;
- }
+ return array;
}
- return -1;
- }
-
- /**
- * The base implementation of `_.indexOf` without `fromIndex` bounds checks.
- *
- * @private
- * @param {Array} array The array to search.
- * @param {*} value The value to search for.
- * @param {number} fromIndex The index to search from.
- * @returns {number} Returns the index of the matched value, else `-1`.
- */
- function baseIndexOf(array, value, fromIndex) {
- if (value !== value) {
- return indexOfNaN(array, fromIndex);
+
+ /**
+ * Creates a base function for methods like `_.forIn` and `_.forOwn`.
+ *
+ * @private
+ * @param {boolean} [fromRight] Specify iterating from right to left.
+ * @returns {Function} Returns the new base function.
+ */
+ function createBaseFor(fromRight) {
+ return function(object, iteratee, keysFunc) {
+ var index = -1,
+ iterable = Object(object),
+ props = keysFunc(object),
+ length = props.length;
+
+ while (length--) {
+ var key = props[fromRight ? length : ++index];
+ if (iteratee(iterable[key], key, iterable) === false) {
+ break;
+ }
+ }
+ return object;
+ };
}
- var index = fromIndex - 1,
- length = array.length;
- while (++index < length) {
- if (array[index] === value) {
- return index;
- }
+ /**
+ * The base implementation of `baseForOwn` which iterates over `object`
+ * properties returned by `keysFunc` and invokes `iteratee` for each property.
+ * Iteratee functions may exit iteration early by explicitly returning `false`.
+ *
+ * @private
+ * @param {Object} object The object to iterate over.
+ * @param {Function} iteratee The function invoked per iteration.
+ * @param {Function} keysFunc The function to get the keys of `object`.
+ * @returns {Object} Returns `object`.
+ */
+ var baseFor = createBaseFor();
+
+ /**
+ * The base implementation of `_.forOwn` without support for iteratee shorthands.
+ *
+ * @private
+ * @param {Object} object The object to iterate over.
+ * @param {Function} iteratee The function invoked per iteration.
+ * @returns {Object} Returns `object`.
+ */
+ function baseForOwn(object, iteratee) {
+ return object && baseFor(object, iteratee, keys);
}
- return -1;
- }
-
- /**
- * Determines the best order for running the functions in `tasks`, based on
- * their requirements. Each function can optionally depend on other functions
- * being completed first, and each function is run as soon as its requirements
- * are satisfied.
- *
- * If any of the functions pass an error to their callback, the `auto` sequence
- * will stop. Further tasks will not execute (so any other functions depending
- * on it will not run), and the main `callback` is immediately called with the
- * error.
- *
- * Functions also receive an object containing the results of functions which
- * have completed so far as the first argument, if they have dependencies. If a
- * task function has no dependencies, it will only be passed a callback.
- *
- * @name auto
- * @static
- * @memberOf module:ControlFlow
- * @method
- * @category Control Flow
- * @param {Object} tasks - An object. Each of its properties is either a
- * function or an array of requirements, with the function itself the last item
- * in the array. The object's key of a property serves as the name of the task
- * defined by that property, i.e. can be used when specifying requirements for
- * other tasks. The function receives one or two arguments:
- * * a `results` object, containing the results of the previously executed
- * functions, only passed if the task has any dependencies,
- * * a `callback(err, result)` function, which must be called when finished,
- * passing an `error` (which can be `null`) and the result of the function's
- * execution.
- * @param {number} [concurrency=Infinity] - An optional `integer` for
- * determining the maximum number of tasks that can be run in parallel. By
- * default, as many as possible.
- * @param {Function} [callback] - An optional callback which is called when all
- * the tasks have been completed. It receives the `err` argument if any `tasks`
- * pass an error to their callback. Results are always returned; however, if an
- * error occurs, no further `tasks` will be performed, and the results object
- * will only contain partial results. Invoked with (err, results).
- * @returns undefined
- * @example
- *
- * async.auto({
- * // this function will just be passed a callback
- * readData: async.apply(fs.readFile, 'data.txt', 'utf-8'),
- * showData: ['readData', function(results, cb) {
- * // results.readData is the file's contents
- * // ...
- * }]
- * }, callback);
- *
- * async.auto({
- * get_data: function(callback) {
- * console.log('in get_data');
- * // async code to get some data
- * callback(null, 'data', 'converted to array');
- * },
- * make_folder: function(callback) {
- * console.log('in make_folder');
- * // async code to create a directory to store a file in
- * // this is run at the same time as getting the data
- * callback(null, 'folder');
- * },
- * write_file: ['get_data', 'make_folder', function(results, callback) {
- * console.log('in write_file', JSON.stringify(results));
- * // once there is some data and the directory exists,
- * // write the data to a file in the directory
- * callback(null, 'filename');
- * }],
- * email_link: ['write_file', function(results, callback) {
- * console.log('in email_link', JSON.stringify(results));
- * // once the file is written let's email a link to it...
- * // results.write_file contains the filename returned by write_file.
- * callback(null, {'file':results.write_file, 'email':'user@example.com'});
- * }]
- * }, function(err, results) {
- * console.log('err = ', err);
- * console.log('results = ', results);
- * });
- */
- function auto (tasks, concurrency, callback) {
- if (typeof concurrency === 'function') {
- // concurrency is optional, shift the args.
- callback = concurrency;
- concurrency = null;
+
+ /**
+ * Gets the index at which the first occurrence of `NaN` is found in `array`.
+ *
+ * @private
+ * @param {Array} array The array to search.
+ * @param {number} fromIndex The index to search from.
+ * @param {boolean} [fromRight] Specify iterating from right to left.
+ * @returns {number} Returns the index of the matched `NaN`, else `-1`.
+ */
+ function indexOfNaN(array, fromIndex, fromRight) {
+ var length = array.length,
+ index = fromIndex + (fromRight ? 1 : -1);
+
+ while ((fromRight ? index-- : ++index < length)) {
+ var other = array[index];
+ if (other !== other) {
+ return index;
+ }
}
- callback = once(callback || noop);
- var keys$$ = keys(tasks);
- var numTasks = keys$$.length;
- if (!numTasks) {
- return callback(null);
+ return -1;
+ }
+
+ /**
+ * The base implementation of `_.indexOf` without `fromIndex` bounds checks.
+ *
+ * @private
+ * @param {Array} array The array to search.
+ * @param {*} value The value to search for.
+ * @param {number} fromIndex The index to search from.
+ * @returns {number} Returns the index of the matched value, else `-1`.
+ */
+ function baseIndexOf(array, value, fromIndex) {
+ if (value !== value) {
+ return indexOfNaN(array, fromIndex);
}
- if (!concurrency) {
- concurrency = numTasks;
+ var index = fromIndex - 1,
+ length = array.length;
+
+ while (++index < length) {
+ if (array[index] === value) {
+ return index;
+ }
}
+ return -1;
+ }
- var results = {};
- var runningTasks = 0;
- var hasError = false;
+ /**
+ * Determines the best order for running the functions in `tasks`, based on
+ * their requirements. Each function can optionally depend on other functions
+ * being completed first, and each function is run as soon as its requirements
+ * are satisfied.
+ *
+ * If any of the functions pass an error to their callback, the `auto` sequence
+ * will stop. Further tasks will not execute (so any other functions depending
+ * on it will not run), and the main `callback` is immediately called with the
+ * error.
+ *
+ * Functions also receive an object containing the results of functions which
+ * have completed so far as the first argument, if they have dependencies. If a
+ * task function has no dependencies, it will only be passed a callback.
+ *
+ * @name auto
+ * @static
+ * @memberOf module:ControlFlow
+ * @method
+ * @category Control Flow
+ * @param {Object} tasks - An object. Each of its properties is either a
+ * function or an array of requirements, with the function itself the last item
+ * in the array. The object's key of a property serves as the name of the task
+ * defined by that property, i.e. can be used when specifying requirements for
+ * other tasks. The function receives one or two arguments:
+ * * a `results` object, containing the results of the previously executed
+ * functions, only passed if the task has any dependencies,
+ * * a `callback(err, result)` function, which must be called when finished,
+ * passing an `error` (which can be `null`) and the result of the function's
+ * execution.
+ * @param {number} [concurrency=Infinity] - An optional `integer` for
+ * determining the maximum number of tasks that can be run in parallel. By
+ * default, as many as possible.
+ * @param {Function} [callback] - An optional callback which is called when all
+ * the tasks have been completed. It receives the `err` argument if any `tasks`
+ * pass an error to their callback. Results are always returned; however, if an
+ * error occurs, no further `tasks` will be performed, and the results object
+ * will only contain partial results. Invoked with (err, results).
+ * @returns undefined
+ * @example
+ *
+ * async.auto({
+ * // this function will just be passed a callback
+ * readData: async.apply(fs.readFile, 'data.txt', 'utf-8'),
+ * showData: ['readData', function(results, cb) {
+ * // results.readData is the file's contents
+ * // ...
+ * }]
+ * }, callback);
+ *
+ * async.auto({
+ * get_data: function(callback) {
+ * console.log('in get_data');
+ * // async code to get some data
+ * callback(null, 'data', 'converted to array');
+ * },
+ * make_folder: function(callback) {
+ * console.log('in make_folder');
+ * // async code to create a directory to store a file in
+ * // this is run at the same time as getting the data
+ * callback(null, 'folder');
+ * },
+ * write_file: ['get_data', 'make_folder', function(results, callback) {
+ * console.log('in write_file', JSON.stringify(results));
+ * // once there is some data and the directory exists,
+ * // write the data to a file in the directory
+ * callback(null, 'filename');
+ * }],
+ * email_link: ['write_file', function(results, callback) {
+ * console.log('in email_link', JSON.stringify(results));
+ * // once the file is written let's email a link to it...
+ * // results.write_file contains the filename returned by write_file.
+ * callback(null, {'file':results.write_file, 'email':'user@example.com'});
+ * }]
+ * }, function(err, results) {
+ * console.log('err = ', err);
+ * console.log('results = ', results);
+ * });
+ */
+ function auto (tasks, concurrency, callback) {
+ if (typeof concurrency === 'function') {
+ // concurrency is optional, shift the args.
+ callback = concurrency;
+ concurrency = null;
+ }
+ callback = once(callback || noop);
+ var keys$$ = keys(tasks);
+ var numTasks = keys$$.length;
+ if (!numTasks) {
+ return callback(null);
+ }
+ if (!concurrency) {
+ concurrency = numTasks;
+ }
- var listeners = {};
+ var results = {};
+ var runningTasks = 0;
+ var hasError = false;
+
+ var listeners = {};
+
+ var readyTasks = [];
+
+ // for cycle detection:
+ var readyToCheck = []; // tasks that have been identified as reachable
+ // without the possibility of returning to an ancestor task
+ var uncheckedDependencies = {};
+
+ baseForOwn(tasks, function (task, key) {
+ if (!isArray(task)) {
+ // no dependencies
+ enqueueTask(key, [task]);
+ readyToCheck.push(key);
+ return;
+ }
+
+ var dependencies = task.slice(0, task.length - 1);
+ var remainingDependencies = dependencies.length;
+ if (remainingDependencies === 0) {
+ enqueueTask(key, task);
+ readyToCheck.push(key);
+ return;
+ }
+ uncheckedDependencies[key] = remainingDependencies;
+
+ arrayEach(dependencies, function (dependencyName) {
+ if (!tasks[dependencyName]) {
+ throw new Error('async.auto task `' + key + '` has a non-existent dependency in ' + dependencies.join(', '));
+ }
+ addListener(dependencyName, function () {
+ remainingDependencies--;
+ if (remainingDependencies === 0) {
+ enqueueTask(key, task);
+ }
+ });
+ });
+ });
+
+ checkForDeadlocks();
+ processQueue();
+
+ function enqueueTask(key, task) {
+ readyTasks.push(function () {
+ runTask(key, task);
+ });
+ }
- var readyTasks = [];
+ function processQueue() {
+ if (readyTasks.length === 0 && runningTasks === 0) {
+ return callback(null, results);
+ }
+ while (readyTasks.length && runningTasks < concurrency) {
+ var run = readyTasks.shift();
+ run();
+ }
+ }
- // for cycle detection:
- var readyToCheck = []; // tasks that have been identified as reachable
- // without the possibility of returning to an ancestor task
- var uncheckedDependencies = {};
+ function addListener(taskName, fn) {
+ var taskListeners = listeners[taskName];
+ if (!taskListeners) {
+ taskListeners = listeners[taskName] = [];
+ }
- baseForOwn(tasks, function (task, key) {
- if (!isArray(task)) {
- // no dependencies
- enqueueTask(key, [task]);
- readyToCheck.push(key);
- return;
- }
+ taskListeners.push(fn);
+ }
- var dependencies = task.slice(0, task.length - 1);
- var remainingDependencies = dependencies.length;
- if (remainingDependencies === 0) {
- enqueueTask(key, task);
- readyToCheck.push(key);
- return;
- }
- uncheckedDependencies[key] = remainingDependencies;
-
- arrayEach(dependencies, function (dependencyName) {
- if (!tasks[dependencyName]) {
- throw new Error('async.auto task `' + key + '` has a non-existent dependency in ' + dependencies.join(', '));
- }
- addListener(dependencyName, function () {
- remainingDependencies--;
- if (remainingDependencies === 0) {
- enqueueTask(key, task);
- }
- });
- });
- });
-
- checkForDeadlocks();
- processQueue();
-
- function enqueueTask(key, task) {
- readyTasks.push(function () {
- runTask(key, task);
- });
+ function taskComplete(taskName) {
+ var taskListeners = listeners[taskName] || [];
+ arrayEach(taskListeners, function (fn) {
+ fn();
+ });
+ processQueue();
+ }
+
+ function runTask(key, task) {
+ if (hasError) return;
+
+ var taskCallback = onlyOnce(rest(function (err, args) {
+ runningTasks--;
+ if (args.length <= 1) {
+ args = args[0];
+ }
+ if (err) {
+ var safeResults = {};
+ baseForOwn(results, function (val, rkey) {
+ safeResults[rkey] = val;
+ });
+ safeResults[key] = args;
+ hasError = true;
+ listeners = [];
+
+ callback(err, safeResults);
+ } else {
+ results[key] = args;
+ taskComplete(key);
+ }
+ }));
+
+ runningTasks++;
+ var taskFn = task[task.length - 1];
+ if (task.length > 1) {
+ taskFn(results, taskCallback);
+ } else {
+ taskFn(taskCallback);
+ }
+ }
+
+ function checkForDeadlocks() {
+ // Kahn's algorithm
+ // https://en.wikipedia.org/wiki/Topological_sorting#Kahn.27s_algorithm
+ // http://connalle.blogspot.com/2013/10/topological-sortingkahn-algorithm.html
+ var currentTask;
+ var counter = 0;
+ while (readyToCheck.length) {
+ currentTask = readyToCheck.pop();
+ counter++;
+ arrayEach(getDependents(currentTask), function (dependent) {
+ if (--uncheckedDependencies[dependent] === 0) {
+ readyToCheck.push(dependent);
+ }
+ });
+ }
+
+ if (counter !== numTasks) {
+ throw new Error('async.auto cannot execute tasks due to a recursive dependency');
+ }
+ }
+
+ function getDependents(taskName) {
+ var result = [];
+ baseForOwn(tasks, function (task, key) {
+ if (isArray(task) && baseIndexOf(task, taskName, 0) >= 0) {
+ result.push(key);
+ }
+ });
+ return result;
+ }
+ }
+
+ /**
+ * A specialized version of `_.map` for arrays without support for iteratee
+ * shorthands.
+ *
+ * @private
+ * @param {Array} [array] The array to iterate over.
+ * @param {Function} iteratee The function invoked per iteration.
+ * @returns {Array} Returns the new mapped array.
+ */
+ function arrayMap(array, iteratee) {
+ var index = -1,
+ length = array ? array.length : 0,
+ result = Array(length);
+
+ while (++index < length) {
+ result[index] = iteratee(array[index], index, array);
}
+ return result;
+ }
- function processQueue() {
- if (readyTasks.length === 0 && runningTasks === 0) {
- return callback(null, results);
- }
- while (readyTasks.length && runningTasks < concurrency) {
- var run = readyTasks.shift();
- run();
- }
+ /**
+ * Copies the values of `source` to `array`.
+ *
+ * @private
+ * @param {Array} source The array to copy values from.
+ * @param {Array} [array=[]] The array to copy values to.
+ * @returns {Array} Returns `array`.
+ */
+ function copyArray(source, array) {
+ var index = -1,
+ length = source.length;
+
+ array || (array = Array(length));
+ while (++index < length) {
+ array[index] = source[index];
}
+ return array;
+ }
- function addListener(taskName, fn) {
- var taskListeners = listeners[taskName];
- if (!taskListeners) {
- taskListeners = listeners[taskName] = [];
- }
+ /**
+ * Checks if `value` is a global object.
+ *
+ * @private
+ * @param {*} value The value to check.
+ * @returns {null|Object} Returns `value` if it's a global object, else `null`.
+ */
+ function checkGlobal(value) {
+ return (value && value.Object === Object) ? value : null;
+ }
- taskListeners.push(fn);
+ /** Detect free variable `global` from Node.js. */
+ var freeGlobal = checkGlobal(typeof global == 'object' && global);
+
+ /** Detect free variable `self`. */
+ var freeSelf = checkGlobal(typeof self == 'object' && self);
+
+ /** Detect `this` as the global object. */
+ var thisGlobal = checkGlobal(typeof this == 'object' && this);
+
+ /** Used as a reference to the global object. */
+ var root = freeGlobal || freeSelf || thisGlobal || Function('return this')();
+
+ /** Built-in value references. */
+ var Symbol$1 = root.Symbol;
+
+ /** Used as references for various `Number` constants. */
+ var INFINITY$1 = 1 / 0;
+
+ /** Used to convert symbols to primitives and strings. */
+ var symbolProto = Symbol$1 ? Symbol$1.prototype : undefined;
+ var symbolToString = symbolProto ? symbolProto.toString : undefined;
+ /**
+ * The base implementation of `_.toString` which doesn't convert nullish
+ * values to empty strings.
+ *
+ * @private
+ * @param {*} value The value to process.
+ * @returns {string} Returns the string.
+ */
+ function baseToString(value) {
+ // Exit early for strings to avoid a performance hit in some environments.
+ if (typeof value == 'string') {
+ return value;
}
+ if (isSymbol(value)) {
+ return symbolToString ? symbolToString.call(value) : '';
+ }
+ var result = (value + '');
+ return (result == '0' && (1 / value) == -INFINITY$1) ? '-0' : result;
+ }
+
+ /**
+ * The base implementation of `_.slice` without an iteratee call guard.
+ *
+ * @private
+ * @param {Array} array The array to slice.
+ * @param {number} [start=0] The start position.
+ * @param {number} [end=array.length] The end position.
+ * @returns {Array} Returns the slice of `array`.
+ */
+ function baseSlice(array, start, end) {
+ var index = -1,
+ length = array.length;
- function taskComplete(taskName) {
- var taskListeners = listeners[taskName] || [];
- arrayEach(taskListeners, function (fn) {
- fn();
- });
- processQueue();
+ if (start < 0) {
+ start = -start > length ? 0 : (length + start);
+ }
+ end = end > length ? length : end;
+ if (end < 0) {
+ end += length;
}
+ length = start > end ? 0 : ((end - start) >>> 0);
+ start >>>= 0;
- function runTask(key, task) {
- if (hasError) return;
-
- var taskCallback = onlyOnce(rest(function (err, args) {
- runningTasks--;
- if (args.length <= 1) {
- args = args[0];
- }
- if (err) {
- var safeResults = {};
- baseForOwn(results, function (val, rkey) {
- safeResults[rkey] = val;
- });
- safeResults[key] = args;
- hasError = true;
- listeners = [];
-
- callback(err, safeResults);
- } else {
- results[key] = args;
- taskComplete(key);
- }
- }));
-
- runningTasks++;
- var taskFn = task[task.length - 1];
- if (task.length > 1) {
- taskFn(results, taskCallback);
- } else {
- taskFn(taskCallback);
- }
+ var result = Array(length);
+ while (++index < length) {
+ result[index] = array[index + start];
}
+ return result;
+ }
- function checkForDeadlocks() {
- // Kahn's algorithm
- // https://en.wikipedia.org/wiki/Topological_sorting#Kahn.27s_algorithm
- // http://connalle.blogspot.com/2013/10/topological-sortingkahn-algorithm.html
- var currentTask;
- var counter = 0;
- while (readyToCheck.length) {
- currentTask = readyToCheck.pop();
- counter++;
- arrayEach(getDependents(currentTask), function (dependent) {
- if (! --uncheckedDependencies[dependent]) {
- readyToCheck.push(dependent);
- }
- });
- }
+ /**
+ * Casts `array` to a slice if it's needed.
+ *
+ * @private
+ * @param {Array} array The array to inspect.
+ * @param {number} start The start position.
+ * @param {number} [end=array.length] The end position.
+ * @returns {Array} Returns the cast slice.
+ */
+ function castSlice(array, start, end) {
+ var length = array.length;
+ end = end === undefined ? length : end;
+ return (!start && end >= length) ? array : baseSlice(array, start, end);
+ }
- if (counter !== numTasks) {
- throw new Error('async.auto cannot execute tasks due to a recursive dependency');
- }
- }
+ /**
+ * Used by `_.trim` and `_.trimEnd` to get the index of the last string symbol
+ * that is not found in the character symbols.
+ *
+ * @private
+ * @param {Array} strSymbols The string symbols to inspect.
+ * @param {Array} chrSymbols The character symbols to find.
+ * @returns {number} Returns the index of the last unmatched string symbol.
+ */
+ function charsEndIndex(strSymbols, chrSymbols) {
+ var index = strSymbols.length;
+
+ while (index-- && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {}
+ return index;
+ }
+
+ /**
+ * Used by `_.trim` and `_.trimStart` to get the index of the first string symbol
+ * that is not found in the character symbols.
+ *
+ * @private
+ * @param {Array} strSymbols The string symbols to inspect.
+ * @param {Array} chrSymbols The character symbols to find.
+ * @returns {number} Returns the index of the first unmatched string symbol.
+ */
+ function charsStartIndex(strSymbols, chrSymbols) {
+ var index = -1,
+ length = strSymbols.length;
+
+ while (++index < length && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {}
+ return index;
+ }
- function getDependents(taskName) {
- var result = [];
- baseForOwn(tasks, function (task, key) {
- if (isArray(task) && baseIndexOf(task, taskName, 0) >= 0) {
- result.push(key);
- }
- });
- return result;
+ /** Used to compose unicode character classes. */
+ var rsAstralRange = '\\ud800-\\udfff';
+ var rsComboMarksRange = '\\u0300-\\u036f\\ufe20-\\ufe23';
+ var rsComboSymbolsRange = '\\u20d0-\\u20f0';
+ var rsVarRange = '\\ufe0e\\ufe0f';
+ var rsAstral = '[' + rsAstralRange + ']';
+ var rsCombo = '[' + rsComboMarksRange + rsComboSymbolsRange + ']';
+ var rsFitz = '\\ud83c[\\udffb-\\udfff]';
+ var rsModifier = '(?:' + rsCombo + '|' + rsFitz + ')';
+ var rsNonAstral = '[^' + rsAstralRange + ']';
+ var rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}';
+ var rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]';
+ var rsZWJ = '\\u200d';
+ var reOptMod = rsModifier + '?';
+ var rsOptVar = '[' + rsVarRange + ']?';
+ var rsOptJoin = '(?:' + rsZWJ + '(?:' + [rsNonAstral, rsRegional, rsSurrPair].join('|') + ')' + rsOptVar + reOptMod + ')*';
+ var rsSeq = rsOptVar + reOptMod + rsOptJoin;
+ var rsSymbol = '(?:' + [rsNonAstral + rsCombo + '?', rsCombo, rsRegional, rsSurrPair, rsAstral].join('|') + ')';
+ /** Used to match [string symbols](https://mathiasbynens.be/notes/javascript-unicode). */
+ var reComplexSymbol = RegExp(rsFitz + '(?=' + rsFitz + ')|' + rsSymbol + rsSeq, 'g');
+
+ /**
+ * Converts `string` to an array.
+ *
+ * @private
+ * @param {string} string The string to convert.
+ * @returns {Array} Returns the converted array.
+ */
+ function stringToArray(string) {
+ return string.match(reComplexSymbol);
+ }
+
+ /**
+ * Converts `value` to a string. An empty string is returned for `null`
+ * and `undefined` values. The sign of `-0` is preserved.
+ *
+ * @static
+ * @memberOf _
+ * @since 4.0.0
+ * @category Lang
+ * @param {*} value The value to process.
+ * @returns {string} Returns the string.
+ * @example
+ *
+ * _.toString(null);
+ * // => ''
+ *
+ * _.toString(-0);
+ * // => '-0'
+ *
+ * _.toString([1, 2, 3]);
+ * // => '1,2,3'
+ */
+ function toString(value) {
+ return value == null ? '' : baseToString(value);
+ }
+
+ /** Used to match leading and trailing whitespace. */
+ var reTrim$1 = /^\s+|\s+$/g;
+
+ /**
+ * Removes leading and trailing whitespace or specified characters from `string`.
+ *
+ * @static
+ * @memberOf _
+ * @since 3.0.0
+ * @category String
+ * @param {string} [string=''] The string to trim.
+ * @param {string} [chars=whitespace] The characters to trim.
+ * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
+ * @returns {string} Returns the trimmed string.
+ * @example
+ *
+ * _.trim(' abc ');
+ * // => 'abc'
+ *
+ * _.trim('-_-abc-_-', '_-');
+ * // => 'abc'
+ *
+ * _.map([' foo ', ' bar '], _.trim);
+ * // => ['foo', 'bar']
+ */
+ function trim(string, chars, guard) {
+ string = toString(string);
+ if (string && (guard || chars === undefined)) {
+ return string.replace(reTrim$1, '');
+ }
+ if (!string || !(chars = baseToString(chars))) {
+ return string;
}
- }
-
- /**
- * A specialized version of `_.map` for arrays without support for iteratee
- * shorthands.
- *
- * @private
- * @param {Array} [array] The array to iterate over.
- * @param {Function} iteratee The function invoked per iteration.
- * @returns {Array} Returns the new mapped array.
- */
- function arrayMap(array, iteratee) {
- var index = -1,
- length = array ? array.length : 0,
- result = Array(length);
-
- while (++index < length) {
- result[index] = iteratee(array[index], index, array);
+ var strSymbols = stringToArray(string),
+ chrSymbols = stringToArray(chars),
+ start = charsStartIndex(strSymbols, chrSymbols),
+ end = charsEndIndex(strSymbols, chrSymbols) + 1;
+
+ return castSlice(strSymbols, start, end).join('');
+ }
+
+ var FN_ARGS = /^(function)?\s*[^\(]*\(\s*([^\)]*)\)/m;
+ var FN_ARG_SPLIT = /,/;
+ var FN_ARG = /(=.+)?(\s*)$/;
+ var STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg;
+
+ function parseParams(func) {
+ func = func.toString().replace(STRIP_COMMENTS, '');
+ func = func.match(FN_ARGS)[2].replace(' ', '');
+ func = func ? func.split(FN_ARG_SPLIT) : [];
+ func = func.map(function (arg) {
+ return trim(arg.replace(FN_ARG, ''));
+ });
+ return func;
+ }
+
+ /**
+ * A dependency-injected version of the [async.auto]{@link module:ControlFlow.auto} function. Dependent
+ * tasks are specified as parameters to the function, after the usual callback
+ * parameter, with the parameter names matching the names of the tasks it
+ * depends on. This can provide even more readable task graphs which can be
+ * easier to maintain.
+ *
+ * If a final callback is specified, the task results are similarly injected,
+ * specified as named parameters after the initial error parameter.
+ *
+ * The autoInject function is purely syntactic sugar and its semantics are
+ * otherwise equivalent to [async.auto]{@link module:ControlFlow.auto}.
+ *
+ * @name autoInject
+ * @static
+ * @memberOf module:ControlFlow
+ * @method
+ * @see [async.auto]{@link module:ControlFlow.auto}
+ * @category Control Flow
+ * @param {Object} tasks - An object, each of whose properties is a function of
+ * the form 'func([dependencies...], callback). The object's key of a property
+ * serves as the name of the task defined by that property, i.e. can be used
+ * when specifying requirements for other tasks.
+ * * The `callback` parameter is a `callback(err, result)` which must be called
+ * when finished, passing an `error` (which can be `null`) and the result of
+ * the function's execution. The remaining parameters name other tasks on
+ * which the task is dependent, and the results from those tasks are the
+ * arguments of those parameters.
+ * @param {Function} [callback] - An optional callback which is called when all
+ * the tasks have been completed. It receives the `err` argument if any `tasks`
+ * pass an error to their callback, and a `results` object with any completed
+ * task results, similar to `auto`.
+ * @example
+ *
+ * // The example from `auto` can be rewritten as follows:
+ * async.autoInject({
+ * get_data: function(callback) {
+ * // async code to get some data
+ * callback(null, 'data', 'converted to array');
+ * },
+ * make_folder: function(callback) {
+ * // async code to create a directory to store a file in
+ * // this is run at the same time as getting the data
+ * callback(null, 'folder');
+ * },
+ * write_file: function(get_data, make_folder, callback) {
+ * // once there is some data and the directory exists,
+ * // write the data to a file in the directory
+ * callback(null, 'filename');
+ * },
+ * email_link: function(write_file, callback) {
+ * // once the file is written let's email a link to it...
+ * // write_file contains the filename returned by write_file.
+ * callback(null, {'file':write_file, 'email':'user@example.com'});
+ * }
+ * }, function(err, results) {
+ * console.log('err = ', err);
+ * console.log('email_link = ', results.email_link);
+ * });
+ *
+ * // If you are using a JS minifier that mangles parameter names, `autoInject`
+ * // will not work with plain functions, since the parameter names will be
+ * // collapsed to a single letter identifier. To work around this, you can
+ * // explicitly specify the names of the parameters your task function needs
+ * // in an array, similar to Angular.js dependency injection.
+ *
+ * // This still has an advantage over plain `auto`, since the results a task
+ * // depends on are still spread into arguments.
+ * async.autoInject({
+ * //...
+ * write_file: ['get_data', 'make_folder', function(get_data, make_folder, callback) {
+ * callback(null, 'filename');
+ * }],
+ * email_link: ['write_file', function(write_file, callback) {
+ * callback(null, {'file':write_file, 'email':'user@example.com'});
+ * }]
+ * //...
+ * }, function(err, results) {
+ * console.log('err = ', err);
+ * console.log('email_link = ', results.email_link);
+ * });
+ */
+ function autoInject(tasks, callback) {
+ var newTasks = {};
+
+ baseForOwn(tasks, function (taskFn, key) {
+ var params;
+
+ if (isArray(taskFn)) {
+ params = copyArray(taskFn);
+ taskFn = params.pop();
+
+ newTasks[key] = params.concat(params.length > 0 ? newTask : taskFn);
+ } else if (taskFn.length === 1) {
+ // no dependencies, use the function as-is
+ newTasks[key] = taskFn;
+ } else {
+ params = parseParams(taskFn);
+ if (taskFn.length === 0 && params.length === 0) {
+ throw new Error("autoInject task functions require explicit parameters.");
+ }
+
+ params.pop();
+
+ newTasks[key] = params.concat(newTask);
+ }
+
+ function newTask(results, taskCb) {
+ var newArgs = arrayMap(params, function (name) {
+ return results[name];
+ });
+ newArgs.push(taskCb);
+ taskFn.apply(null, newArgs);
+ }
+ });
+
+ auto(newTasks, callback);
+ }
+
+ var hasSetImmediate = typeof setImmediate === 'function' && setImmediate;
+ var hasNextTick = typeof process === 'object' && typeof process.nextTick === 'function';
+
+ function fallback(fn) {
+ setTimeout(fn, 0);
+ }
+
+ function wrap(defer) {
+ return rest(function (fn, args) {
+ defer(function () {
+ fn.apply(null, args);
+ });
+ });
+ }
+
+ var _defer;
+
+ if (hasSetImmediate) {
+ _defer = setImmediate;
+ } else if (hasNextTick) {
+ _defer = process.nextTick;
+ } else {
+ _defer = fallback;
+ }
+
+ var setImmediate$1 = wrap(_defer);
+
+ // Simple doubly linked list (https://en.wikipedia.org/wiki/Doubly_linked_list) implementation
+ // used for queues. This implementation assumes that the node provided by the user can be modified
+ // to adjust the next and last properties. We implement only the minimal functionality
+ // for queue support.
+ function DLL() {
+ this.head = this.tail = null;
+ this.length = 0;
+ }
+
+ function setInitial(dll, node) {
+ dll.length = 1;
+ dll.head = dll.tail = node;
+ }
+
+ DLL.prototype.removeLink = function (node) {
+ if (node.prev) node.prev.next = node.next;else this.head = node.next;
+ if (node.next) node.next.prev = node.prev;else this.tail = node.prev;
+
+ node.prev = node.next = null;
+ this.length -= 1;
+ return node;
+ };
+
+ DLL.prototype.empty = DLL;
+
+ DLL.prototype.insertAfter = function (node, newNode) {
+ newNode.prev = node;
+ newNode.next = node.next;
+ if (node.next) node.next.prev = newNode;else this.tail = newNode;
+ node.next = newNode;
+ this.length += 1;
+ };
+
+ DLL.prototype.insertBefore = function (node, newNode) {
+ newNode.prev = node.prev;
+ newNode.next = node;
+ if (node.prev) node.prev.next = newNode;else this.head = newNode;
+ node.prev = newNode;
+ this.length += 1;
+ };
+
+ DLL.prototype.unshift = function (node) {
+ if (this.head) this.insertBefore(this.head, node);else setInitial(this, node);
+ };
+
+ DLL.prototype.push = function (node) {
+ if (this.tail) this.insertAfter(this.tail, node);else setInitial(this, node);
+ };
+
+ DLL.prototype.shift = function () {
+ return this.head && this.removeLink(this.head);
+ };
+
+ DLL.prototype.pop = function () {
+ return this.tail && this.removeLink(this.tail);
+ };
+
+ function queue(worker, concurrency, payload) {
+ if (concurrency == null) {
+ concurrency = 1;
+ } else if (concurrency === 0) {
+ throw new Error('Concurrency must not be zero');
+ }
+
+ function _insert(data, insertAtFront, callback) {
+ if (callback != null && typeof callback !== 'function') {
+ throw new Error('task callback must be a function');
+ }
+ q.started = true;
+ if (!isArray(data)) {
+ data = [data];
+ }
+ if (data.length === 0 && q.idle()) {
+ // call drain immediately if there are no tasks
+ return setImmediate$1(function () {
+ q.drain();
+ });
+ }
+ arrayEach(data, function (task) {
+ var item = {
+ data: task,
+ callback: callback || noop
+ };
+
+ if (insertAtFront) {
+ q._tasks.unshift(item);
+ } else {
+ q._tasks.push(item);
+ }
+ });
+ setImmediate$1(q.process);
+ }
+
+ function _next(tasks) {
+ return rest(function (args) {
+ workers -= 1;
+
+ arrayEach(tasks, function (task) {
+ arrayEach(workersList, function (worker, index) {
+ if (worker === task) {
+ workersList.splice(index, 1);
+ return false;
+ }
+ });
+
+ task.callback.apply(task, args);
+
+ if (args[0] != null) {
+ q.error(args[0], task.data);
+ }
+ });
+
+ if (workers <= q.concurrency - q.buffer) {
+ q.unsaturated();
+ }
+
+ if (q.idle()) {
+ q.drain();
+ }
+ q.process();
+ });
+ }
+
+ var workers = 0;
+ var workersList = [];
+ var q = {
+ _tasks: new DLL(),
+ concurrency: concurrency,
+ payload: payload,
+ saturated: noop,
+ unsaturated: noop,
+ buffer: concurrency / 4,
+ empty: noop,
+ drain: noop,
+ error: noop,
+ started: false,
+ paused: false,
+ push: function (data, callback) {
+ _insert(data, false, callback);
+ },
+ kill: function () {
+ q.drain = noop;
+ q._tasks.empty();
+ },
+ unshift: function (data, callback) {
+ _insert(data, true, callback);
+ },
+ process: function () {
+ while (!q.paused && workers < q.concurrency && q._tasks.length) {
+ var tasks = [],
+ data = [];
+ var l = q._tasks.length;
+ if (q.payload) l = Math.min(l, q.payload);
+ for (var i = 0; i < l; i++) {
+ var node = q._tasks.shift();
+ tasks.push(node);
+ data.push(node.data);
+ }
+
+ if (q._tasks.length === 0) {
+ q.empty();
+ }
+ workers += 1;
+ workersList.push(tasks[0]);
+
+ if (workers === q.concurrency) {
+ q.saturated();
+ }
+
+ var cb = onlyOnce(_next(tasks));
+ worker(data, cb);
+ }
+ },
+ length: function () {
+ return q._tasks.length;
+ },
+ running: function () {
+ return workers;
+ },
+ workersList: function () {
+ return workersList;
+ },
+ idle: function () {
+ return q._tasks.length + workers === 0;
+ },
+ pause: function () {
+ q.paused = true;
+ },
+ resume: function () {
+ if (q.paused === false) {
+ return;
+ }
+ q.paused = false;
+ var resumeCount = Math.min(q.concurrency, q._tasks.length);
+ // Need to call q.process once per concurrent
+ // worker to preserve full concurrency after pause
+ for (var w = 1; w <= resumeCount; w++) {
+ setImmediate$1(q.process);
+ }
+ }
+ };
+ return q;
+ }
+
+ /**
+ * A cargo of tasks for the worker function to complete. Cargo inherits all of
+ * the same methods and event callbacks as [`queue`]{@link module:ControlFlow.queue}.
+ * @typedef {Object} CargoObject
+ * @memberOf module:ControlFlow
+ * @property {Function} length - A function returning the number of items
+ * waiting to be processed. Invoke like `cargo.length()`.
+ * @property {number} payload - An `integer` for determining how many tasks
+ * should be process per round. This property can be changed after a `cargo` is
+ * created to alter the payload on-the-fly.
+ * @property {Function} push - Adds `task` to the `queue`. The callback is
+ * called once the `worker` has finished processing the task. Instead of a
+ * single task, an array of `tasks` can be submitted. The respective callback is
+ * used for every task in the list. Invoke like `cargo.push(task, [callback])`.
+ * @property {Function} saturated - A callback that is called when the
+ * `queue.length()` hits the concurrency and further tasks will be queued.
+ * @property {Function} empty - A callback that is called when the last item
+ * from the `queue` is given to a `worker`.
+ * @property {Function} drain - A callback that is called when the last item
+ * from the `queue` has returned from the `worker`.
+ * @property {Function} idle - a function returning false if there are items
+ * waiting or being processed, or true if not. Invoke like `cargo.idle()`.
+ * @property {Function} pause - a function that pauses the processing of tasks
+ * until `resume()` is called. Invoke like `cargo.pause()`.
+ * @property {Function} resume - a function that resumes the processing of
+ * queued tasks when the queue is paused. Invoke like `cargo.resume()`.
+ * @property {Function} kill - a function that removes the `drain` callback and
+ * empties remaining tasks from the queue forcing it to go idle. Invoke like `cargo.kill()`.
+ */
+
+ /**
+ * Creates a `cargo` object with the specified payload. Tasks added to the
+ * cargo will be processed altogether (up to the `payload` limit). If the
+ * `worker` is in progress, the task is queued until it becomes available. Once
+ * the `worker` has completed some tasks, each callback of those tasks is
+ * called. Check out [these](https://camo.githubusercontent.com/6bbd36f4cf5b35a0f11a96dcd2e97711ffc2fb37/68747470733a2f2f662e636c6f75642e6769746875622e636f6d2f6173736574732f313637363837312f36383130382f62626330636662302d356632392d313165322d393734662d3333393763363464633835382e676966) [animations](https://camo.githubusercontent.com/f4810e00e1c5f5f8addbe3e9f49064fd5d102699/68747470733a2f2f662e636c6f75642e6769746875622e636f6d2f6173736574732f313637363837312f36383130312f38346339323036362d356632392d313165322d383134662d3964336430323431336266642e676966)
+ * for how `cargo` and `queue` work.
+ *
+ * While [`queue`]{@link module:ControlFlow.queue} passes only one task to one of a group of workers
+ * at a time, cargo passes an array of tasks to a single worker, repeating
+ * when the worker is finished.
+ *
+ * @name cargo
+ * @static
+ * @memberOf module:ControlFlow
+ * @method
+ * @see [async.queue]{@link module:ControlFlow.queue}
+ * @category Control Flow
+ * @param {Function} worker - An asynchronous function for processing an array
+ * of queued tasks, which must call its `callback(err)` argument when finished,
+ * with an optional `err` argument. Invoked with `(tasks, callback)`.
+ * @param {number} [payload=Infinity] - An optional `integer` for determining
+ * how many tasks should be processed per round; if omitted, the default is
+ * unlimited.
+ * @returns {module:ControlFlow.CargoObject} A cargo object to manage the tasks. Callbacks can
+ * attached as certain properties to listen for specific events during the
+ * lifecycle of the cargo and inner queue.
+ * @example
+ *
+ * // create a cargo object with payload 2
+ * var cargo = async.cargo(function(tasks, callback) {
+ * for (var i=0; i<tasks.length; i++) {
+ * console.log('hello ' + tasks[i].name);
+ * }
+ * callback();
+ * }, 2);
+ *
+ * // add some items
+ * cargo.push({name: 'foo'}, function(err) {
+ * console.log('finished processing foo');
+ * });
+ * cargo.push({name: 'bar'}, function(err) {
+ * console.log('finished processing bar');
+ * });
+ * cargo.push({name: 'baz'}, function(err) {
+ * console.log('finished processing baz');
+ * });
+ */
+ function cargo(worker, payload) {
+ return queue(worker, 1, payload);
+ }
+
+ /**
+ * The same as [`eachOf`]{@link module:Collections.eachOf} but runs only a single async operation at a time.
+ *
+ * @name eachOfSeries
+ * @static
+ * @memberOf module:Collections
+ * @method
+ * @see [async.eachOf]{@link module:Collections.eachOf}
+ * @alias forEachOfSeries
+ * @category Collection
+ * @param {Array|Iterable|Object} coll - A collection to iterate over.
+ * @param {Function} iteratee - A function to apply to each item in `coll`. The
+ * `key` is the item's key, or index in the case of an array. The iteratee is
+ * passed a `callback(err)` which must be called once it has completed. If no
+ * error has occurred, the callback should be run without arguments or with an
+ * explicit `null` argument. Invoked with (item, key, callback).
+ * @param {Function} [callback] - A callback which is called when all `iteratee`
+ * functions have finished, or an error occurs. Invoked with (err).
+ */
+ var eachOfSeries = doLimit(eachOfLimit, 1);
+
+ /**
+ * Reduces `coll` into a single value using an async `iteratee` to return each
+ * successive step. `memo` is the initial state of the reduction. This function
+ * only operates in series.
+ *
+ * For performance reasons, it may make sense to split a call to this function
+ * into a parallel map, and then use the normal `Array.prototype.reduce` on the
+ * results. This function is for situations where each step in the reduction
+ * needs to be async; if you can get the data before reducing it, then it's
+ * probably a good idea to do so.
+ *
+ * @name reduce
+ * @static
+ * @memberOf module:Collections
+ * @method
+ * @alias inject
+ * @alias foldl
+ * @category Collection
+ * @param {Array|Iterable|Object} coll - A collection to iterate over.
+ * @param {*} memo - The initial state of the reduction.
+ * @param {Function} iteratee - A function applied to each item in the
+ * array to produce the next step in the reduction. The `iteratee` is passed a
+ * `callback(err, reduction)` which accepts an optional error as its first
+ * argument, and the state of the reduction as the second. If an error is
+ * passed to the callback, the reduction is stopped and the main `callback` is
+ * immediately called with the error. Invoked with (memo, item, callback).
+ * @param {Function} [callback] - A callback which is called after all the
+ * `iteratee` functions have finished. Result is the reduced value. Invoked with
+ * (err, result).
+ * @example
+ *
+ * async.reduce([1,2,3], 0, function(memo, item, callback) {
+ * // pointless async:
+ * process.nextTick(function() {
+ * callback(null, memo + item)
+ * });
+ * }, function(err, result) {
+ * // result is now equal to the last value of memo, which is 6
+ * });
+ */
+ function reduce(coll, memo, iteratee, callback) {
+ callback = once(callback || noop);
+ eachOfSeries(coll, function (x, i, callback) {
+ iteratee(memo, x, function (err, v) {
+ memo = v;
+ callback(err);
+ });
+ }, function (err) {
+ callback(err, memo);
+ });
+ }
+
+ /**
+ * Version of the compose function that is more natural to read. Each function
+ * consumes the return value of the previous function. It is the equivalent of
+ * [compose]{@link module:ControlFlow.compose} with the arguments reversed.
+ *
+ * Each function is executed with the `this` binding of the composed function.
+ *
+ * @name seq
+ * @static
+ * @memberOf module:ControlFlow
+ * @method
+ * @see [async.compose]{@link module:ControlFlow.compose}
+ * @category Control Flow
+ * @param {...Function} functions - the asynchronous functions to compose
+ * @returns {Function} a function that composes the `functions` in order
+ * @example
+ *
+ * // Requires lodash (or underscore), express3 and dresende's orm2.
+ * // Part of an app, that fetches cats of the logged user.
+ * // This example uses `seq` function to avoid overnesting and error
+ * // handling clutter.
+ * app.get('/cats', function(request, response) {
+ * var User = request.models.User;
+ * async.seq(
+ * _.bind(User.get, User), // 'User.get' has signature (id, callback(err, data))
+ * function(user, fn) {
+ * user.getCats(fn); // 'getCats' has signature (callback(err, data))
+ * }
+ * )(req.session.user_id, function (err, cats) {
+ * if (err) {
+ * console.error(err);
+ * response.json({ status: 'error', message: err.message });
+ * } else {
+ * response.json({ status: 'ok', message: 'Cats found', data: cats });
+ * }
+ * });
+ * });
+ */
+ var seq = rest(function seq(functions) {
+ return rest(function (args) {
+ var that = this;
+
+ var cb = args[args.length - 1];
+ if (typeof cb == 'function') {
+ args.pop();
+ } else {
+ cb = noop;
+ }
+
+ reduce(functions, args, function (newargs, fn, cb) {
+ fn.apply(that, newargs.concat([rest(function (err, nextargs) {
+ cb(err, nextargs);
+ })]));
+ }, function (err, results) {
+ cb.apply(that, [err].concat(results));
+ });
+ });
+ });
+
+ /**
+ * Creates a function which is a composition of the passed asynchronous
+ * functions. Each function consumes the return value of the function that
+ * follows. Composing functions `f()`, `g()`, and `h()` would produce the result
+ * of `f(g(h()))`, only this version uses callbacks to obtain the return values.
+ *
+ * Each function is executed with the `this` binding of the composed function.
+ *
+ * @name compose
+ * @static
+ * @memberOf module:ControlFlow
+ * @method
+ * @category Control Flow
+ * @param {...Function} functions - the asynchronous functions to compose
+ * @returns {Function} an asynchronous function that is the composed
+ * asynchronous `functions`
+ * @example
+ *
+ * function add1(n, callback) {
+ * setTimeout(function () {
+ * callback(null, n + 1);
+ * }, 10);
+ * }
+ *
+ * function mul3(n, callback) {
+ * setTimeout(function () {
+ * callback(null, n * 3);
+ * }, 10);
+ * }
+ *
+ * var add1mul3 = async.compose(mul3, add1);
+ * add1mul3(4, function (err, result) {
+ * // result now equals 15
+ * });
+ */
+ var compose = rest(function (args) {
+ return seq.apply(null, args.reverse());
+ });
+
+ function concat$1(eachfn, arr, fn, callback) {
+ var result = [];
+ eachfn(arr, function (x, index, cb) {
+ fn(x, function (err, y) {
+ result = result.concat(y || []);
+ cb(err);
+ });
+ }, function (err) {
+ callback(err, result);
+ });
}
- return result;
- }
-
- /**
- * Copies the values of `source` to `array`.
- *
- * @private
- * @param {Array} source The array to copy values from.
- * @param {Array} [array=[]] The array to copy values to.
- * @returns {Array} Returns `array`.
- */
- function copyArray(source, array) {
- var index = -1,
- length = source.length;
-
- array || (array = Array(length));
- while (++index < length) {
- array[index] = source[index];
+
+ /**
+ * Applies `iteratee` to each item in `coll`, concatenating the results. Returns
+ * the concatenated list. The `iteratee`s are called in parallel, and the
+ * results are concatenated as they return. There is no guarantee that the
+ * results array will be returned in the original order of `coll` passed to the
+ * `iteratee` function.
+ *
+ * @name concat
+ * @static
+ * @memberOf module:Collections
+ * @method
+ * @category Collection
+ * @param {Array|Iterable|Object} coll - A collection to iterate over.
+ * @param {Function} iteratee - A function to apply to each item in `coll`.
+ * The iteratee is passed a `callback(err, results)` which must be called once
+ * it has completed with an error (which can be `null`) and an array of results.
+ * Invoked with (item, callback).
+ * @param {Function} [callback(err)] - A callback which is called after all the
+ * `iteratee` functions have finished, or an error occurs. Results is an array
+ * containing the concatenated results of the `iteratee` function. Invoked with
+ * (err, results).
+ * @example
+ *
+ * async.concat(['dir1','dir2','dir3'], fs.readdir, function(err, files) {
+ * // files is now a list of filenames that exist in the 3 directories
+ * });
+ */
+ var concat = doParallel(concat$1);
+
+ function doSeries(fn) {
+ return function (obj, iteratee, callback) {
+ return fn(eachOfSeries, obj, iteratee, callback);
+ };
}
- return array;
- }
-
- /**
- * Checks if `value` is a global object.
- *
- * @private
- * @param {*} value The value to check.
- * @returns {null|Object} Returns `value` if it's a global object, else `null`.
- */
- function checkGlobal(value) {
- return (value && value.Object === Object) ? value : null;
- }
-
- /** Detect free variable `global` from Node.js. */
- var freeGlobal = checkGlobal(typeof global == 'object' && global);
-
- /** Detect free variable `self`. */
- var freeSelf = checkGlobal(typeof self == 'object' && self);
-
- /** Detect `this` as the global object. */
- var thisGlobal = checkGlobal(typeof this == 'object' && this);
-
- /** Used as a reference to the global object. */
- var root = freeGlobal || freeSelf || thisGlobal || Function('return this')();
-
- /** Built-in value references. */
- var Symbol$1 = root.Symbol;
-
- /** Used as references for various `Number` constants. */
- var INFINITY$1 = 1 / 0;
-
- /** Used to convert symbols to primitives and strings. */
- var symbolProto = Symbol$1 ? Symbol$1.prototype : undefined;
- var symbolToString = symbolProto ? symbolProto.toString : undefined;
- /**
- * The base implementation of `_.toString` which doesn't convert nullish
- * values to empty strings.
- *
- * @private
- * @param {*} value The value to process.
- * @returns {string} Returns the string.
- */
- function baseToString(value) {
- // Exit early for strings to avoid a performance hit in some environments.
- if (typeof value == 'string') {
+
+ /**
+ * The same as [`concat`]{@link module:Collections.concat} but runs only a single async operation at a time.
+ *
+ * @name concatSeries
+ * @static
+ * @memberOf module:Collections
+ * @method
+ * @see [async.concat]{@link module:Collections.concat}
+ * @category Collection
+ * @param {Array|Iterable|Object} coll - A collection to iterate over.
+ * @param {Function} iteratee - A function to apply to each item in `coll`.
+ * The iteratee is passed a `callback(err, results)` which must be called once
+ * it has completed with an error (which can be `null`) and an array of results.
+ * Invoked with (item, callback).
+ * @param {Function} [callback(err)] - A callback which is called after all the
+ * `iteratee` functions have finished, or an error occurs. Results is an array
+ * containing the concatenated results of the `iteratee` function. Invoked with
+ * (err, results).
+ */
+ var concatSeries = doSeries(concat$1);
+
+ /**
+ * Returns a function that when called, calls-back with the values provided.
+ * Useful as the first function in a [`waterfall`]{@link module:ControlFlow.waterfall}, or for plugging values in to
+ * [`auto`]{@link module:ControlFlow.auto}.
+ *
+ * @name constant
+ * @static
+ * @memberOf module:Utils
+ * @method
+ * @category Util
+ * @param {...*} arguments... - Any number of arguments to automatically invoke
+ * callback with.
+ * @returns {Function} Returns a function that when invoked, automatically
+ * invokes the callback with the previous given arguments.
+ * @example
+ *
+ * async.waterfall([
+ * async.constant(42),
+ * function (value, next) {
+ * // value === 42
+ * },
+ * //...
+ * ], callback);
+ *
+ * async.waterfall([
+ * async.constant(filename, "utf8"),
+ * fs.readFile,
+ * function (fileData, next) {
+ * //...
+ * }
+ * //...
+ * ], callback);
+ *
+ * async.auto({
+ * hostname: async.constant("https://server.net/"),
+ * port: findFreePort,
+ * launchServer: ["hostname", "port", function (options, cb) {
+ * startServer(options, cb);
+ * }],
+ * //...
+ * }, callback);
+ */
+ var constant = rest(function (values) {
+ var args = [null].concat(values);
+ return initialParams(function (ignoredArgs, callback) {
+ return callback.apply(this, args);
+ });
+ });
+
+ /**
+ * This method returns the first argument given to it.
+ *
+ * @static
+ * @since 0.1.0
+ * @memberOf _
+ * @category Util
+ * @param {*} value Any value.
+ * @returns {*} Returns `value`.
+ * @example
+ *
+ * var object = { 'user': 'fred' };
+ *
+ * console.log(_.identity(object) === object);
+ * // => true
+ */
+ function identity(value) {
return value;
}
- if (isSymbol(value)) {
- return symbolToString ? symbolToString.call(value) : '';
+
+ function _createTester(eachfn, check, getResult) {
+ return function (arr, limit, iteratee, cb) {
+ function done(err) {
+ if (cb) {
+ if (err) {
+ cb(err);
+ } else {
+ cb(null, getResult(false));
+ }
+ }
+ }
+ function wrappedIteratee(x, _, callback) {
+ if (!cb) return callback();
+ iteratee(x, function (err, v) {
+ if (cb) {
+ if (err) {
+ cb(err);
+ cb = iteratee = false;
+ } else if (check(v)) {
+ cb(null, getResult(true, x));
+ cb = iteratee = false;
+ }
+ }
+ callback();
+ });
+ }
+ if (arguments.length > 3) {
+ cb = cb || noop;
+ eachfn(arr, limit, wrappedIteratee, done);
+ } else {
+ cb = iteratee;
+ cb = cb || noop;
+ iteratee = limit;
+ eachfn(arr, wrappedIteratee, done);
+ }
+ };
}
- var result = (value + '');
- return (result == '0' && (1 / value) == -INFINITY$1) ? '-0' : result;
- }
-
- /**
- * The base implementation of `_.slice` without an iteratee call guard.
- *
- * @private
- * @param {Array} array The array to slice.
- * @param {number} [start=0] The start position.
- * @param {number} [end=array.length] The end position.
- * @returns {Array} Returns the slice of `array`.
- */
- function baseSlice(array, start, end) {
- var index = -1,
- length = array.length;
-
- if (start < 0) {
- start = -start > length ? 0 : (length + start);
+
+ function _findGetResult(v, x) {
+ return x;
}
- end = end > length ? length : end;
- if (end < 0) {
- end += length;
+
+ /**
+ * Returns the first value in `coll` that passes an async truth test. The
+ * `iteratee` is applied in parallel, meaning the first iteratee to return
+ * `true` will fire the detect `callback` with that result. That means the
+ * result might not be the first item in the original `coll` (in terms of order)
+ * that passes the test.
+
+ * If order within the original `coll` is important, then look at
+ * [`detectSeries`]{@link module:Collections.detectSeries}.
+ *
+ * @name detect
+ * @static
+ * @memberOf module:Collections
+ * @method
+ * @alias find
+ * @category Collections
+ * @param {Array|Iterable|Object} coll - A collection to iterate over.
+ * @param {Function} iteratee - A truth test to apply to each item in `coll`.
+ * The iteratee is passed a `callback(err, truthValue)` which must be called
+ * with a boolean argument once it has completed. Invoked with (item, callback).
+ * @param {Function} [callback] - A callback which is called as soon as any
+ * iteratee returns `true`, or after all the `iteratee` functions have finished.
+ * Result will be the first item in the array that passes the truth test
+ * (iteratee) or the value `undefined` if none passed. Invoked with
+ * (err, result).
+ * @example
+ *
+ * async.detect(['file1','file2','file3'], function(filePath, callback) {
+ * fs.access(filePath, function(err) {
+ * callback(null, !err)
+ * });
+ * }, function(err, result) {
+ * // result now equals the first file in the list that exists
+ * });
+ */
+ var detect = _createTester(eachOf, identity, _findGetResult);
+
+ /**
+ * The same as [`detect`]{@link module:Collections.detect} but runs a maximum of `limit` async operations at a
+ * time.
+ *
+ * @name detectLimit
+ * @static
+ * @memberOf module:Collections
+ * @method
+ * @see [async.detect]{@link module:Collections.detect}
+ * @alias findLimit
+ * @category Collections
+ * @param {Array|Iterable|Object} coll - A collection to iterate over.
+ * @param {number} limit - The maximum number of async operations at a time.
+ * @param {Function} iteratee - A truth test to apply to each item in `coll`.
+ * The iteratee is passed a `callback(err, truthValue)` which must be called
+ * with a boolean argument once it has completed. Invoked with (item, callback).
+ * @param {Function} [callback] - A callback which is called as soon as any
+ * iteratee returns `true`, or after all the `iteratee` functions have finished.
+ * Result will be the first item in the array that passes the truth test
+ * (iteratee) or the value `undefined` if none passed. Invoked with
+ * (err, result).
+ */
+ var detectLimit = _createTester(eachOfLimit, identity, _findGetResult);
+
+ /**
+ * The same as [`detect`]{@link module:Collections.detect} but runs only a single async operation at a time.
+ *
+ * @name detectSeries
+ * @static
+ * @memberOf module:Collections
+ * @method
+ * @see [async.detect]{@link module:Collections.detect}
+ * @alias findSeries
+ * @category Collections
+ * @param {Array|Iterable|Object} coll - A collection to iterate over.
+ * @param {Function} iteratee - A truth test to apply to each item in `coll`.
+ * The iteratee is passed a `callback(err, truthValue)` which must be called
+ * with a boolean argument once it has completed. Invoked with (item, callback).
+ * @param {Function} [callback] - A callback which is called as soon as any
+ * iteratee returns `true`, or after all the `iteratee` functions have finished.
+ * Result will be the first item in the array that passes the truth test
+ * (iteratee) or the value `undefined` if none passed. Invoked with
+ * (err, result).
+ */
+ var detectSeries = _createTester(eachOfSeries, identity, _findGetResult);
+
+ function consoleFunc(name) {
+ return rest(function (fn, args) {
+ fn.apply(null, args.concat([rest(function (err, args) {
+ if (typeof console === 'object') {
+ if (err) {
+ if (console.error) {
+ console.error(err);
+ }
+ } else if (console[name]) {
+ arrayEach(args, function (x) {
+ console[name](x);
+ });
+ }
+ }
+ })]));
+ });
}
- length = start > end ? 0 : ((end - start) >>> 0);
- start >>>= 0;
- var result = Array(length);
- while (++index < length) {
- result[index] = array[index + start];
+ /**
+ * Logs the result of an `async` function to the `console` using `console.dir`
+ * to display the properties of the resulting object. Only works in Node.js or
+ * in browsers that support `console.dir` and `console.error` (such as FF and
+ * Chrome). If multiple arguments are returned from the async function,
+ * `console.dir` is called on each argument in order.
+ *
+ * @name dir
+ * @static
+ * @memberOf module:Utils
+ * @method
+ * @category Util
+ * @param {Function} function - The function you want to eventually apply all
+ * arguments to.
+ * @param {...*} arguments... - Any number of arguments to apply to the function.
+ * @example
+ *
+ * // in a module
+ * var hello = function(name, callback) {
+ * setTimeout(function() {
+ * callback(null, {hello: name});
+ * }, 1000);
+ * };
+ *
+ * // in the node repl
+ * node> async.dir(hello, 'world');
+ * {hello: 'world'}
+ */
+ var dir = consoleFunc('dir');
+
+ /**
+ * The post-check version of [`during`]{@link module:ControlFlow.during}. To reflect the difference in
+ * the order of operations, the arguments `test` and `fn` are switched.
+ *
+ * Also a version of [`doWhilst`]{@link module:ControlFlow.doWhilst} with asynchronous `test` function.
+ * @name doDuring
+ * @static
+ * @memberOf module:ControlFlow
+ * @method
+ * @see [async.during]{@link module:ControlFlow.during}
+ * @category Control Flow
+ * @param {Function} fn - A function which is called each time `test` passes.
+ * The function is passed a `callback(err)`, which must be called once it has
+ * completed with an optional `err` argument. Invoked with (callback).
+ * @param {Function} test - asynchronous truth test to perform before each
+ * execution of `fn`. Invoked with (...args, callback), where `...args` are the
+ * non-error args from the previous callback of `fn`.
+ * @param {Function} [callback] - A callback which is called after the test
+ * function has failed and repeated execution of `fn` has stopped. `callback`
+ * will be passed an error if one occured, otherwise `null`.
+ */
+ function doDuring(fn, test, callback) {
+ callback = onlyOnce(callback || noop);
+
+ var next = rest(function (err, args) {
+ if (err) return callback(err);
+ args.push(check);
+ test.apply(this, args);
+ });
+
+ function check(err, truth) {
+ if (err) return callback(err);
+ if (!truth) return callback(null);
+ fn(next);
+ }
+
+ check(null, true);
}
- return result;
- }
-
- /**
- * Casts `array` to a slice if it's needed.
- *
- * @private
- * @param {Array} array The array to inspect.
- * @param {number} start The start position.
- * @param {number} [end=array.length] The end position.
- * @returns {Array} Returns the cast slice.
- */
- function castSlice(array, start, end) {
- var length = array.length;
- end = end === undefined ? length : end;
- return (!start && end >= length) ? array : baseSlice(array, start, end);
- }
-
- /**
- * Used by `_.trim` and `_.trimEnd` to get the index of the last string symbol
- * that is not found in the character symbols.
- *
- * @private
- * @param {Array} strSymbols The string symbols to inspect.
- * @param {Array} chrSymbols The character symbols to find.
- * @returns {number} Returns the index of the last unmatched string symbol.
- */
- function charsEndIndex(strSymbols, chrSymbols) {
- var index = strSymbols.length;
-
- while (index-- && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {}
- return index;
- }
-
- /**
- * Used by `_.trim` and `_.trimStart` to get the index of the first string symbol
- * that is not found in the character symbols.
- *
- * @private
- * @param {Array} strSymbols The string symbols to inspect.
- * @param {Array} chrSymbols The character symbols to find.
- * @returns {number} Returns the index of the first unmatched string symbol.
- */
- function charsStartIndex(strSymbols, chrSymbols) {
- var index = -1,
- length = strSymbols.length;
-
- while (++index < length && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {}
- return index;
- }
-
- /** Used to compose unicode character classes. */
- var rsAstralRange = '\\ud800-\\udfff';
- var rsComboMarksRange = '\\u0300-\\u036f\\ufe20-\\ufe23';
- var rsComboSymbolsRange = '\\u20d0-\\u20f0';
- var rsVarRange = '\\ufe0e\\ufe0f';
- var rsAstral = '[' + rsAstralRange + ']';
- var rsCombo = '[' + rsComboMarksRange + rsComboSymbolsRange + ']';
- var rsFitz = '\\ud83c[\\udffb-\\udfff]';
- var rsModifier = '(?:' + rsCombo + '|' + rsFitz + ')';
- var rsNonAstral = '[^' + rsAstralRange + ']';
- var rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}';
- var rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]';
- var rsZWJ = '\\u200d';
- var reOptMod = rsModifier + '?';
- var rsOptVar = '[' + rsVarRange + ']?';
- var rsOptJoin = '(?:' + rsZWJ + '(?:' + [rsNonAstral, rsRegional, rsSurrPair].join('|') + ')' + rsOptVar + reOptMod + ')*';
- var rsSeq = rsOptVar + reOptMod + rsOptJoin;
- var rsSymbol = '(?:' + [rsNonAstral + rsCombo + '?', rsCombo, rsRegional, rsSurrPair, rsAstral].join('|') + ')';
- /** Used to match [string symbols](https://mathiasbynens.be/notes/javascript-unicode). */
- var reComplexSymbol = RegExp(rsFitz + '(?=' + rsFitz + ')|' + rsSymbol + rsSeq, 'g');
-
- /**
- * Converts `string` to an array.
- *
- * @private
- * @param {string} string The string to convert.
- * @returns {Array} Returns the converted array.
- */
- function stringToArray(string) {
- return string.match(reComplexSymbol);
- }
-
- /**
- * Converts `value` to a string. An empty string is returned for `null`
- * and `undefined` values. The sign of `-0` is preserved.
- *
- * @static
- * @memberOf _
- * @since 4.0.0
- * @category Lang
- * @param {*} value The value to process.
- * @returns {string} Returns the string.
- * @example
- *
- * _.toString(null);
- * // => ''
- *
- * _.toString(-0);
- * // => '-0'
- *
- * _.toString([1, 2, 3]);
- * // => '1,2,3'
- */
- function toString(value) {
- return value == null ? '' : baseToString(value);
- }
-
- /** Used to match leading and trailing whitespace. */
- var reTrim$1 = /^\s+|\s+$/g;
-
- /**
- * Removes leading and trailing whitespace or specified characters from `string`.
- *
- * @static
- * @memberOf _
- * @since 3.0.0
- * @category String
- * @param {string} [string=''] The string to trim.
- * @param {string} [chars=whitespace] The characters to trim.
- * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
- * @returns {string} Returns the trimmed string.
- * @example
- *
- * _.trim(' abc ');
- * // => 'abc'
- *
- * _.trim('-_-abc-_-', '_-');
- * // => 'abc'
- *
- * _.map([' foo ', ' bar '], _.trim);
- * // => ['foo', 'bar']
- */
- function trim(string, chars, guard) {
- string = toString(string);
- if (string && (guard || chars === undefined)) {
- return string.replace(reTrim$1, '');
+
+ /**
+ * The post-check version of [`whilst`]{@link module:ControlFlow.whilst}. To reflect the difference in
+ * the order of operations, the arguments `test` and `iteratee` are switched.
+ *
+ * `doWhilst` is to `whilst` as `do while` is to `while` in plain JavaScript.
+ *
+ * @name doWhilst
+ * @static
+ * @memberOf module:ControlFlow
+ * @method
+ * @see [async.whilst]{@link module:ControlFlow.whilst}
+ * @category Control Flow
+ * @param {Function} iteratee - A function which is called each time `test`
+ * passes. The function is passed a `callback(err)`, which must be called once
+ * it has completed with an optional `err` argument. Invoked with (callback).
+ * @param {Function} test - synchronous truth test to perform after each
+ * execution of `iteratee`. Invoked with Invoked with the non-error callback
+ * results of `iteratee`.
+ * @param {Function} [callback] - A callback which is called after the test
+ * function has failed and repeated execution of `iteratee` has stopped.
+ * `callback` will be passed an error and any arguments passed to the final
+ * `iteratee`'s callback. Invoked with (err, [results]);
+ */
+ function doWhilst(iteratee, test, callback) {
+ callback = onlyOnce(callback || noop);
+ var next = rest(function (err, args) {
+ if (err) return callback(err);
+ if (test.apply(this, args)) return iteratee(next);
+ callback.apply(null, [null].concat(args));
+ });
+ iteratee(next);
}
- if (!string || !(chars = baseToString(chars))) {
- return string;
+
+ /**
+ * Like ['doWhilst']{@link module:ControlFlow.doWhilst}, except the `test` is inverted. Note the
+ * argument ordering differs from `until`.
+ *
+ * @name doUntil
+ * @static
+ * @memberOf module:ControlFlow
+ * @method
+ * @see [async.doWhilst]{@link module:ControlFlow.doWhilst}
+ * @category Control Flow
+ * @param {Function} fn - A function which is called each time `test` fails.
+ * The function is passed a `callback(err)`, which must be called once it has
+ * completed with an optional `err` argument. Invoked with (callback).
+ * @param {Function} test - synchronous truth test to perform after each
+ * execution of `fn`. Invoked with the non-error callback results of `fn`.
+ * @param {Function} [callback] - A callback which is called after the test
+ * function has passed and repeated execution of `fn` has stopped. `callback`
+ * will be passed an error and any arguments passed to the final `fn`'s
+ * callback. Invoked with (err, [results]);
+ */
+ function doUntil(fn, test, callback) {
+ doWhilst(fn, function () {
+ return !test.apply(this, arguments);
+ }, callback);
}
- var strSymbols = stringToArray(string),
- chrSymbols = stringToArray(chars),
- start = charsStartIndex(strSymbols, chrSymbols),
- end = charsEndIndex(strSymbols, chrSymbols) + 1;
-
- return castSlice(strSymbols, start, end).join('');
- }
-
- var FN_ARGS = /^(function)?\s*[^\(]*\(\s*([^\)]*)\)/m;
- var FN_ARG_SPLIT = /,/;
- var FN_ARG = /(=.+)?(\s*)$/;
- var STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg;
-
- function parseParams(func) {
- func = func.toString().replace(STRIP_COMMENTS, '');
- func = func.match(FN_ARGS)[2].replace(' ', '');
- func = func ? func.split(FN_ARG_SPLIT) : [];
- func = func.map(function (arg) {
- return trim(arg.replace(FN_ARG, ''));
- });
- return func;
- }
-
- /**
- * A dependency-injected version of the [async.auto]{@link module:ControlFlow.auto} function. Dependent
- * tasks are specified as parameters to the function, after the usual callback
- * parameter, with the parameter names matching the names of the tasks it
- * depends on. This can provide even more readable task graphs which can be
- * easier to maintain.
- *
- * If a final callback is specified, the task results are similarly injected,
- * specified as named parameters after the initial error parameter.
- *
- * The autoInject function is purely syntactic sugar and its semantics are
- * otherwise equivalent to [async.auto]{@link module:ControlFlow.auto}.
- *
- * @name autoInject
- * @static
- * @memberOf module:ControlFlow
- * @method
- * @see [async.auto]{@link module:ControlFlow.auto}
- * @category Control Flow
- * @param {Object} tasks - An object, each of whose properties is a function of
- * the form 'func([dependencies...], callback). The object's key of a property
- * serves as the name of the task defined by that property, i.e. can be used
- * when specifying requirements for other tasks.
- * * The `callback` parameter is a `callback(err, result)` which must be called
- * when finished, passing an `error` (which can be `null`) and the result of
- * the function's execution. The remaining parameters name other tasks on
- * which the task is dependent, and the results from those tasks are the
- * arguments of those parameters.
- * @param {Function} [callback] - An optional callback which is called when all
- * the tasks have been completed. It receives the `err` argument if any `tasks`
- * pass an error to their callback, and a `results` object with any completed
- * task results, similar to `auto`.
- * @example
- *
- * // The example from `auto` can be rewritten as follows:
- * async.autoInject({
- * get_data: function(callback) {
- * // async code to get some data
- * callback(null, 'data', 'converted to array');
- * },
- * make_folder: function(callback) {
- * // async code to create a directory to store a file in
- * // this is run at the same time as getting the data
- * callback(null, 'folder');
- * },
- * write_file: function(get_data, make_folder, callback) {
- * // once there is some data and the directory exists,
- * // write the data to a file in the directory
- * callback(null, 'filename');
- * },
- * email_link: function(write_file, callback) {
- * // once the file is written let's email a link to it...
- * // write_file contains the filename returned by write_file.
- * callback(null, {'file':write_file, 'email':'user@example.com'});
- * }
- * }, function(err, results) {
- * console.log('err = ', err);
- * console.log('email_link = ', results.email_link);
- * });
- *
- * // If you are using a JS minifier that mangles parameter names, `autoInject`
- * // will not work with plain functions, since the parameter names will be
- * // collapsed to a single letter identifier. To work around this, you can
- * // explicitly specify the names of the parameters your task function needs
- * // in an array, similar to Angular.js dependency injection.
- *
- * // This still has an advantage over plain `auto`, since the results a task
- * // depends on are still spread into arguments.
- * async.autoInject({
- * //...
- * write_file: ['get_data', 'make_folder', function(get_data, make_folder, callback) {
- * callback(null, 'filename');
- * }],
- * email_link: ['write_file', function(write_file, callback) {
- * callback(null, {'file':write_file, 'email':'user@example.com'});
- * }]
- * //...
- * }, function(err, results) {
- * console.log('err = ', err);
- * console.log('email_link = ', results.email_link);
- * });
- */
- function autoInject(tasks, callback) {
- var newTasks = {};
-
- baseForOwn(tasks, function (taskFn, key) {
- var params;
-
- if (isArray(taskFn)) {
- params = copyArray(taskFn);
- taskFn = params.pop();
-
- newTasks[key] = params.concat(params.length > 0 ? newTask : taskFn);
- } else if (taskFn.length === 1) {
- // no dependencies, use the function as-is
- newTasks[key] = taskFn;
- } else {
- params = parseParams(taskFn);
- if (taskFn.length === 0 && params.length === 0) {
- throw new Error("autoInject task functions require explicit parameters.");
- }
-
- params.pop();
-
- newTasks[key] = params.concat(newTask);
- }
- function newTask(results, taskCb) {
- var newArgs = arrayMap(params, function (name) {
- return results[name];
- });
- newArgs.push(taskCb);
- taskFn.apply(null, newArgs);
- }
- });
-
- auto(newTasks, callback);
- }
-
- var hasSetImmediate = typeof setImmediate === 'function' && setImmediate;
- var hasNextTick = typeof process === 'object' && typeof process.nextTick === 'function';
-
- function fallback(fn) {
- setTimeout(fn, 0);
- }
-
- function wrap(defer) {
- return rest(function (fn, args) {
- defer(function () {
- fn.apply(null, args);
- });
- });
- }
-
- var _defer;
-
- if (hasSetImmediate) {
- _defer = setImmediate;
- } else if (hasNextTick) {
- _defer = process.nextTick;
- } else {
- _defer = fallback;
- }
-
- var setImmediate$1 = wrap(_defer);
-
- // Simple doubly linked list (https://en.wikipedia.org/wiki/Doubly_linked_list) implementation
- // used for queues. This implementation assumes that the node provided by the user can be modified
- // to adjust the next and last properties. We implement only the minimal functionality
- // for queue support.
- function DLL() {
- this.head = this.tail = null;
- this.length = 0;
- }
-
- function setInitial(dll, node) {
- dll.length = 1;
- dll.head = dll.tail = node;
- }
-
- DLL.prototype.removeLink = function (node) {
- if (node.prev) node.prev.next = node.next;else this.head = node.next;
- if (node.next) node.next.prev = node.prev;else this.tail = node.prev;
-
- node.prev = node.next = null;
- this.length -= 1;
- return node;
- };
-
- DLL.prototype.empty = DLL;
-
- DLL.prototype.insertAfter = function (node, newNode) {
- newNode.prev = node;
- newNode.next = node.next;
- if (node.next) node.next.prev = newNode;else this.tail = newNode;
- node.next = newNode;
- this.length += 1;
- };
-
- DLL.prototype.insertBefore = function (node, newNode) {
- newNode.prev = node.prev;
- newNode.next = node;
- if (node.prev) node.prev.next = newNode;else this.head = newNode;
- node.prev = newNode;
- this.length += 1;
- };
-
- DLL.prototype.unshift = function (node) {
- if (this.head) this.insertBefore(this.head, node);else setInitial(this, node);
- };
-
- DLL.prototype.push = function (node) {
- if (this.tail) this.insertAfter(this.tail, node);else setInitial(this, node);
- };
-
- DLL.prototype.shift = function () {
- return this.head && this.removeLink(this.head);
- };
-
- DLL.prototype.pop = function () {
- return this.tail && this.removeLink(this.tail);
- };
-
- function queue(worker, concurrency, payload) {
- if (concurrency == null) {
- concurrency = 1;
- } else if (concurrency === 0) {
- throw new Error('Concurrency must not be zero');
- }
+ /**
+ * Like [`whilst`]{@link module:ControlFlow.whilst}, except the `test` is an asynchronous function that
+ * is passed a callback in the form of `function (err, truth)`. If error is
+ * passed to `test` or `fn`, the main callback is immediately called with the
+ * value of the error.
+ *
+ * @name during
+ * @static
+ * @memberOf module:ControlFlow
+ * @method
+ * @see [async.whilst]{@link module:ControlFlow.whilst}
+ * @category Control Flow
+ * @param {Function} test - asynchronous truth test to perform before each
+ * execution of `fn`. Invoked with (callback).
+ * @param {Function} fn - A function which is called each time `test` passes.
+ * The function is passed a `callback(err)`, which must be called once it has
+ * completed with an optional `err` argument. Invoked with (callback).
+ * @param {Function} [callback] - A callback which is called after the test
+ * function has failed and repeated execution of `fn` has stopped. `callback`
+ * will be passed an error, if one occured, otherwise `null`.
+ * @example
+ *
+ * var count = 0;
+ *
+ * async.during(
+ * function (callback) {
+ * return callback(null, count < 5);
+ * },
+ * function (callback) {
+ * count++;
+ * setTimeout(callback, 1000);
+ * },
+ * function (err) {
+ * // 5 seconds have passed
+ * }
+ * );
+ */
+ function during(test, fn, callback) {
+ callback = onlyOnce(callback || noop);
+
+ function next(err) {
+ if (err) return callback(err);
+ test(check);
+ }
- function _insert(data, pos, callback) {
- if (callback != null && typeof callback !== 'function') {
- throw new Error('task callback must be a function');
- }
- q.started = true;
- if (!isArray(data)) {
- data = [data];
- }
- if (data.length === 0 && q.idle()) {
- // call drain immediately if there are no tasks
- return setImmediate$1(function () {
- q.drain();
- });
- }
- arrayEach(data, function (task) {
- var item = {
- data: task,
- callback: callback || noop
- };
-
- if (pos) {
- q._tasks.unshift(item);
- } else {
- q._tasks.push(item);
- }
- });
- setImmediate$1(q.process);
- }
+ function check(err, truth) {
+ if (err) return callback(err);
+ if (!truth) return callback(null);
+ fn(next);
+ }
- function _next(tasks) {
- return rest(function (args) {
- workers -= 1;
-
- arrayEach(tasks, function (task) {
- arrayEach(workersList, function (worker, index) {
- if (worker === task) {
- workersList.splice(index, 1);
- return false;
- }
- });
-
- task.callback.apply(task, args);
-
- if (args[0] != null) {
- q.error(args[0], task.data);
- }
- });
-
- if (workers <= q.concurrency - q.buffer) {
- q.unsaturated();
- }
-
- if (q.idle()) {
- q.drain();
- }
- q.process();
- });
- }
+ test(check);
+ }
- var workers = 0;
- var workersList = [];
- var q = {
- _tasks: new DLL(),
- concurrency: concurrency,
- payload: payload,
- saturated: noop,
- unsaturated: noop,
- buffer: concurrency / 4,
- empty: noop,
- drain: noop,
- error: noop,
- started: false,
- paused: false,
- push: function (data, callback) {
- _insert(data, false, callback);
- },
- kill: function () {
- q.drain = noop;
- q._tasks.empty();
- },
- unshift: function (data, callback) {
- _insert(data, true, callback);
- },
- process: function () {
- while (!q.paused && workers < q.concurrency && q._tasks.length) {
- var tasks = [],
- data = [];
- var l = q._tasks.length;
- if (q.payload) l = Math.min(l, q.payload);
- for (var i = 0; i < l; i++) {
- var node = q._tasks.shift();
- tasks.push(node);
- data.push(node.data);
- }
-
- if (q._tasks.length === 0) {
- q.empty();
- }
- workers += 1;
- workersList.push(tasks[0]);
-
- if (workers === q.concurrency) {
- q.saturated();
- }
-
- var cb = onlyOnce(_next(tasks));
- worker(data, cb);
- }
- },
- length: function () {
- return q._tasks.length;
- },
- running: function () {
- return workers;
- },
- workersList: function () {
- return workersList;
- },
- idle: function () {
- return q._tasks.length + workers === 0;
- },
- pause: function () {
- q.paused = true;
- },
- resume: function () {
- if (q.paused === false) {
- return;
- }
- q.paused = false;
- var resumeCount = Math.min(q.concurrency, q._tasks.length);
- // Need to call q.process once per concurrent
- // worker to preserve full concurrency after pause
- for (var w = 1; w <= resumeCount; w++) {
- setImmediate$1(q.process);
- }
- }
- };
- return q;
- }
-
- /**
- * A cargo of tasks for the worker function to complete. Cargo inherits all of
- * the same methods and event callbacks as [`queue`]{@link module:ControlFlow.queue}.
- * @typedef {Object} CargoObject
- * @memberOf module:ControlFlow
- * @property {Function} length - A function returning the number of items
- * waiting to be processed. Invoke like `cargo.length()`.
- * @property {number} payload - An `integer` for determining how many tasks
- * should be process per round. This property can be changed after a `cargo` is
- * created to alter the payload on-the-fly.
- * @property {Function} push - Adds `task` to the `queue`. The callback is
- * called once the `worker` has finished processing the task. Instead of a
- * single task, an array of `tasks` can be submitted. The respective callback is
- * used for every task in the list. Invoke like `cargo.push(task, [callback])`.
- * @property {Function} saturated - A callback that is called when the
- * `queue.length()` hits the concurrency and further tasks will be queued.
- * @property {Function} empty - A callback that is called when the last item
- * from the `queue` is given to a `worker`.
- * @property {Function} drain - A callback that is called when the last item
- * from the `queue` has returned from the `worker`.
- * @property {Function} idle - a function returning false if there are items
- * waiting or being processed, or true if not. Invoke like `cargo.idle()`.
- * @property {Function} pause - a function that pauses the processing of tasks
- * until `resume()` is called. Invoke like `cargo.pause()`.
- * @property {Function} resume - a function that resumes the processing of
- * queued tasks when the queue is paused. Invoke like `cargo.resume()`.
- * @property {Function} kill - a function that removes the `drain` callback and
- * empties remaining tasks from the queue forcing it to go idle. Invoke like `cargo.kill()`.
- */
-
- /**
- * Creates a `cargo` object with the specified payload. Tasks added to the
- * cargo will be processed altogether (up to the `payload` limit). If the
- * `worker` is in progress, the task is queued until it becomes available. Once
- * the `worker` has completed some tasks, each callback of those tasks is
- * called. Check out [these](https://camo.githubusercontent.com/6bbd36f4cf5b35a0f11a96dcd2e97711ffc2fb37/68747470733a2f2f662e636c6f75642e6769746875622e636f6d2f6173736574732f313637363837312f36383130382f62626330636662302d356632392d313165322d393734662d3333393763363464633835382e676966) [animations](https://camo.githubusercontent.com/f4810e00e1c5f5f8addbe3e9f49064fd5d102699/68747470733a2f2f662e636c6f75642e6769746875622e636f6d2f6173736574732f313637363837312f36383130312f38346339323036362d356632392d313165322d383134662d3964336430323431336266642e676966)
- * for how `cargo` and `queue` work.
- *
- * While [`queue`]{@link module:ControlFlow.queue} passes only one task to one of a group of workers
- * at a time, cargo passes an array of tasks to a single worker, repeating
- * when the worker is finished.
- *
- * @name cargo
- * @static
- * @memberOf module:ControlFlow
- * @method
- * @see [async.queue]{@link module:ControlFlow.queue}
- * @category Control Flow
- * @param {Function} worker - An asynchronous function for processing an array
- * of queued tasks, which must call its `callback(err)` argument when finished,
- * with an optional `err` argument. Invoked with `(tasks, callback)`.
- * @param {number} [payload=Infinity] - An optional `integer` for determining
- * how many tasks should be processed per round; if omitted, the default is
- * unlimited.
- * @returns {module:ControlFlow.CargoObject} A cargo object to manage the tasks. Callbacks can
- * attached as certain properties to listen for specific events during the
- * lifecycle of the cargo and inner queue.
- * @example
- *
- * // create a cargo object with payload 2
- * var cargo = async.cargo(function(tasks, callback) {
- * for (var i=0; i<tasks.length; i++) {
- * console.log('hello ' + tasks[i].name);
- * }
- * callback();
- * }, 2);
- *
- * // add some items
- * cargo.push({name: 'foo'}, function(err) {
- * console.log('finished processing foo');
- * });
- * cargo.push({name: 'bar'}, function(err) {
- * console.log('finished processing bar');
- * });
- * cargo.push({name: 'baz'}, function(err) {
- * console.log('finished processing baz');
- * });
- */
- function cargo(worker, payload) {
- return queue(worker, 1, payload);
- }
-
- /**
- * The same as [`eachOf`]{@link module:Collections.eachOf} but runs a maximum of `limit` async operations at a
- * time.
- *
- * @name eachOfLimit
- * @static
- * @memberOf module:Collections
- * @method
- * @see [async.eachOf]{@link module:Collections.eachOf}
- * @alias forEachOfLimit
- * @category Collection
- * @param {Array|Iterable|Object} coll - A collection to iterate over.
- * @param {number} limit - The maximum number of async operations at a time.
- * @param {Function} iteratee - A function to apply to each
- * item in `coll`. The `key` is the item's key, or index in the case of an
- * array. The iteratee is passed a `callback(err)` which must be called once it
- * has completed. If no error has occurred, the callback should be run without
- * arguments or with an explicit `null` argument. Invoked with
- * (item, key, callback).
- * @param {Function} [callback] - A callback which is called when all
- * `iteratee` functions have finished, or an error occurs. Invoked with (err).
- */
- function eachOfLimit(coll, limit, iteratee, callback) {
- _eachOfLimit(limit)(coll, iteratee, callback);
- }
-
- /**
- * The same as [`eachOf`]{@link module:Collections.eachOf} but runs only a single async operation at a time.
- *
- * @name eachOfSeries
- * @static
- * @memberOf module:Collections
- * @method
- * @see [async.eachOf]{@link module:Collections.eachOf}
- * @alias forEachOfSeries
- * @category Collection
- * @param {Array|Iterable|Object} coll - A collection to iterate over.
- * @param {Function} iteratee - A function to apply to each item in `coll`. The
- * `key` is the item's key, or index in the case of an array. The iteratee is
- * passed a `callback(err)` which must be called once it has completed. If no
- * error has occurred, the callback should be run without arguments or with an
- * explicit `null` argument. Invoked with (item, key, callback).
- * @param {Function} [callback] - A callback which is called when all `iteratee`
- * functions have finished, or an error occurs. Invoked with (err).
- */
- var eachOfSeries = doLimit(eachOfLimit, 1);
-
- /**
- * Reduces `coll` into a single value using an async `iteratee` to return each
- * successive step. `memo` is the initial state of the reduction. This function
- * only operates in series.
- *
- * For performance reasons, it may make sense to split a call to this function
- * into a parallel map, and then use the normal `Array.prototype.reduce` on the
- * results. This function is for situations where each step in the reduction
- * needs to be async; if you can get the data before reducing it, then it's
- * probably a good idea to do so.
- *
- * @name reduce
- * @static
- * @memberOf module:Collections
- * @method
- * @alias inject
- * @alias foldl
- * @category Collection
- * @param {Array|Iterable|Object} coll - A collection to iterate over.
- * @param {*} memo - The initial state of the reduction.
- * @param {Function} iteratee - A function applied to each item in the
- * array to produce the next step in the reduction. The `iteratee` is passed a
- * `callback(err, reduction)` which accepts an optional error as its first
- * argument, and the state of the reduction as the second. If an error is
- * passed to the callback, the reduction is stopped and the main `callback` is
- * immediately called with the error. Invoked with (memo, item, callback).
- * @param {Function} [callback] - A callback which is called after all the
- * `iteratee` functions have finished. Result is the reduced value. Invoked with
- * (err, result).
- * @example
- *
- * async.reduce([1,2,3], 0, function(memo, item, callback) {
- * // pointless async:
- * process.nextTick(function() {
- * callback(null, memo + item)
- * });
- * }, function(err, result) {
- * // result is now equal to the last value of memo, which is 6
- * });
- */
- function reduce(coll, memo, iteratee, callback) {
- callback = once(callback || noop);
- eachOfSeries(coll, function (x, i, callback) {
- iteratee(memo, x, function (err, v) {
- memo = v;
- callback(err);
- });
- }, function (err) {
- callback(err, memo);
- });
- }
-
- /**
- * Version of the compose function that is more natural to read. Each function
- * consumes the return value of the previous function. It is the equivalent of
- * [compose]{@link module:ControlFlow.compose} with the arguments reversed.
- *
- * Each function is executed with the `this` binding of the composed function.
- *
- * @name seq
- * @static
- * @memberOf module:ControlFlow
- * @method
- * @see [async.compose]{@link module:ControlFlow.compose}
- * @category Control Flow
- * @param {...Function} functions - the asynchronous functions to compose
- * @returns {Function} a function that composes the `functions` in order
- * @example
- *
- * // Requires lodash (or underscore), express3 and dresende's orm2.
- * // Part of an app, that fetches cats of the logged user.
- * // This example uses `seq` function to avoid overnesting and error
- * // handling clutter.
- * app.get('/cats', function(request, response) {
- * var User = request.models.User;
- * async.seq(
- * _.bind(User.get, User), // 'User.get' has signature (id, callback(err, data))
- * function(user, fn) {
- * user.getCats(fn); // 'getCats' has signature (callback(err, data))
- * }
- * )(req.session.user_id, function (err, cats) {
- * if (err) {
- * console.error(err);
- * response.json({ status: 'error', message: err.message });
- * } else {
- * response.json({ status: 'ok', message: 'Cats found', data: cats });
- * }
- * });
- * });
- */
- var seq = rest(function seq(functions) {
- return rest(function (args) {
- var that = this;
-
- var cb = args[args.length - 1];
- if (typeof cb == 'function') {
- args.pop();
- } else {
- cb = noop;
- }
+ function _withoutIndex(iteratee) {
+ return function (value, index, callback) {
+ return iteratee(value, callback);
+ };
+ }
- reduce(functions, args, function (newargs, fn, cb) {
- fn.apply(that, newargs.concat([rest(function (err, nextargs) {
- cb(err, nextargs);
- })]));
- }, function (err, results) {
- cb.apply(that, [err].concat(results));
- });
- });
- });
-
- /**
- * Creates a function which is a composition of the passed asynchronous
- * functions. Each function consumes the return value of the function that
- * follows. Composing functions `f()`, `g()`, and `h()` would produce the result
- * of `f(g(h()))`, only this version uses callbacks to obtain the return values.
- *
- * Each function is executed with the `this` binding of the composed function.
- *
- * @name compose
- * @static
- * @memberOf module:ControlFlow
- * @method
- * @category Control Flow
- * @param {...Function} functions - the asynchronous functions to compose
- * @returns {Function} an asynchronous function that is the composed
- * asynchronous `functions`
- * @example
- *
- * function add1(n, callback) {
- * setTimeout(function () {
- * callback(null, n + 1);
- * }, 10);
- * }
- *
- * function mul3(n, callback) {
- * setTimeout(function () {
- * callback(null, n * 3);
- * }, 10);
- * }
- *
- * var add1mul3 = async.compose(mul3, add1);
- * add1mul3(4, function (err, result) {
- * // result now equals 15
- * });
- */
- var compose = rest(function (args) {
- return seq.apply(null, args.reverse());
- });
-
- function concat$1(eachfn, arr, fn, callback) {
- var result = [];
- eachfn(arr, function (x, index, cb) {
- fn(x, function (err, y) {
- result = result.concat(y || []);
- cb(err);
- });
- }, function (err) {
- callback(err, result);
- });
- }
-
- /**
- * Like [`each`]{@link module:Collections.each}, except that it passes the key (or index) as the second argument
- * to the iteratee.
- *
- * @name eachOf
- * @static
- * @memberOf module:Collections
- * @method
- * @alias forEachOf
- * @category Collection
- * @see [async.each]{@link module:Collections.each}
- * @param {Array|Iterable|Object} coll - A collection to iterate over.
- * @param {Function} iteratee - A function to apply to each
- * item in `coll`. The `key` is the item's key, or index in the case of an
- * array. The iteratee is passed a `callback(err)` which must be called once it
- * has completed. If no error has occurred, the callback should be run without
- * arguments or with an explicit `null` argument. Invoked with
- * (item, key, callback).
- * @param {Function} [callback] - A callback which is called when all
- * `iteratee` functions have finished, or an error occurs. Invoked with (err).
- * @example
- *
- * var obj = {dev: "/dev.json", test: "/test.json", prod: "/prod.json"};
- * var configs = {};
- *
- * async.forEachOf(obj, function (value, key, callback) {
- * fs.readFile(__dirname + value, "utf8", function (err, data) {
- * if (err) return callback(err);
- * try {
- * configs[key] = JSON.parse(data);
- * } catch (e) {
- * return callback(e);
- * }
- * callback();
- * });
- * }, function (err) {
- * if (err) console.error(err.message);
- * // configs is now a map of JSON data
- * doSomethingWith(configs);
- * });
- */
- var eachOf = doLimit(eachOfLimit, Infinity);
-
- function doParallel(fn) {
- return function (obj, iteratee, callback) {
- return fn(eachOf, obj, iteratee, callback);
- };
- }
-
- /**
- * Applies `iteratee` to each item in `coll`, concatenating the results. Returns
- * the concatenated list. The `iteratee`s are called in parallel, and the
- * results are concatenated as they return. There is no guarantee that the
- * results array will be returned in the original order of `coll` passed to the
- * `iteratee` function.
- *
- * @name concat
- * @static
- * @memberOf module:Collections
- * @method
- * @category Collection
- * @param {Array|Iterable|Object} coll - A collection to iterate over.
- * @param {Function} iteratee - A function to apply to each item in `coll`.
- * The iteratee is passed a `callback(err, results)` which must be called once
- * it has completed with an error (which can be `null`) and an array of results.
- * Invoked with (item, callback).
- * @param {Function} [callback(err)] - A callback which is called after all the
- * `iteratee` functions have finished, or an error occurs. Results is an array
- * containing the concatenated results of the `iteratee` function. Invoked with
- * (err, results).
- * @example
- *
- * async.concat(['dir1','dir2','dir3'], fs.readdir, function(err, files) {
- * // files is now a list of filenames that exist in the 3 directories
- * });
- */
- var concat = doParallel(concat$1);
-
- function doSeries(fn) {
- return function (obj, iteratee, callback) {
- return fn(eachOfSeries, obj, iteratee, callback);
- };
- }
-
- /**
- * The same as [`concat`]{@link module:Collections.concat} but runs only a single async operation at a time.
- *
- * @name concatSeries
- * @static
- * @memberOf module:Collections
- * @method
- * @see [async.concat]{@link module:Collections.concat}
- * @category Collection
- * @param {Array|Iterable|Object} coll - A collection to iterate over.
- * @param {Function} iteratee - A function to apply to each item in `coll`.
- * The iteratee is passed a `callback(err, results)` which must be called once
- * it has completed with an error (which can be `null`) and an array of results.
- * Invoked with (item, callback).
- * @param {Function} [callback(err)] - A callback which is called after all the
- * `iteratee` functions have finished, or an error occurs. Results is an array
- * containing the concatenated results of the `iteratee` function. Invoked with
- * (err, results).
- */
- var concatSeries = doSeries(concat$1);
-
- /**
- * Returns a function that when called, calls-back with the values provided.
- * Useful as the first function in a [`waterfall`]{@link module:ControlFlow.waterfall}, or for plugging values in to
- * [`auto`]{@link module:ControlFlow.auto}.
- *
- * @name constant
- * @static
- * @memberOf module:Utils
- * @method
- * @category Util
- * @param {...*} arguments... - Any number of arguments to automatically invoke
- * callback with.
- * @returns {Function} Returns a function that when invoked, automatically
- * invokes the callback with the previous given arguments.
- * @example
- *
- * async.waterfall([
- * async.constant(42),
- * function (value, next) {
- * // value === 42
- * },
- * //...
- * ], callback);
- *
- * async.waterfall([
- * async.constant(filename, "utf8"),
- * fs.readFile,
- * function (fileData, next) {
- * //...
- * }
- * //...
- * ], callback);
- *
- * async.auto({
- * hostname: async.constant("https://server.net/"),
- * port: findFreePort,
- * launchServer: ["hostname", "port", function (options, cb) {
- * startServer(options, cb);
- * }],
- * //...
- * }, callback);
- */
- var constant = rest(function (values) {
- var args = [null].concat(values);
- return initialParams(function (ignoredArgs, callback) {
- return callback.apply(this, args);
- });
- });
-
- /**
- * This method returns the first argument given to it.
- *
- * @static
- * @since 0.1.0
- * @memberOf _
- * @category Util
- * @param {*} value Any value.
- * @returns {*} Returns `value`.
- * @example
- *
- * var object = { 'user': 'fred' };
- *
- * console.log(_.identity(object) === object);
- * // => true
- */
- function identity(value) {
- return value;
- }
-
- function _createTester(eachfn, check, getResult) {
- return function (arr, limit, iteratee, cb) {
- function done(err) {
- if (cb) {
- if (err) {
- cb(err);
- } else {
- cb(null, getResult(false));
- }
- }
- }
- function wrappedIteratee(x, _, callback) {
- if (!cb) return callback();
- iteratee(x, function (err, v) {
- if (cb) {
- if (err) {
- cb(err);
- cb = iteratee = false;
- } else if (check(v)) {
- cb(null, getResult(true, x));
- cb = iteratee = false;
- }
- }
- callback();
- });
- }
- if (arguments.length > 3) {
- cb = cb || noop;
- eachfn(arr, limit, wrappedIteratee, done);
- } else {
- cb = iteratee;
- cb = cb || noop;
- iteratee = limit;
- eachfn(arr, wrappedIteratee, done);
- }
- };
- }
-
- function _findGetResult(v, x) {
- return x;
- }
-
- /**
- * Returns the first value in `coll` that passes an async truth test. The
- * `iteratee` is applied in parallel, meaning the first iteratee to return
- * `true` will fire the detect `callback` with that result. That means the
- * result might not be the first item in the original `coll` (in terms of order)
- * that passes the test.
-
- * If order within the original `coll` is important, then look at
- * [`detectSeries`]{@link module:Collections.detectSeries}.
- *
- * @name detect
- * @static
- * @memberOf module:Collections
- * @method
- * @alias find
- * @category Collections
- * @param {Array|Iterable|Object} coll - A collection to iterate over.
- * @param {Function} iteratee - A truth test to apply to each item in `coll`.
- * The iteratee is passed a `callback(err, truthValue)` which must be called
- * with a boolean argument once it has completed. Invoked with (item, callback).
- * @param {Function} [callback] - A callback which is called as soon as any
- * iteratee returns `true`, or after all the `iteratee` functions have finished.
- * Result will be the first item in the array that passes the truth test
- * (iteratee) or the value `undefined` if none passed. Invoked with
- * (err, result).
- * @example
- *
- * async.detect(['file1','file2','file3'], function(filePath, callback) {
- * fs.access(filePath, function(err) {
- * callback(null, !err)
- * });
- * }, function(err, result) {
- * // result now equals the first file in the list that exists
- * });
- */
- var detect = _createTester(eachOf, identity, _findGetResult);
-
- /**
- * The same as [`detect`]{@link module:Collections.detect} but runs a maximum of `limit` async operations at a
- * time.
- *
- * @name detectLimit
- * @static
- * @memberOf module:Collections
- * @method
- * @see [async.detect]{@link module:Collections.detect}
- * @alias findLimit
- * @category Collections
- * @param {Array|Iterable|Object} coll - A collection to iterate over.
- * @param {number} limit - The maximum number of async operations at a time.
- * @param {Function} iteratee - A truth test to apply to each item in `coll`.
- * The iteratee is passed a `callback(err, truthValue)` which must be called
- * with a boolean argument once it has completed. Invoked with (item, callback).
- * @param {Function} [callback] - A callback which is called as soon as any
- * iteratee returns `true`, or after all the `iteratee` functions have finished.
- * Result will be the first item in the array that passes the truth test
- * (iteratee) or the value `undefined` if none passed. Invoked with
- * (err, result).
- */
- var detectLimit = _createTester(eachOfLimit, identity, _findGetResult);
-
- /**
- * The same as [`detect`]{@link module:Collections.detect} but runs only a single async operation at a time.
- *
- * @name detectSeries
- * @static
- * @memberOf module:Collections
- * @method
- * @see [async.detect]{@link module:Collections.detect}
- * @alias findSeries
- * @category Collections
- * @param {Array|Iterable|Object} coll - A collection to iterate over.
- * @param {Function} iteratee - A truth test to apply to each item in `coll`.
- * The iteratee is passed a `callback(err, truthValue)` which must be called
- * with a boolean argument once it has completed. Invoked with (item, callback).
- * @param {Function} [callback] - A callback which is called as soon as any
- * iteratee returns `true`, or after all the `iteratee` functions have finished.
- * Result will be the first item in the array that passes the truth test
- * (iteratee) or the value `undefined` if none passed. Invoked with
- * (err, result).
- */
- var detectSeries = _createTester(eachOfSeries, identity, _findGetResult);
-
- function consoleFunc(name) {
- return rest(function (fn, args) {
- fn.apply(null, args.concat([rest(function (err, args) {
- if (typeof console === 'object') {
- if (err) {
- if (console.error) {
- console.error(err);
- }
- } else if (console[name]) {
- arrayEach(args, function (x) {
- console[name](x);
- });
- }
- }
- })]));
- });
- }
-
- /**
- * Logs the result of an `async` function to the `console` using `console.dir`
- * to display the properties of the resulting object. Only works in Node.js or
- * in browsers that support `console.dir` and `console.error` (such as FF and
- * Chrome). If multiple arguments are returned from the async function,
- * `console.dir` is called on each argument in order.
- *
- * @name dir
- * @static
- * @memberOf module:Utils
- * @method
- * @category Util
- * @param {Function} function - The function you want to eventually apply all
- * arguments to.
- * @param {...*} arguments... - Any number of arguments to apply to the function.
- * @example
- *
- * // in a module
- * var hello = function(name, callback) {
- * setTimeout(function() {
- * callback(null, {hello: name});
- * }, 1000);
- * };
- *
- * // in the node repl
- * node> async.dir(hello, 'world');
- * {hello: 'world'}
- */
- var dir = consoleFunc('dir');
-
- /**
- * The post-check version of [`during`]{@link module:ControlFlow.during}. To reflect the difference in
- * the order of operations, the arguments `test` and `fn` are switched.
- *
- * Also a version of [`doWhilst`]{@link module:ControlFlow.doWhilst} with asynchronous `test` function.
- * @name doDuring
- * @static
- * @memberOf module:ControlFlow
- * @method
- * @see [async.during]{@link module:ControlFlow.during}
- * @category Control Flow
- * @param {Function} fn - A function which is called each time `test` passes.
- * The function is passed a `callback(err)`, which must be called once it has
- * completed with an optional `err` argument. Invoked with (callback).
- * @param {Function} test - asynchronous truth test to perform before each
- * execution of `fn`. Invoked with (...args, callback), where `...args` are the
- * non-error args from the previous callback of `fn`.
- * @param {Function} [callback] - A callback which is called after the test
- * function has failed and repeated execution of `fn` has stopped. `callback`
- * will be passed an error if one occured, otherwise `null`.
- */
- function doDuring(fn, test, callback) {
- callback = onlyOnce(callback || noop);
-
- var next = rest(function (err, args) {
- if (err) return callback(err);
- args.push(check);
- test.apply(this, args);
- });
-
- function check(err, truth) {
- if (err) return callback(err);
- if (!truth) return callback(null);
- fn(next);
- }
+ /**
+ * Applies the function `iteratee` to each item in `coll`, in parallel.
+ * The `iteratee` is called with an item from the list, and a callback for when
+ * it has finished. If the `iteratee` passes an error to its `callback`, the
+ * main `callback` (for the `each` function) is immediately called with the
+ * error.
+ *
+ * Note, that since this function applies `iteratee` to each item in parallel,
+ * there is no guarantee that the iteratee functions will complete in order.
+ *
+ * @name each
+ * @static
+ * @memberOf module:Collections
+ * @method
+ * @alias forEach
+ * @category Collection
+ * @param {Array|Iterable|Object} coll - A collection to iterate over.
+ * @param {Function} iteratee - A function to apply to each item
+ * in `coll`. The iteratee is passed a `callback(err)` which must be called once
+ * it has completed. If no error has occurred, the `callback` should be run
+ * without arguments or with an explicit `null` argument. The array index is not
+ * passed to the iteratee. Invoked with (item, callback). If you need the index,
+ * use `eachOf`.
+ * @param {Function} [callback] - A callback which is called when all
+ * `iteratee` functions have finished, or an error occurs. Invoked with (err).
+ * @example
+ *
+ * // assuming openFiles is an array of file names and saveFile is a function
+ * // to save the modified contents of that file:
+ *
+ * async.each(openFiles, saveFile, function(err){
+ * // if any of the saves produced an error, err would equal that error
+ * });
+ *
+ * // assuming openFiles is an array of file names
+ * async.each(openFiles, function(file, callback) {
+ *
+ * // Perform operation on file here.
+ * console.log('Processing file ' + file);
+ *
+ * if( file.length > 32 ) {
+ * console.log('This file name is too long');
+ * callback('File name too long');
+ * } else {
+ * // Do work to process file here
+ * console.log('File processed');
+ * callback();
+ * }
+ * }, function(err) {
+ * // if any of the file processing produced an error, err would equal that error
+ * if( err ) {
+ * // One of the iterations produced an error.
+ * // All processing will now stop.
+ * console.log('A file failed to process');
+ * } else {
+ * console.log('All files have been processed successfully');
+ * }
+ * });
+ */
+ function eachLimit(coll, iteratee, callback) {
+ eachOf(coll, _withoutIndex(iteratee), callback);
+ }
- check(null, true);
- }
-
- /**
- * The post-check version of [`whilst`]{@link module:ControlFlow.whilst}. To reflect the difference in
- * the order of operations, the arguments `test` and `iteratee` are switched.
- *
- * `doWhilst` is to `whilst` as `do while` is to `while` in plain JavaScript.
- *
- * @name doWhilst
- * @static
- * @memberOf module:ControlFlow
- * @method
- * @see [async.whilst]{@link module:ControlFlow.whilst}
- * @category Control Flow
- * @param {Function} iteratee - A function which is called each time `test`
- * passes. The function is passed a `callback(err)`, which must be called once
- * it has completed with an optional `err` argument. Invoked with (callback).
- * @param {Function} test - synchronous truth test to perform after each
- * execution of `iteratee`. Invoked with Invoked with the non-error callback
- * results of `iteratee`.
- * @param {Function} [callback] - A callback which is called after the test
- * function has failed and repeated execution of `iteratee` has stopped.
- * `callback` will be passed an error and any arguments passed to the final
- * `iteratee`'s callback. Invoked with (err, [results]);
- */
- function doWhilst(iteratee, test, callback) {
- callback = onlyOnce(callback || noop);
- var next = rest(function (err, args) {
- if (err) return callback(err);
- if (test.apply(this, args)) return iteratee(next);
- callback.apply(null, [null].concat(args));
- });
- iteratee(next);
- }
-
- /**
- * Like ['doWhilst']{@link module:ControlFlow.doWhilst}, except the `test` is inverted. Note the
- * argument ordering differs from `until`.
- *
- * @name doUntil
- * @static
- * @memberOf module:ControlFlow
- * @method
- * @see [async.doWhilst]{@link module:ControlFlow.doWhilst}
- * @category Control Flow
- * @param {Function} fn - A function which is called each time `test` fails.
- * The function is passed a `callback(err)`, which must be called once it has
- * completed with an optional `err` argument. Invoked with (callback).
- * @param {Function} test - synchronous truth test to perform after each
- * execution of `fn`. Invoked with the non-error callback results of `fn`.
- * @param {Function} [callback] - A callback which is called after the test
- * function has passed and repeated execution of `fn` has stopped. `callback`
- * will be passed an error and any arguments passed to the final `fn`'s
- * callback. Invoked with (err, [results]);
- */
- function doUntil(fn, test, callback) {
- doWhilst(fn, function () {
- return !test.apply(this, arguments);
- }, callback);
- }
-
- /**
- * Like [`whilst`]{@link module:ControlFlow.whilst}, except the `test` is an asynchronous function that
- * is passed a callback in the form of `function (err, truth)`. If error is
- * passed to `test` or `fn`, the main callback is immediately called with the
- * value of the error.
- *
- * @name during
- * @static
- * @memberOf module:ControlFlow
- * @method
- * @see [async.whilst]{@link module:ControlFlow.whilst}
- * @category Control Flow
- * @param {Function} test - asynchronous truth test to perform before each
- * execution of `fn`. Invoked with (callback).
- * @param {Function} fn - A function which is called each time `test` passes.
- * The function is passed a `callback(err)`, which must be called once it has
- * completed with an optional `err` argument. Invoked with (callback).
- * @param {Function} [callback] - A callback which is called after the test
- * function has failed and repeated execution of `fn` has stopped. `callback`
- * will be passed an error, if one occured, otherwise `null`.
- * @example
- *
- * var count = 0;
- *
- * async.during(
- * function (callback) {
- * return callback(null, count < 5);
- * },
- * function (callback) {
- * count++;
- * setTimeout(callback, 1000);
- * },
- * function (err) {
- * // 5 seconds have passed
- * }
- * );
- */
- function during(test, fn, callback) {
- callback = onlyOnce(callback || noop);
-
- function next(err) {
- if (err) return callback(err);
- test(check);
- }
+ /**
+ * The same as [`each`]{@link module:Collections.each} but runs a maximum of `limit` async operations at a time.
+ *
+ * @name eachLimit
+ * @static
+ * @memberOf module:Collections
+ * @method
+ * @see [async.each]{@link module:Collections.each}
+ * @alias forEachLimit
+ * @category Collection
+ * @param {Array|Iterable|Object} coll - A colleciton to iterate over.
+ * @param {number} limit - The maximum number of async operations at a time.
+ * @param {Function} iteratee - A function to apply to each item in `coll`. The
+ * iteratee is passed a `callback(err)` which must be called once it has
+ * completed. If no error has occurred, the `callback` should be run without
+ * arguments or with an explicit `null` argument. The array index is not passed
+ * to the iteratee. Invoked with (item, callback). If you need the index, use
+ * `eachOfLimit`.
+ * @param {Function} [callback] - A callback which is called when all
+ * `iteratee` functions have finished, or an error occurs. Invoked with (err).
+ */
+ function eachLimit$1(coll, limit, iteratee, callback) {
+ _eachOfLimit(limit)(coll, _withoutIndex(iteratee), callback);
+ }
- function check(err, truth) {
- if (err) return callback(err);
- if (!truth) return callback(null);
- fn(next);
- }
+ /**
+ * The same as [`each`]{@link module:Collections.each} but runs only a single async operation at a time.
+ *
+ * @name eachSeries
+ * @static
+ * @memberOf module:Collections
+ * @method
+ * @see [async.each]{@link module:Collections.each}
+ * @alias forEachSeries
+ * @category Collection
+ * @param {Array|Iterable|Object} coll - A collection to iterate over.
+ * @param {Function} iteratee - A function to apply to each
+ * item in `coll`. The iteratee is passed a `callback(err)` which must be called
+ * once it has completed. If no error has occurred, the `callback` should be run
+ * without arguments or with an explicit `null` argument. The array index is
+ * not passed to the iteratee. Invoked with (item, callback). If you need the
+ * index, use `eachOfSeries`.
+ * @param {Function} [callback] - A callback which is called when all
+ * `iteratee` functions have finished, or an error occurs. Invoked with (err).
+ */
+ var eachSeries = doLimit(eachLimit$1, 1);
+
+ /**
+ * Wrap an async function and ensure it calls its callback on a later tick of
+ * the event loop. If the function already calls its callback on a next tick,
+ * no extra deferral is added. This is useful for preventing stack overflows
+ * (`RangeError: Maximum call stack size exceeded`) and generally keeping
+ * [Zalgo](http://blog.izs.me/post/59142742143/designing-apis-for-asynchrony)
+ * contained.
+ *
+ * @name ensureAsync
+ * @static
+ * @memberOf module:Utils
+ * @method
+ * @category Util
+ * @param {Function} fn - an async function, one that expects a node-style
+ * callback as its last argument.
+ * @returns {Function} Returns a wrapped function with the exact same call
+ * signature as the function passed in.
+ * @example
+ *
+ * function sometimesAsync(arg, callback) {
+ * if (cache[arg]) {
+ * return callback(null, cache[arg]); // this would be synchronous!!
+ * } else {
+ * doSomeIO(arg, callback); // this IO would be asynchronous
+ * }
+ * }
+ *
+ * // this has a risk of stack overflows if many results are cached in a row
+ * async.mapSeries(args, sometimesAsync, done);
+ *
+ * // this will defer sometimesAsync's callback if necessary,
+ * // preventing stack overflows
+ * async.mapSeries(args, async.ensureAsync(sometimesAsync), done);
+ */
+ function ensureAsync(fn) {
+ return initialParams(function (args, callback) {
+ var sync = true;
+ args.push(function () {
+ var innerArgs = arguments;
+ if (sync) {
+ setImmediate$1(function () {
+ callback.apply(null, innerArgs);
+ });
+ } else {
+ callback.apply(null, innerArgs);
+ }
+ });
+ fn.apply(this, args);
+ sync = false;
+ });
+ }
- test(check);
- }
+ function notId(v) {
+ return !v;
+ }
- function _withoutIndex(iteratee) {
- return function (value, index, callback) {
- return iteratee(value, callback);
- };
- }
-
- /**
- * The same as [`each`]{@link module:Collections.each} but runs a maximum of `limit` async operations at a time.
- *
- * @name eachLimit
- * @static
- * @memberOf module:Collections
- * @method
- * @see [async.each]{@link module:Collections.each}
- * @alias forEachLimit
- * @category Collection
- * @param {Array|Iterable|Object} coll - A colleciton to iterate over.
- * @param {number} limit - The maximum number of async operations at a time.
- * @param {Function} iteratee - A function to apply to each item in `coll`. The
- * iteratee is passed a `callback(err)` which must be called once it has
- * completed. If no error has occurred, the `callback` should be run without
- * arguments or with an explicit `null` argument. The array index is not passed
- * to the iteratee. Invoked with (item, callback). If you need the index, use
- * `eachOfLimit`.
- * @param {Function} [callback] - A callback which is called when all
- * `iteratee` functions have finished, or an error occurs. Invoked with (err).
- */
- function eachLimit(coll, limit, iteratee, callback) {
- _eachOfLimit(limit)(coll, _withoutIndex(iteratee), callback);
- }
-
- /**
- * Applies the function `iteratee` to each item in `coll`, in parallel.
- * The `iteratee` is called with an item from the list, and a callback for when
- * it has finished. If the `iteratee` passes an error to its `callback`, the
- * main `callback` (for the `each` function) is immediately called with the
- * error.
- *
- * Note, that since this function applies `iteratee` to each item in parallel,
- * there is no guarantee that the iteratee functions will complete in order.
- *
- * @name each
- * @static
- * @memberOf module:Collections
- * @method
- * @alias forEach
- * @category Collection
- * @param {Array|Iterable|Object} coll - A collection to iterate over.
- * @param {Function} iteratee - A function to apply to each item
- * in `coll`. The iteratee is passed a `callback(err)` which must be called once
- * it has completed. If no error has occurred, the `callback` should be run
- * without arguments or with an explicit `null` argument. The array index is not
- * passed to the iteratee. Invoked with (item, callback). If you need the index,
- * use `eachOf`.
- * @param {Function} [callback] - A callback which is called when all
- * `iteratee` functions have finished, or an error occurs. Invoked with (err).
- * @example
- *
- * // assuming openFiles is an array of file names and saveFile is a function
- * // to save the modified contents of that file:
- *
- * async.each(openFiles, saveFile, function(err){
- * // if any of the saves produced an error, err would equal that error
- * });
- *
- * // assuming openFiles is an array of file names
- * async.each(openFiles, function(file, callback) {
- *
- * // Perform operation on file here.
- * console.log('Processing file ' + file);
- *
- * if( file.length > 32 ) {
- * console.log('This file name is too long');
- * callback('File name too long');
- * } else {
- * // Do work to process file here
- * console.log('File processed');
- * callback();
- * }
- * }, function(err) {
- * // if any of the file processing produced an error, err would equal that error
- * if( err ) {
- * // One of the iterations produced an error.
- * // All processing will now stop.
- * console.log('A file failed to process');
- * } else {
- * console.log('All files have been processed successfully');
- * }
- * });
- */
- var each = doLimit(eachLimit, Infinity);
-
- /**
- * The same as [`each`]{@link module:Collections.each} but runs only a single async operation at a time.
- *
- * @name eachSeries
- * @static
- * @memberOf module:Collections
- * @method
- * @see [async.each]{@link module:Collections.each}
- * @alias forEachSeries
- * @category Collection
- * @param {Array|Iterable|Object} coll - A collection to iterate over.
- * @param {Function} iteratee - A function to apply to each
- * item in `coll`. The iteratee is passed a `callback(err)` which must be called
- * once it has completed. If no error has occurred, the `callback` should be run
- * without arguments or with an explicit `null` argument. The array index is
- * not passed to the iteratee. Invoked with (item, callback). If you need the
- * index, use `eachOfSeries`.
- * @param {Function} [callback] - A callback which is called when all
- * `iteratee` functions have finished, or an error occurs. Invoked with (err).
- */
- var eachSeries = doLimit(eachLimit, 1);
-
- /**
- * Wrap an async function and ensure it calls its callback on a later tick of
- * the event loop. If the function already calls its callback on a next tick,
- * no extra deferral is added. This is useful for preventing stack overflows
- * (`RangeError: Maximum call stack size exceeded`) and generally keeping
- * [Zalgo](http://blog.izs.me/post/59142742143/designing-apis-for-asynchrony)
- * contained.
- *
- * @name ensureAsync
- * @static
- * @memberOf module:Utils
- * @method
- * @category Util
- * @param {Function} fn - an async function, one that expects a node-style
- * callback as its last argument.
- * @returns {Function} Returns a wrapped function with the exact same call
- * signature as the function passed in.
- * @example
- *
- * function sometimesAsync(arg, callback) {
- * if (cache[arg]) {
- * return callback(null, cache[arg]); // this would be synchronous!!
- * } else {
- * doSomeIO(arg, callback); // this IO would be asynchronous
- * }
- * }
- *
- * // this has a risk of stack overflows if many results are cached in a row
- * async.mapSeries(args, sometimesAsync, done);
- *
- * // this will defer sometimesAsync's callback if necessary,
- * // preventing stack overflows
- * async.mapSeries(args, async.ensureAsync(sometimesAsync), done);
- */
- function ensureAsync(fn) {
- return initialParams(function (args, callback) {
- var sync = true;
- args.push(function () {
- var innerArgs = arguments;
- if (sync) {
- setImmediate$1(function () {
- callback.apply(null, innerArgs);
- });
- } else {
- callback.apply(null, innerArgs);
- }
- });
- fn.apply(this, args);
- sync = false;
- });
- }
-
- function notId(v) {
- return !v;
- }
-
- /**
- * The same as [`every`]{@link module:Collections.every} but runs a maximum of `limit` async operations at a time.
- *
- * @name everyLimit
- * @static
- * @memberOf module:Collections
- * @method
- * @see [async.every]{@link module:Collections.every}
- * @alias allLimit
- * @category Collection
- * @param {Array|Iterable|Object} coll - A collection to iterate over.
- * @param {number} limit - The maximum number of async operations at a time.
- * @param {Function} iteratee - A truth test to apply to each item in the
- * collection in parallel. The iteratee is passed a `callback(err, truthValue)`
- * which must be called with a boolean argument once it has completed. Invoked
- * with (item, callback).
- * @param {Function} [callback] - A callback which is called after all the
- * `iteratee` functions have finished. Result will be either `true` or `false`
- * depending on the values of the async tests. Invoked with (err, result).
- */
- var everyLimit = _createTester(eachOfLimit, notId, notId);
-
- /**
- * Returns `true` if every element in `coll` satisfies an async test. If any
- * iteratee call returns `false`, the main `callback` is immediately called.
- *
- * @name every
- * @static
- * @memberOf module:Collections
- * @method
- * @alias all
- * @category Collection
- * @param {Array|Iterable|Object} coll - A collection to iterate over.
- * @param {Function} iteratee - A truth test to apply to each item in the
- * collection in parallel. The iteratee is passed a `callback(err, truthValue)`
- * which must be called with a boolean argument once it has completed. Invoked
- * with (item, callback).
- * @param {Function} [callback] - A callback which is called after all the
- * `iteratee` functions have finished. Result will be either `true` or `false`
- * depending on the values of the async tests. Invoked with (err, result).
- * @example
- *
- * async.every(['file1','file2','file3'], function(filePath, callback) {
- * fs.access(filePath, function(err) {
- * callback(null, !err)
- * });
- * }, function(err, result) {
- * // if result is true then every file exists
- * });
- */
- var every = doLimit(everyLimit, Infinity);
-
- /**
- * The same as [`every`]{@link module:Collections.every} but runs only a single async operation at a time.
- *
- * @name everySeries
- * @static
- * @memberOf module:Collections
- * @method
- * @see [async.every]{@link module:Collections.every}
- * @alias allSeries
- * @category Collection
- * @param {Array|Iterable|Object} coll - A collection to iterate over.
- * @param {Function} iteratee - A truth test to apply to each item in the
- * collection in parallel. The iteratee is passed a `callback(err, truthValue)`
- * which must be called with a boolean argument once it has completed. Invoked
- * with (item, callback).
- * @param {Function} [callback] - A callback which is called after all the
- * `iteratee` functions have finished. Result will be either `true` or `false`
- * depending on the values of the async tests. Invoked with (err, result).
- */
- var everySeries = doLimit(everyLimit, 1);
-
- function _filter(eachfn, arr, iteratee, callback) {
- callback = once(callback || noop);
- var results = [];
- eachfn(arr, function (x, index, callback) {
- iteratee(x, function (err, v) {
- if (err) {
- callback(err);
- } else {
- if (v) {
- results.push({ index: index, value: x });
- }
- callback();
- }
- });
- }, function (err) {
- if (err) {
- callback(err);
- } else {
- callback(null, arrayMap(results.sort(function (a, b) {
- return a.index - b.index;
- }), baseProperty('value')));
- }
- });
- }
-
- /**
- * The same as [`filter`]{@link module:Collections.filter} but runs a maximum of `limit` async operations at a
- * time.
- *
- * @name filterLimit
- * @static
- * @memberOf module:Collections
- * @method
- * @see [async.filter]{@link module:Collections.filter}
- * @alias selectLimit
- * @category Collection
- * @param {Array|Iterable|Object} coll - A collection to iterate over.
- * @param {number} limit - The maximum number of async operations at a time.
- * @param {Function} iteratee - A truth test to apply to each item in `coll`.
- * The `iteratee` is passed a `callback(err, truthValue)`, which must be called
- * with a boolean argument once it has completed. Invoked with (item, callback).
- * @param {Function} [callback] - A callback which is called after all the
- * `iteratee` functions have finished. Invoked with (err, results).
- */
- var filterLimit = doParallelLimit(_filter);
-
- /**
- * Returns a new array of all the values in `coll` which pass an async truth
- * test. This operation is performed in parallel, but the results array will be
- * in the same order as the original.
- *
- * @name filter
- * @static
- * @memberOf module:Collections
- * @method
- * @alias select
- * @category Collection
- * @param {Array|Iterable|Object} coll - A collection to iterate over.
- * @param {Function} iteratee - A truth test to apply to each item in `coll`.
- * The `iteratee` is passed a `callback(err, truthValue)`, which must be called
- * with a boolean argument once it has completed. Invoked with (item, callback).
- * @param {Function} [callback] - A callback which is called after all the
- * `iteratee` functions have finished. Invoked with (err, results).
- * @example
- *
- * async.filter(['file1','file2','file3'], function(filePath, callback) {
- * fs.access(filePath, function(err) {
- * callback(null, !err)
- * });
- * }, function(err, results) {
- * // results now equals an array of the existing files
- * });
- */
- var filter = doLimit(filterLimit, Infinity);
-
- /**
- * The same as [`filter`]{@link module:Collections.filter} but runs only a single async operation at a time.
- *
- * @name filterSeries
- * @static
- * @memberOf module:Collections
- * @method
- * @see [async.filter]{@link module:Collections.filter}
- * @alias selectSeries
- * @category Collection
- * @param {Array|Iterable|Object} coll - A collection to iterate over.
- * @param {Function} iteratee - A truth test to apply to each item in `coll`.
- * The `iteratee` is passed a `callback(err, truthValue)`, which must be called
- * with a boolean argument once it has completed. Invoked with (item, callback).
- * @param {Function} [callback] - A callback which is called after all the
- * `iteratee` functions have finished. Invoked with (err, results)
- */
- var filterSeries = doLimit(filterLimit, 1);
-
- /**
- * Calls the asynchronous function `fn` with a callback parameter that allows it
- * to call itself again, in series, indefinitely.
-
- * If an error is passed to the
- * callback then `errback` is called with the error, and execution stops,
- * otherwise it will never be called.
- *
- * @name forever
- * @static
- * @memberOf module:ControlFlow
- * @method
- * @category Control Flow
- * @param {Function} fn - a function to call repeatedly. Invoked with (next).
- * @param {Function} [errback] - when `fn` passes an error to it's callback,
- * this function will be called, and execution stops. Invoked with (err).
- * @example
- *
- * async.forever(
- * function(next) {
- * // next is suitable for passing to things that need a callback(err [, whatever]);
- * // it will result in this function being called again.
- * },
- * function(err) {
- * // if next is called with a value in its first parameter, it will appear
- * // in here as 'err', and execution will stop.
- * }
- * );
- */
- function forever(fn, errback) {
- var done = onlyOnce(errback || noop);
- var task = ensureAsync(fn);
-
- function next(err) {
- if (err) return done(err);
- task(next);
- }
- next();
- }
-
- /**
- * Logs the result of an `async` function to the `console`. Only works in
- * Node.js or in browsers that support `console.log` and `console.error` (such
- * as FF and Chrome). If multiple arguments are returned from the async
- * function, `console.log` is called on each argument in order.
- *
- * @name log
- * @static
- * @memberOf module:Utils
- * @method
- * @category Util
- * @param {Function} function - The function you want to eventually apply all
- * arguments to.
- * @param {...*} arguments... - Any number of arguments to apply to the function.
- * @example
- *
- * // in a module
- * var hello = function(name, callback) {
- * setTimeout(function() {
- * callback(null, 'hello ' + name);
- * }, 1000);
- * };
- *
- * // in the node repl
- * node> async.log(hello, 'world');
- * 'hello world'
- */
- var log = consoleFunc('log');
-
- /**
- * The same as [`mapValues`]{@link module:Collections.mapValues} but runs a maximum of `limit` async operations at a
- * time.
- *
- * @name mapValuesLimit
- * @static
- * @memberOf module:Collections
- * @method
- * @see [async.mapValues]{@link module:Collections.mapValues}
- * @category Collection
- * @param {Object} obj - A collection to iterate over.
- * @param {number} limit - The maximum number of async operations at a time.
- * @param {Function} iteratee - A function to apply to each value in `obj`.
- * The iteratee is passed a `callback(err, transformed)` which must be called
- * once it has completed with an error (which can be `null`) and a
- * transformed value. Invoked with (value, key, callback).
- * @param {Function} [callback] - A callback which is called when all `iteratee`
- * functions have finished, or an error occurs. Result is an object of the
- * transformed values from the `obj`. Invoked with (err, result).
- */
- function mapValuesLimit(obj, limit, iteratee, callback) {
- callback = once(callback || noop);
- var newObj = {};
- eachOfLimit(obj, limit, function (val, key, next) {
- iteratee(val, key, function (err, result) {
- if (err) return next(err);
- newObj[key] = result;
- next();
- });
- }, function (err) {
- callback(err, newObj);
- });
- }
-
- /**
- * A relative of [`map`]{@link module:Collections.map}, designed for use with objects.
- *
- * Produces a new Object by mapping each value of `obj` through the `iteratee`
- * function. The `iteratee` is called each `value` and `key` from `obj` and a
- * callback for when it has finished processing. Each of these callbacks takes
- * two arguments: an `error`, and the transformed item from `obj`. If `iteratee`
- * passes an error to its callback, the main `callback` (for the `mapValues`
- * function) is immediately called with the error.
- *
- * Note, the order of the keys in the result is not guaranteed. The keys will
- * be roughly in the order they complete, (but this is very engine-specific)
- *
- * @name mapValues
- * @static
- * @memberOf module:Collections
- * @method
- * @category Collection
- * @param {Object} obj - A collection to iterate over.
- * @param {Function} iteratee - A function to apply to each value and key in
- * `coll`. The iteratee is passed a `callback(err, transformed)` which must be
- * called once it has completed with an error (which can be `null`) and a
- * transformed value. Invoked with (value, key, callback).
- * @param {Function} [callback] - A callback which is called when all `iteratee`
- * functions have finished, or an error occurs. Results is an array of the
- * transformed items from the `obj`. Invoked with (err, result).
- * @example
- *
- * async.mapValues({
- * f1: 'file1',
- * f2: 'file2',
- * f3: 'file3'
- * }, function (file, key, callback) {
- * fs.stat(file, callback);
- * }, function(err, result) {
- * // results is now a map of stats for each file, e.g.
- * // {
- * // f1: [stats for file1],
- * // f2: [stats for file2],
- * // f3: [stats for file3]
- * // }
- * });
- */
-
- var mapValues = doLimit(mapValuesLimit, Infinity);
-
- /**
- * The same as [`mapValues`]{@link module:Collections.mapValues} but runs only a single async operation at a time.
- *
- * @name mapValuesSeries
- * @static
- * @memberOf module:Collections
- * @method
- * @see [async.mapValues]{@link module:Collections.mapValues}
- * @category Collection
- * @param {Object} obj - A collection to iterate over.
- * @param {Function} iteratee - A function to apply to each value in `obj`.
- * The iteratee is passed a `callback(err, transformed)` which must be called
- * once it has completed with an error (which can be `null`) and a
- * transformed value. Invoked with (value, key, callback).
- * @param {Function} [callback] - A callback which is called when all `iteratee`
- * functions have finished, or an error occurs. Result is an object of the
- * transformed values from the `obj`. Invoked with (err, result).
- */
- var mapValuesSeries = doLimit(mapValuesLimit, 1);
-
- function has(obj, key) {
- return key in obj;
- }
-
- /**
- * Caches the results of an `async` function. When creating a hash to store
- * function results against, the callback is omitted from the hash and an
- * optional hash function can be used.
- *
- * If no hash function is specified, the first argument is used as a hash key,
- * which may work reasonably if it is a string or a data type that converts to a
- * distinct string. Note that objects and arrays will not behave reasonably.
- * Neither will cases where the other arguments are significant. In such cases,
- * specify your own hash function.
- *
- * The cache of results is exposed as the `memo` property of the function
- * returned by `memoize`.
- *
- * @name memoize
- * @static
- * @memberOf module:Utils
- * @method
- * @category Util
- * @param {Function} fn - The function to proxy and cache results from.
- * @param {Function} hasher - An optional function for generating a custom hash
- * for storing results. It has all the arguments applied to it apart from the
- * callback, and must be synchronous.
- * @returns {Function} a memoized version of `fn`
- * @example
- *
- * var slow_fn = function(name, callback) {
- * // do something
- * callback(null, result);
- * };
- * var fn = async.memoize(slow_fn);
- *
- * // fn can now be used as if it were slow_fn
- * fn('some name', function() {
- * // callback
- * });
- */
- function memoize(fn, hasher) {
- var memo = Object.create(null);
- var queues = Object.create(null);
- hasher = hasher || identity;
- var memoized = initialParams(function memoized(args, callback) {
- var key = hasher.apply(null, args);
- if (has(memo, key)) {
- setImmediate$1(function () {
- callback.apply(null, memo[key]);
- });
- } else if (has(queues, key)) {
- queues[key].push(callback);
- } else {
- queues[key] = [callback];
- fn.apply(null, args.concat([rest(function (args) {
- memo[key] = args;
- var q = queues[key];
- delete queues[key];
- for (var i = 0, l = q.length; i < l; i++) {
- q[i].apply(null, args);
- }
- })]));
- }
- });
- memoized.memo = memo;
- memoized.unmemoized = fn;
- return memoized;
- }
-
- /**
- * Calls `callback` on a later loop around the event loop. In Node.js this just
- * calls `setImmediate`. In the browser it will use `setImmediate` if
- * available, otherwise `setTimeout(callback, 0)`, which means other higher
- * priority events may precede the execution of `callback`.
- *
- * This is used internally for browser-compatibility purposes.
- *
- * @name nextTick
- * @static
- * @memberOf module:Utils
- * @method
- * @alias setImmediate
- * @category Util
- * @param {Function} callback - The function to call on a later loop around
- * the event loop. Invoked with (args...).
- * @param {...*} args... - any number of additional arguments to pass to the
- * callback on the next tick.
- * @example
- *
- * var call_order = [];
- * async.nextTick(function() {
- * call_order.push('two');
- * // call_order now equals ['one','two']
- * });
- * call_order.push('one');
- *
- * async.setImmediate(function (a, b, c) {
- * // a, b, and c equal 1, 2, and 3
- * }, 1, 2, 3);
- */
- var _defer$1;
-
- if (hasNextTick) {
- _defer$1 = process.nextTick;
- } else if (hasSetImmediate) {
- _defer$1 = setImmediate;
- } else {
- _defer$1 = fallback;
- }
-
- var nextTick = wrap(_defer$1);
-
- function _parallel(eachfn, tasks, callback) {
- callback = callback || noop;
- var results = isArrayLike(tasks) ? [] : {};
-
- eachfn(tasks, function (task, key, callback) {
- task(rest(function (err, args) {
- if (args.length <= 1) {
- args = args[0];
- }
- results[key] = args;
- callback(err);
- }));
- }, function (err) {
- callback(err, results);
- });
- }
-
- /**
- * The same as [`parallel`]{@link module:ControlFlow.parallel} but runs a maximum of `limit` async operations at a
- * time.
- *
- * @name parallelLimit
- * @static
- * @memberOf module:ControlFlow
- * @method
- * @see [async.parallel]{@link module:ControlFlow.parallel}
- * @category Control Flow
- * @param {Array|Collection} tasks - A collection containing functions to run.
- * Each function is passed a `callback(err, result)` which it must call on
- * completion with an error `err` (which can be `null`) and an optional `result`
- * value.
- * @param {number} limit - The maximum number of async operations at a time.
- * @param {Function} [callback] - An optional callback to run once all the
- * functions have completed successfully. This function gets a results array
- * (or object) containing all the result arguments passed to the task callbacks.
- * Invoked with (err, results).
- */
- function parallelLimit(tasks, limit, callback) {
- _parallel(_eachOfLimit(limit), tasks, callback);
- }
-
- /**
- * Run the `tasks` collection of functions in parallel, without waiting until
- * the previous function has completed. If any of the functions pass an error to
- * its callback, the main `callback` is immediately called with the value of the
- * error. Once the `tasks` have completed, the results are passed to the final
- * `callback` as an array.
- *
- * **Note:** `parallel` is about kicking-off I/O tasks in parallel, not about
- * parallel execution of code. If your tasks do not use any timers or perform
- * any I/O, they will actually be executed in series. Any synchronous setup
- * sections for each task will happen one after the other. JavaScript remains
- * single-threaded.
- *
- * It is also possible to use an object instead of an array. Each property will
- * be run as a function and the results will be passed to the final `callback`
- * as an object instead of an array. This can be a more readable way of handling
- * results from {@link async.parallel}.
- *
- * @name parallel
- * @static
- * @memberOf module:ControlFlow
- * @method
- * @category Control Flow
- * @param {Array|Iterable|Object} tasks - A collection containing functions to run.
- * Each function is passed a `callback(err, result)` which it must call on
- * completion with an error `err` (which can be `null`) and an optional `result`
- * value.
- * @param {Function} [callback] - An optional callback to run once all the
- * functions have completed successfully. This function gets a results array
- * (or object) containing all the result arguments passed to the task callbacks.
- * Invoked with (err, results).
- * @example
- * async.parallel([
- * function(callback) {
- * setTimeout(function() {
- * callback(null, 'one');
- * }, 200);
- * },
- * function(callback) {
- * setTimeout(function() {
- * callback(null, 'two');
- * }, 100);
- * }
- * ],
- * // optional callback
- * function(err, results) {
- * // the results array will equal ['one','two'] even though
- * // the second function had a shorter timeout.
- * });
- *
- * // an example using an object instead of an array
- * async.parallel({
- * one: function(callback) {
- * setTimeout(function() {
- * callback(null, 1);
- * }, 200);
- * },
- * two: function(callback) {
- * setTimeout(function() {
- * callback(null, 2);
- * }, 100);
- * }
- * }, function(err, results) {
- * // results is now equals to: {one: 1, two: 2}
- * });
- */
- var parallel = doLimit(parallelLimit, Infinity);
-
- /**
- * A queue of tasks for the worker function to complete.
- * @typedef {Object} QueueObject
- * @memberOf module:ControlFlow
- * @property {Function} length - a function returning the number of items
- * waiting to be processed. Invoke with `queue.length()`.
- * @property {Function} started - a function returning whether or not any
- * items have been pushed and processed by the queue. Invoke with `queue.started()`.
- * @property {Function} running - a function returning the number of items
- * currently being processed. Invoke with `queue.running()`.
- * @property {Function} workersList - a function returning the array of items
- * currently being processed. Invoke with `queue.workersList()`.
- * @property {Function} idle - a function returning false if there are items
- * waiting or being processed, or true if not. Invoke with `queue.idle()`.
- * @property {number} concurrency - an integer for determining how many `worker`
- * functions should be run in parallel. This property can be changed after a
- * `queue` is created to alter the concurrency on-the-fly.
- * @property {Function} push - add a new task to the `queue`. Calls `callback`
- * once the `worker` has finished processing the task. Instead of a single task,
- * a `tasks` array can be submitted. The respective callback is used for every
- * task in the list. Invoke with `queue.push(task, [callback])`,
- * @property {Function} unshift - add a new task to the front of the `queue`.
- * Invoke with `queue.unshift(task, [callback])`.
- * @property {Function} saturated - a callback that is called when the number of
- * running workers hits the `concurrency` limit, and further tasks will be
- * queued.
- * @property {Function} unsaturated - a callback that is called when the number
- * of running workers is less than the `concurrency` & `buffer` limits, and
- * further tasks will not be queued.
- * @property {number} buffer - A minimum threshold buffer in order to say that
- * the `queue` is `unsaturated`.
- * @property {Function} empty - a callback that is called when the last item
- * from the `queue` is given to a `worker`.
- * @property {Function} drain - a callback that is called when the last item
- * from the `queue` has returned from the `worker`.
- * @property {Function} error - a callback that is called when a task errors.
- * Has the signature `function(error, task)`.
- * @property {boolean} paused - a boolean for determining whether the queue is
- * in a paused state.
- * @property {Function} pause - a function that pauses the processing of tasks
- * until `resume()` is called. Invoke with `queue.pause()`.
- * @property {Function} resume - a function that resumes the processing of
- * queued tasks when the queue is paused. Invoke with `queue.resume()`.
- * @property {Function} kill - a function that removes the `drain` callback and
- * empties remaining tasks from the queue forcing it to go idle. Invoke with `queue.kill()`.
- */
-
- /**
- * Creates a `queue` object with the specified `concurrency`. Tasks added to the
- * `queue` are processed in parallel (up to the `concurrency` limit). If all
- * `worker`s are in progress, the task is queued until one becomes available.
- * Once a `worker` completes a `task`, that `task`'s callback is called.
- *
- * @name queue
- * @static
- * @memberOf module:ControlFlow
- * @method
- * @category Control Flow
- * @param {Function} worker - An asynchronous function for processing a queued
- * task, which must call its `callback(err)` argument when finished, with an
- * optional `error` as an argument. If you want to handle errors from an
- * individual task, pass a callback to `q.push()`. Invoked with
- * (task, callback).
- * @param {number} [concurrency=1] - An `integer` for determining how many
- * `worker` functions should be run in parallel. If omitted, the concurrency
- * defaults to `1`. If the concurrency is `0`, an error is thrown.
- * @returns {module:ControlFlow.QueueObject} A queue object to manage the tasks. Callbacks can
- * attached as certain properties to listen for specific events during the
- * lifecycle of the queue.
- * @example
- *
- * // create a queue object with concurrency 2
- * var q = async.queue(function(task, callback) {
- * console.log('hello ' + task.name);
- * callback();
- * }, 2);
- *
- * // assign a callback
- * q.drain = function() {
- * console.log('all items have been processed');
- * };
- *
- * // add some items to the queue
- * q.push({name: 'foo'}, function(err) {
- * console.log('finished processing foo');
- * });
- * q.push({name: 'bar'}, function (err) {
- * console.log('finished processing bar');
- * });
- *
- * // add some items to the queue (batch-wise)
- * q.push([{name: 'baz'},{name: 'bay'},{name: 'bax'}], function(err) {
- * console.log('finished processing item');
- * });
- *
- * // add some items to the front of the queue
- * q.unshift({name: 'bar'}, function (err) {
- * console.log('finished processing bar');
- * });
- */
- function queue$1 (worker, concurrency) {
- return queue(function (items, cb) {
- worker(items[0], cb);
- }, concurrency, 1);
- }
-
- /**
- * The same as [async.queue]{@link module:ControlFlow.queue} only tasks are assigned a priority and
- * completed in ascending priority order.
- *
- * @name priorityQueue
- * @static
- * @memberOf module:ControlFlow
- * @method
- * @see [async.queue]{@link module:ControlFlow.queue}
- * @category Control Flow
- * @param {Function} worker - An asynchronous function for processing a queued
- * task, which must call its `callback(err)` argument when finished, with an
- * optional `error` as an argument. If you want to handle errors from an
- * individual task, pass a callback to `q.push()`. Invoked with
- * (task, callback).
- * @param {number} concurrency - An `integer` for determining how many `worker`
- * functions should be run in parallel. If omitted, the concurrency defaults to
- * `1`. If the concurrency is `0`, an error is thrown.
- * @returns {module:ControlFlow.QueueObject} A priorityQueue object to manage the tasks. There are two
- * differences between `queue` and `priorityQueue` objects:
- * * `push(task, priority, [callback])` - `priority` should be a number. If an
- * array of `tasks` is given, all tasks will be assigned the same priority.
- * * The `unshift` method was removed.
- */
- function priorityQueue (worker, concurrency) {
- // Start with a normal queue
- var q = queue$1(worker, concurrency);
-
- // Override push to accept second parameter representing priority
- q.push = function (data, priority, callback) {
- if (callback == null) callback = noop;
- if (typeof callback !== 'function') {
- throw new Error('task callback must be a function');
- }
- q.started = true;
- if (!isArray(data)) {
- data = [data];
- }
- if (data.length === 0) {
- // call drain immediately if there are no tasks
- return setImmediate$1(function () {
- q.drain();
- });
- }
+ /**
+ * Returns `true` if every element in `coll` satisfies an async test. If any
+ * iteratee call returns `false`, the main `callback` is immediately called.
+ *
+ * @name every
+ * @static
+ * @memberOf module:Collections
+ * @method
+ * @alias all
+ * @category Collection
+ * @param {Array|Iterable|Object} coll - A collection to iterate over.
+ * @param {Function} iteratee - A truth test to apply to each item in the
+ * collection in parallel. The iteratee is passed a `callback(err, truthValue)`
+ * which must be called with a boolean argument once it has completed. Invoked
+ * with (item, callback).
+ * @param {Function} [callback] - A callback which is called after all the
+ * `iteratee` functions have finished. Result will be either `true` or `false`
+ * depending on the values of the async tests. Invoked with (err, result).
+ * @example
+ *
+ * async.every(['file1','file2','file3'], function(filePath, callback) {
+ * fs.access(filePath, function(err) {
+ * callback(null, !err)
+ * });
+ * }, function(err, result) {
+ * // if result is true then every file exists
+ * });
+ */
+ var every = _createTester(eachOf, notId, notId);
+
+ /**
+ * The same as [`every`]{@link module:Collections.every} but runs a maximum of `limit` async operations at a time.
+ *
+ * @name everyLimit
+ * @static
+ * @memberOf module:Collections
+ * @method
+ * @see [async.every]{@link module:Collections.every}
+ * @alias allLimit
+ * @category Collection
+ * @param {Array|Iterable|Object} coll - A collection to iterate over.
+ * @param {number} limit - The maximum number of async operations at a time.
+ * @param {Function} iteratee - A truth test to apply to each item in the
+ * collection in parallel. The iteratee is passed a `callback(err, truthValue)`
+ * which must be called with a boolean argument once it has completed. Invoked
+ * with (item, callback).
+ * @param {Function} [callback] - A callback which is called after all the
+ * `iteratee` functions have finished. Result will be either `true` or `false`
+ * depending on the values of the async tests. Invoked with (err, result).
+ */
+ var everyLimit = _createTester(eachOfLimit, notId, notId);
+
+ /**
+ * The same as [`every`]{@link module:Collections.every} but runs only a single async operation at a time.
+ *
+ * @name everySeries
+ * @static
+ * @memberOf module:Collections
+ * @method
+ * @see [async.every]{@link module:Collections.every}
+ * @alias allSeries
+ * @category Collection
+ * @param {Array|Iterable|Object} coll - A collection to iterate over.
+ * @param {Function} iteratee - A truth test to apply to each item in the
+ * collection in parallel. The iteratee is passed a `callback(err, truthValue)`
+ * which must be called with a boolean argument once it has completed. Invoked
+ * with (item, callback).
+ * @param {Function} [callback] - A callback which is called after all the
+ * `iteratee` functions have finished. Result will be either `true` or `false`
+ * depending on the values of the async tests. Invoked with (err, result).
+ */
+ var everySeries = doLimit(everyLimit, 1);
+
+ function _filter(eachfn, arr, iteratee, callback) {
+ callback = once(callback || noop);
+ var results = [];
+ eachfn(arr, function (x, index, callback) {
+ iteratee(x, function (err, v) {
+ if (err) {
+ callback(err);
+ } else {
+ if (v) {
+ results.push({ index: index, value: x });
+ }
+ callback();
+ }
+ });
+ }, function (err) {
+ if (err) {
+ callback(err);
+ } else {
+ callback(null, arrayMap(results.sort(function (a, b) {
+ return a.index - b.index;
+ }), baseProperty('value')));
+ }
+ });
+ }
- priority = priority || 0;
- var nextNode = q._tasks.head;
- while (nextNode && priority >= nextNode.priority) {
- nextNode = nextNode.next;
- }
+ /**
+ * Returns a new array of all the values in `coll` which pass an async truth
+ * test. This operation is performed in parallel, but the results array will be
+ * in the same order as the original.
+ *
+ * @name filter
+ * @static
+ * @memberOf module:Collections
+ * @method
+ * @alias select
+ * @category Collection
+ * @param {Array|Iterable|Object} coll - A collection to iterate over.
+ * @param {Function} iteratee - A truth test to apply to each item in `coll`.
+ * The `iteratee` is passed a `callback(err, truthValue)`, which must be called
+ * with a boolean argument once it has completed. Invoked with (item, callback).
+ * @param {Function} [callback] - A callback which is called after all the
+ * `iteratee` functions have finished. Invoked with (err, results).
+ * @example
+ *
+ * async.filter(['file1','file2','file3'], function(filePath, callback) {
+ * fs.access(filePath, function(err) {
+ * callback(null, !err)
+ * });
+ * }, function(err, results) {
+ * // results now equals an array of the existing files
+ * });
+ */
+ var filter = doParallel(_filter);
+
+ /**
+ * The same as [`filter`]{@link module:Collections.filter} but runs a maximum of `limit` async operations at a
+ * time.
+ *
+ * @name filterLimit
+ * @static
+ * @memberOf module:Collections
+ * @method
+ * @see [async.filter]{@link module:Collections.filter}
+ * @alias selectLimit
+ * @category Collection
+ * @param {Array|Iterable|Object} coll - A collection to iterate over.
+ * @param {number} limit - The maximum number of async operations at a time.
+ * @param {Function} iteratee - A truth test to apply to each item in `coll`.
+ * The `iteratee` is passed a `callback(err, truthValue)`, which must be called
+ * with a boolean argument once it has completed. Invoked with (item, callback).
+ * @param {Function} [callback] - A callback which is called after all the
+ * `iteratee` functions have finished. Invoked with (err, results).
+ */
+ var filterLimit = doParallelLimit(_filter);
+
+ /**
+ * The same as [`filter`]{@link module:Collections.filter} but runs only a single async operation at a time.
+ *
+ * @name filterSeries
+ * @static
+ * @memberOf module:Collections
+ * @method
+ * @see [async.filter]{@link module:Collections.filter}
+ * @alias selectSeries
+ * @category Collection
+ * @param {Array|Iterable|Object} coll - A collection to iterate over.
+ * @param {Function} iteratee - A truth test to apply to each item in `coll`.
+ * The `iteratee` is passed a `callback(err, truthValue)`, which must be called
+ * with a boolean argument once it has completed. Invoked with (item, callback).
+ * @param {Function} [callback] - A callback which is called after all the
+ * `iteratee` functions have finished. Invoked with (err, results)
+ */
+ var filterSeries = doLimit(filterLimit, 1);
+
+ /**
+ * Calls the asynchronous function `fn` with a callback parameter that allows it
+ * to call itself again, in series, indefinitely.
+
+ * If an error is passed to the
+ * callback then `errback` is called with the error, and execution stops,
+ * otherwise it will never be called.
+ *
+ * @name forever
+ * @static
+ * @memberOf module:ControlFlow
+ * @method
+ * @category Control Flow
+ * @param {Function} fn - a function to call repeatedly. Invoked with (next).
+ * @param {Function} [errback] - when `fn` passes an error to it's callback,
+ * this function will be called, and execution stops. Invoked with (err).
+ * @example
+ *
+ * async.forever(
+ * function(next) {
+ * // next is suitable for passing to things that need a callback(err [, whatever]);
+ * // it will result in this function being called again.
+ * },
+ * function(err) {
+ * // if next is called with a value in its first parameter, it will appear
+ * // in here as 'err', and execution will stop.
+ * }
+ * );
+ */
+ function forever(fn, errback) {
+ var done = onlyOnce(errback || noop);
+ var task = ensureAsync(fn);
+
+ function next(err) {
+ if (err) return done(err);
+ task(next);
+ }
+ next();
+ }
- arrayEach(data, function (task) {
- var item = {
- data: task,
- priority: priority,
- callback: callback
- };
-
- if (nextNode) {
- q._tasks.insertBefore(nextNode, item);
- } else {
- q._tasks.push(item);
- }
- });
- setImmediate$1(q.process);
- };
+ /**
+ * Logs the result of an `async` function to the `console`. Only works in
+ * Node.js or in browsers that support `console.log` and `console.error` (such
+ * as FF and Chrome). If multiple arguments are returned from the async
+ * function, `console.log` is called on each argument in order.
+ *
+ * @name log
+ * @static
+ * @memberOf module:Utils
+ * @method
+ * @category Util
+ * @param {Function} function - The function you want to eventually apply all
+ * arguments to.
+ * @param {...*} arguments... - Any number of arguments to apply to the function.
+ * @example
+ *
+ * // in a module
+ * var hello = function(name, callback) {
+ * setTimeout(function() {
+ * callback(null, 'hello ' + name);
+ * }, 1000);
+ * };
+ *
+ * // in the node repl
+ * node> async.log(hello, 'world');
+ * 'hello world'
+ */
+ var log = consoleFunc('log');
+
+ /**
+ * The same as [`mapValues`]{@link module:Collections.mapValues} but runs a maximum of `limit` async operations at a
+ * time.
+ *
+ * @name mapValuesLimit
+ * @static
+ * @memberOf module:Collections
+ * @method
+ * @see [async.mapValues]{@link module:Collections.mapValues}
+ * @category Collection
+ * @param {Object} obj - A collection to iterate over.
+ * @param {number} limit - The maximum number of async operations at a time.
+ * @param {Function} iteratee - A function to apply to each value in `obj`.
+ * The iteratee is passed a `callback(err, transformed)` which must be called
+ * once it has completed with an error (which can be `null`) and a
+ * transformed value. Invoked with (value, key, callback).
+ * @param {Function} [callback] - A callback which is called when all `iteratee`
+ * functions have finished, or an error occurs. Result is an object of the
+ * transformed values from the `obj`. Invoked with (err, result).
+ */
+ function mapValuesLimit(obj, limit, iteratee, callback) {
+ callback = once(callback || noop);
+ var newObj = {};
+ eachOfLimit(obj, limit, function (val, key, next) {
+ iteratee(val, key, function (err, result) {
+ if (err) return next(err);
+ newObj[key] = result;
+ next();
+ });
+ }, function (err) {
+ callback(err, newObj);
+ });
+ }
- // Remove unshift function
- delete q.unshift;
-
- return q;
- }
-
- /**
- * Runs the `tasks` array of functions in parallel, without waiting until the
- * previous function has completed. Once any the `tasks` completed or pass an
- * error to its callback, the main `callback` is immediately called. It's
- * equivalent to `Promise.race()`.
- *
- * @name race
- * @static
- * @memberOf module:ControlFlow
- * @method
- * @category Control Flow
- * @param {Array} tasks - An array containing functions to run. Each function
- * is passed a `callback(err, result)` which it must call on completion with an
- * error `err` (which can be `null`) and an optional `result` value.
- * @param {Function} callback - A callback to run once any of the functions have
- * completed. This function gets an error or result from the first function that
- * completed. Invoked with (err, result).
- * @returns undefined
- * @example
- *
- * async.race([
- * function(callback) {
- * setTimeout(function() {
- * callback(null, 'one');
- * }, 200);
- * },
- * function(callback) {
- * setTimeout(function() {
- * callback(null, 'two');
- * }, 100);
- * }
- * ],
- * // main callback
- * function(err, result) {
- * // the result will be equal to 'two' as it finishes earlier
- * });
- */
- function race(tasks, callback) {
- callback = once(callback || noop);
- if (!isArray(tasks)) return callback(new TypeError('First argument to race must be an array of functions'));
- if (!tasks.length) return callback();
- arrayEach(tasks, function (task) {
- task(callback);
- });
- }
-
- var slice = Array.prototype.slice;
-
- /**
- * Same as [`reduce`]{@link module:Collections.reduce}, only operates on `array` in reverse order.
- *
- * @name reduceRight
- * @static
- * @memberOf module:Collections
- * @method
- * @see [async.reduce]{@link module:Collections.reduce}
- * @alias foldr
- * @category Collection
- * @param {Array} array - A collection to iterate over.
- * @param {*} memo - The initial state of the reduction.
- * @param {Function} iteratee - A function applied to each item in the
- * array to produce the next step in the reduction. The `iteratee` is passed a
- * `callback(err, reduction)` which accepts an optional error as its first
- * argument, and the state of the reduction as the second. If an error is
- * passed to the callback, the reduction is stopped and the main `callback` is
- * immediately called with the error. Invoked with (memo, item, callback).
- * @param {Function} [callback] - A callback which is called after all the
- * `iteratee` functions have finished. Result is the reduced value. Invoked with
- * (err, result).
- */
- function reduceRight(array, memo, iteratee, callback) {
- var reversed = slice.call(array).reverse();
- reduce(reversed, memo, iteratee, callback);
- }
-
- /**
- * Wraps the function in another function that always returns data even when it
- * errors.
- *
- * The object returned has either the property `error` or `value`.
- *
- * @name reflect
- * @static
- * @memberOf module:Utils
- * @method
- * @category Util
- * @param {Function} fn - The function you want to wrap
- * @returns {Function} - A function that always passes null to it's callback as
- * the error. The second argument to the callback will be an `object` with
- * either an `error` or a `value` property.
- * @example
- *
- * async.parallel([
- * async.reflect(function(callback) {
- * // do some stuff ...
- * callback(null, 'one');
- * }),
- * async.reflect(function(callback) {
- * // do some more stuff but error ...
- * callback('bad stuff happened');
- * }),
- * async.reflect(function(callback) {
- * // do some more stuff ...
- * callback(null, 'two');
- * })
- * ],
- * // optional callback
- * function(err, results) {
- * // values
- * // results[0].value = 'one'
- * // results[1].error = 'bad stuff happened'
- * // results[2].value = 'two'
- * });
- */
- function reflect(fn) {
- return initialParams(function reflectOn(args, reflectCallback) {
- args.push(rest(function callback(err, cbArgs) {
- if (err) {
- reflectCallback(null, {
- error: err
- });
- } else {
- var value = null;
- if (cbArgs.length === 1) {
- value = cbArgs[0];
- } else if (cbArgs.length > 1) {
- value = cbArgs;
- }
- reflectCallback(null, {
- value: value
- });
- }
- }));
-
- return fn.apply(this, args);
- });
- }
-
- function reject$1(eachfn, arr, iteratee, callback) {
- _filter(eachfn, arr, function (value, cb) {
- iteratee(value, function (err, v) {
- if (err) {
- cb(err);
- } else {
- cb(null, !v);
- }
- });
- }, callback);
- }
-
- /**
- * The same as [`reject`]{@link module:Collections.reject} but runs a maximum of `limit` async operations at a
- * time.
- *
- * @name rejectLimit
- * @static
- * @memberOf module:Collections
- * @method
- * @see [async.reject]{@link module:Collections.reject}
- * @category Collection
- * @param {Array|Iterable|Object} coll - A collection to iterate over.
- * @param {number} limit - The maximum number of async operations at a time.
- * @param {Function} iteratee - A truth test to apply to each item in `coll`.
- * The `iteratee` is passed a `callback(err, truthValue)`, which must be called
- * with a boolean argument once it has completed. Invoked with (item, callback).
- * @param {Function} [callback] - A callback which is called after all the
- * `iteratee` functions have finished. Invoked with (err, results).
- */
- var rejectLimit = doParallelLimit(reject$1);
-
- /**
- * The opposite of [`filter`]{@link module:Collections.filter}. Removes values that pass an `async` truth test.
- *
- * @name reject
- * @static
- * @memberOf module:Collections
- * @method
- * @see [async.filter]{@link module:Collections.filter}
- * @category Collection
- * @param {Array|Iterable|Object} coll - A collection to iterate over.
- * @param {Function} iteratee - A truth test to apply to each item in `coll`.
- * The `iteratee` is passed a `callback(err, truthValue)`, which must be called
- * with a boolean argument once it has completed. Invoked with (item, callback).
- * @param {Function} [callback] - A callback which is called after all the
- * `iteratee` functions have finished. Invoked with (err, results).
- * @example
- *
- * async.reject(['file1','file2','file3'], function(filePath, callback) {
- * fs.access(filePath, function(err) {
- * callback(null, !err)
- * });
- * }, function(err, results) {
- * // results now equals an array of missing files
- * createFiles(results);
- * });
- */
- var reject = doLimit(rejectLimit, Infinity);
-
- /**
- * A helper function that wraps an array or an object of functions with reflect.
- *
- * @name reflectAll
- * @static
- * @memberOf module:Utils
- * @method
- * @see [async.reflect]{@link module:Utils.reflect}
- * @category Util
- * @param {Array} tasks - The array of functions to wrap in `async.reflect`.
- * @returns {Array} Returns an array of functions, each function wrapped in
- * `async.reflect`
- * @example
- *
- * let tasks = [
- * function(callback) {
- * setTimeout(function() {
- * callback(null, 'one');
- * }, 200);
- * },
- * function(callback) {
- * // do some more stuff but error ...
- * callback(new Error('bad stuff happened'));
- * },
- * function(callback) {
- * setTimeout(function() {
- * callback(null, 'two');
- * }, 100);
- * }
- * ];
- *
- * async.parallel(async.reflectAll(tasks),
- * // optional callback
- * function(err, results) {
- * // values
- * // results[0].value = 'one'
- * // results[1].error = Error('bad stuff happened')
- * // results[2].value = 'two'
- * });
- *
- * // an example using an object instead of an array
- * let tasks = {
- * one: function(callback) {
- * setTimeout(function() {
- * callback(null, 'one');
- * }, 200);
- * },
- * two: function(callback) {
- * callback('two');
- * },
- * three: function(callback) {
- * setTimeout(function() {
- * callback(null, 'three');
- * }, 100);
- * }
- * };
- *
- * async.parallel(async.reflectAll(tasks),
- * // optional callback
- * function(err, results) {
- * // values
- * // results.one.value = 'one'
- * // results.two.error = 'two'
- * // results.three.value = 'three'
- * });
- */
- function reflectAll(tasks) {
- var results;
- if (isArray(tasks)) {
- results = arrayMap(tasks, reflect);
- } else {
- results = {};
- baseForOwn(tasks, function (task, key) {
- results[key] = reflect.call(this, task);
- });
- }
- return results;
- }
-
- /**
- * The same as [`reject`]{@link module:Collections.reject} but runs only a single async operation at a time.
- *
- * @name rejectSeries
- * @static
- * @memberOf module:Collections
- * @method
- * @see [async.reject]{@link module:Collections.reject}
- * @category Collection
- * @param {Array|Iterable|Object} coll - A collection to iterate over.
- * @param {Function} iteratee - A truth test to apply to each item in `coll`.
- * The `iteratee` is passed a `callback(err, truthValue)`, which must be called
- * with a boolean argument once it has completed. Invoked with (item, callback).
- * @param {Function} [callback] - A callback which is called after all the
- * `iteratee` functions have finished. Invoked with (err, results).
- */
- var rejectSeries = doLimit(rejectLimit, 1);
-
- /**
- * Creates a function that returns `value`.
- *
- * @static
- * @memberOf _
- * @since 2.4.0
- * @category Util
- * @param {*} value The value to return from the new function.
- * @returns {Function} Returns the new constant function.
- * @example
- *
- * var objects = _.times(2, _.constant({ 'a': 1 }));
- *
- * console.log(objects);
- * // => [{ 'a': 1 }, { 'a': 1 }]
- *
- * console.log(objects[0] === objects[1]);
- * // => true
- */
- function constant$1(value) {
- return function() {
- return value;
- };
- }
-
- /**
- * Attempts to get a successful response from `task` no more than `times` times
- * before returning an error. If the task is successful, the `callback` will be
- * passed the result of the successful task. If all attempts fail, the callback
- * will be passed the error and result (if any) of the final attempt.
- *
- * @name retry
- * @static
- * @memberOf module:ControlFlow
- * @method
- * @category Control Flow
- * @param {Object|number} [opts = {times: 5, interval: 0}| 5] - Can be either an
- * object with `times` and `interval` or a number.
- * * `times` - The number of attempts to make before giving up. The default
- * is `5`.
- * * `interval` - The time to wait between retries, in milliseconds. The
- * default is `0`. The interval may also be specified as a function of the
- * retry count (see example).
- * * If `opts` is a number, the number specifies the number of times to retry,
- * with the default interval of `0`.
- * @param {Function} task - A function which receives two arguments: (1) a
- * `callback(err, result)` which must be called when finished, passing `err`
- * (which can be `null`) and the `result` of the function's execution, and (2)
- * a `results` object, containing the results of the previously executed
- * functions (if nested inside another control flow). Invoked with
- * (callback, results).
- * @param {Function} [callback] - An optional callback which is called when the
- * task has succeeded, or after the final failed attempt. It receives the `err`
- * and `result` arguments of the last attempt at completing the `task`. Invoked
- * with (err, results).
- * @example
- *
- * // The `retry` function can be used as a stand-alone control flow by passing
- * // a callback, as shown below:
- *
- * // try calling apiMethod 3 times
- * async.retry(3, apiMethod, function(err, result) {
- * // do something with the result
- * });
- *
- * // try calling apiMethod 3 times, waiting 200 ms between each retry
- * async.retry({times: 3, interval: 200}, apiMethod, function(err, result) {
- * // do something with the result
- * });
- *
- * // try calling apiMethod 10 times with exponential backoff
- * // (i.e. intervals of 100, 200, 400, 800, 1600, ... milliseconds)
- * async.retry({
- * times: 10,
- * interval: function(retryCount) {
- * return 50 * Math.pow(2, retryCount);
- * }
- * }, apiMethod, function(err, result) {
- * // do something with the result
- * });
- *
- * // try calling apiMethod the default 5 times no delay between each retry
- * async.retry(apiMethod, function(err, result) {
- * // do something with the result
- * });
- *
- * // It can also be embedded within other control flow functions to retry
- * // individual methods that are not as reliable, like this:
- * async.auto({
- * users: api.getUsers.bind(api),
- * payments: async.retry(3, api.getPayments.bind(api))
- * }, function(err, results) {
- * // do something with the results
- * });
- */
- function retry(opts, task, callback) {
- var DEFAULT_TIMES = 5;
- var DEFAULT_INTERVAL = 0;
-
- var options = {
- times: DEFAULT_TIMES,
- intervalFunc: constant$1(DEFAULT_INTERVAL)
- };
+ /**
+ * A relative of [`map`]{@link module:Collections.map}, designed for use with objects.
+ *
+ * Produces a new Object by mapping each value of `obj` through the `iteratee`
+ * function. The `iteratee` is called each `value` and `key` from `obj` and a
+ * callback for when it has finished processing. Each of these callbacks takes
+ * two arguments: an `error`, and the transformed item from `obj`. If `iteratee`
+ * passes an error to its callback, the main `callback` (for the `mapValues`
+ * function) is immediately called with the error.
+ *
+ * Note, the order of the keys in the result is not guaranteed. The keys will
+ * be roughly in the order they complete, (but this is very engine-specific)
+ *
+ * @name mapValues
+ * @static
+ * @memberOf module:Collections
+ * @method
+ * @category Collection
+ * @param {Object} obj - A collection to iterate over.
+ * @param {Function} iteratee - A function to apply to each value and key in
+ * `coll`. The iteratee is passed a `callback(err, transformed)` which must be
+ * called once it has completed with an error (which can be `null`) and a
+ * transformed value. Invoked with (value, key, callback).
+ * @param {Function} [callback] - A callback which is called when all `iteratee`
+ * functions have finished, or an error occurs. Results is an array of the
+ * transformed items from the `obj`. Invoked with (err, result).
+ * @example
+ *
+ * async.mapValues({
+ * f1: 'file1',
+ * f2: 'file2',
+ * f3: 'file3'
+ * }, function (file, key, callback) {
+ * fs.stat(file, callback);
+ * }, function(err, result) {
+ * // results is now a map of stats for each file, e.g.
+ * // {
+ * // f1: [stats for file1],
+ * // f2: [stats for file2],
+ * // f3: [stats for file3]
+ * // }
+ * });
+ */
+
+ var mapValues = doLimit(mapValuesLimit, Infinity);
+
+ /**
+ * The same as [`mapValues`]{@link module:Collections.mapValues} but runs only a single async operation at a time.
+ *
+ * @name mapValuesSeries
+ * @static
+ * @memberOf module:Collections
+ * @method
+ * @see [async.mapValues]{@link module:Collections.mapValues}
+ * @category Collection
+ * @param {Object} obj - A collection to iterate over.
+ * @param {Function} iteratee - A function to apply to each value in `obj`.
+ * The iteratee is passed a `callback(err, transformed)` which must be called
+ * once it has completed with an error (which can be `null`) and a
+ * transformed value. Invoked with (value, key, callback).
+ * @param {Function} [callback] - A callback which is called when all `iteratee`
+ * functions have finished, or an error occurs. Result is an object of the
+ * transformed values from the `obj`. Invoked with (err, result).
+ */
+ var mapValuesSeries = doLimit(mapValuesLimit, 1);
+
+ function has(obj, key) {
+ return key in obj;
+ }
- function parseTimes(acc, t) {
- if (typeof t === 'object') {
- acc.times = +t.times || DEFAULT_TIMES;
+ /**
+ * Caches the results of an `async` function. When creating a hash to store
+ * function results against, the callback is omitted from the hash and an
+ * optional hash function can be used.
+ *
+ * If no hash function is specified, the first argument is used as a hash key,
+ * which may work reasonably if it is a string or a data type that converts to a
+ * distinct string. Note that objects and arrays will not behave reasonably.
+ * Neither will cases where the other arguments are significant. In such cases,
+ * specify your own hash function.
+ *
+ * The cache of results is exposed as the `memo` property of the function
+ * returned by `memoize`.
+ *
+ * @name memoize
+ * @static
+ * @memberOf module:Utils
+ * @method
+ * @category Util
+ * @param {Function} fn - The function to proxy and cache results from.
+ * @param {Function} hasher - An optional function for generating a custom hash
+ * for storing results. It has all the arguments applied to it apart from the
+ * callback, and must be synchronous.
+ * @returns {Function} a memoized version of `fn`
+ * @example
+ *
+ * var slow_fn = function(name, callback) {
+ * // do something
+ * callback(null, result);
+ * };
+ * var fn = async.memoize(slow_fn);
+ *
+ * // fn can now be used as if it were slow_fn
+ * fn('some name', function() {
+ * // callback
+ * });
+ */
+ function memoize(fn, hasher) {
+ var memo = Object.create(null);
+ var queues = Object.create(null);
+ hasher = hasher || identity;
+ var memoized = initialParams(function memoized(args, callback) {
+ var key = hasher.apply(null, args);
+ if (has(memo, key)) {
+ setImmediate$1(function () {
+ callback.apply(null, memo[key]);
+ });
+ } else if (has(queues, key)) {
+ queues[key].push(callback);
+ } else {
+ queues[key] = [callback];
+ fn.apply(null, args.concat([rest(function (args) {
+ memo[key] = args;
+ var q = queues[key];
+ delete queues[key];
+ for (var i = 0, l = q.length; i < l; i++) {
+ q[i].apply(null, args);
+ }
+ })]));
+ }
+ });
+ memoized.memo = memo;
+ memoized.unmemoized = fn;
+ return memoized;
+ }
- acc.intervalFunc = typeof t.interval === 'function' ? t.interval : constant$1(+t.interval || DEFAULT_INTERVAL);
- } else if (typeof t === 'number' || typeof t === 'string') {
- acc.times = +t || DEFAULT_TIMES;
- } else {
- throw new Error("Invalid arguments for async.retry");
- }
- }
+ /**
+ * Calls `callback` on a later loop around the event loop. In Node.js this just
+ * calls `setImmediate`. In the browser it will use `setImmediate` if
+ * available, otherwise `setTimeout(callback, 0)`, which means other higher
+ * priority events may precede the execution of `callback`.
+ *
+ * This is used internally for browser-compatibility purposes.
+ *
+ * @name nextTick
+ * @static
+ * @memberOf module:Utils
+ * @method
+ * @alias setImmediate
+ * @category Util
+ * @param {Function} callback - The function to call on a later loop around
+ * the event loop. Invoked with (args...).
+ * @param {...*} args... - any number of additional arguments to pass to the
+ * callback on the next tick.
+ * @example
+ *
+ * var call_order = [];
+ * async.nextTick(function() {
+ * call_order.push('two');
+ * // call_order now equals ['one','two']
+ * });
+ * call_order.push('one');
+ *
+ * async.setImmediate(function (a, b, c) {
+ * // a, b, and c equal 1, 2, and 3
+ * }, 1, 2, 3);
+ */
+ var _defer$1;
+
+ if (hasNextTick) {
+ _defer$1 = process.nextTick;
+ } else if (hasSetImmediate) {
+ _defer$1 = setImmediate;
+ } else {
+ _defer$1 = fallback;
+ }
- if (arguments.length < 3 && typeof opts === 'function') {
- callback = task || noop;
- task = opts;
- } else {
- parseTimes(options, opts);
- callback = callback || noop;
- }
+ var nextTick = wrap(_defer$1);
+
+ function _parallel(eachfn, tasks, callback) {
+ callback = callback || noop;
+ var results = isArrayLike(tasks) ? [] : {};
+
+ eachfn(tasks, function (task, key, callback) {
+ task(rest(function (err, args) {
+ if (args.length <= 1) {
+ args = args[0];
+ }
+ results[key] = args;
+ callback(err);
+ }));
+ }, function (err) {
+ callback(err, results);
+ });
+ }
- if (typeof task !== 'function') {
- throw new Error("Invalid arguments for async.retry");
- }
+ /**
+ * Run the `tasks` collection of functions in parallel, without waiting until
+ * the previous function has completed. If any of the functions pass an error to
+ * its callback, the main `callback` is immediately called with the value of the
+ * error. Once the `tasks` have completed, the results are passed to the final
+ * `callback` as an array.
+ *
+ * **Note:** `parallel` is about kicking-off I/O tasks in parallel, not about
+ * parallel execution of code. If your tasks do not use any timers or perform
+ * any I/O, they will actually be executed in series. Any synchronous setup
+ * sections for each task will happen one after the other. JavaScript remains
+ * single-threaded.
+ *
+ * It is also possible to use an object instead of an array. Each property will
+ * be run as a function and the results will be passed to the final `callback`
+ * as an object instead of an array. This can be a more readable way of handling
+ * results from {@link async.parallel}.
+ *
+ * @name parallel
+ * @static
+ * @memberOf module:ControlFlow
+ * @method
+ * @category Control Flow
+ * @param {Array|Iterable|Object} tasks - A collection containing functions to run.
+ * Each function is passed a `callback(err, result)` which it must call on
+ * completion with an error `err` (which can be `null`) and an optional `result`
+ * value.
+ * @param {Function} [callback] - An optional callback to run once all the
+ * functions have completed successfully. This function gets a results array
+ * (or object) containing all the result arguments passed to the task callbacks.
+ * Invoked with (err, results).
+ * @example
+ * async.parallel([
+ * function(callback) {
+ * setTimeout(function() {
+ * callback(null, 'one');
+ * }, 200);
+ * },
+ * function(callback) {
+ * setTimeout(function() {
+ * callback(null, 'two');
+ * }, 100);
+ * }
+ * ],
+ * // optional callback
+ * function(err, results) {
+ * // the results array will equal ['one','two'] even though
+ * // the second function had a shorter timeout.
+ * });
+ *
+ * // an example using an object instead of an array
+ * async.parallel({
+ * one: function(callback) {
+ * setTimeout(function() {
+ * callback(null, 1);
+ * }, 200);
+ * },
+ * two: function(callback) {
+ * setTimeout(function() {
+ * callback(null, 2);
+ * }, 100);
+ * }
+ * }, function(err, results) {
+ * // results is now equals to: {one: 1, two: 2}
+ * });
+ */
+ function parallelLimit(tasks, callback) {
+ _parallel(eachOf, tasks, callback);
+ }
- var attempt = 1;
- function retryAttempt() {
- task(function (err) {
- if (err && attempt++ < options.times) {
- setTimeout(retryAttempt, options.intervalFunc(attempt));
- } else {
- callback.apply(null, arguments);
- }
- });
- }
+ /**
+ * The same as [`parallel`]{@link module:ControlFlow.parallel} but runs a maximum of `limit` async operations at a
+ * time.
+ *
+ * @name parallelLimit
+ * @static
+ * @memberOf module:ControlFlow
+ * @method
+ * @see [async.parallel]{@link module:ControlFlow.parallel}
+ * @category Control Flow
+ * @param {Array|Collection} tasks - A collection containing functions to run.
+ * Each function is passed a `callback(err, result)` which it must call on
+ * completion with an error `err` (which can be `null`) and an optional `result`
+ * value.
+ * @param {number} limit - The maximum number of async operations at a time.
+ * @param {Function} [callback] - An optional callback to run once all the
+ * functions have completed successfully. This function gets a results array
+ * (or object) containing all the result arguments passed to the task callbacks.
+ * Invoked with (err, results).
+ */
+ function parallelLimit$1(tasks, limit, callback) {
+ _parallel(_eachOfLimit(limit), tasks, callback);
+ }
- retryAttempt();
- }
-
- /**
- * A close relative of [`retry`]{@link module:ControlFlow.retry}. This method wraps a task and makes it
- * retryable, rather than immediately calling it with retries.
- *
- * @name retryable
- * @static
- * @memberOf module:ControlFlow
- * @method
- * @see [async.retry]{@link module:ControlFlow.retry}
- * @category Control Flow
- * @param {Object|number} [opts = {times: 5, interval: 0}| 5] - optional
- * options, exactly the same as from `retry`
- * @param {Function} task - the asynchronous function to wrap
- * @returns {Functions} The wrapped function, which when invoked, will retry on
- * an error, based on the parameters specified in `opts`.
- * @example
- *
- * async.auto({
- * dep1: async.retryable(3, getFromFlakyService),
- * process: ["dep1", async.retryable(3, function (results, cb) {
- * maybeProcessData(results.dep1, cb);
- * })]
- * }, callback);
- */
- function retryable (opts, task) {
- if (!task) {
- task = opts;
- opts = null;
- }
- return initialParams(function (args, callback) {
- function taskFn(cb) {
- task.apply(null, args.concat([cb]));
- }
+ /**
+ * A queue of tasks for the worker function to complete.
+ * @typedef {Object} QueueObject
+ * @memberOf module:ControlFlow
+ * @property {Function} length - a function returning the number of items
+ * waiting to be processed. Invoke with `queue.length()`.
+ * @property {boolean} started - a boolean indicating whether or not any
+ * items have been pushed and processed by the queue.
+ * @property {Function} running - a function returning the number of items
+ * currently being processed. Invoke with `queue.running()`.
+ * @property {Function} workersList - a function returning the array of items
+ * currently being processed. Invoke with `queue.workersList()`.
+ * @property {Function} idle - a function returning false if there are items
+ * waiting or being processed, or true if not. Invoke with `queue.idle()`.
+ * @property {number} concurrency - an integer for determining how many `worker`
+ * functions should be run in parallel. This property can be changed after a
+ * `queue` is created to alter the concurrency on-the-fly.
+ * @property {Function} push - add a new task to the `queue`. Calls `callback`
+ * once the `worker` has finished processing the task. Instead of a single task,
+ * a `tasks` array can be submitted. The respective callback is used for every
+ * task in the list. Invoke with `queue.push(task, [callback])`,
+ * @property {Function} unshift - add a new task to the front of the `queue`.
+ * Invoke with `queue.unshift(task, [callback])`.
+ * @property {Function} saturated - a callback that is called when the number of
+ * running workers hits the `concurrency` limit, and further tasks will be
+ * queued.
+ * @property {Function} unsaturated - a callback that is called when the number
+ * of running workers is less than the `concurrency` & `buffer` limits, and
+ * further tasks will not be queued.
+ * @property {number} buffer - A minimum threshold buffer in order to say that
+ * the `queue` is `unsaturated`.
+ * @property {Function} empty - a callback that is called when the last item
+ * from the `queue` is given to a `worker`.
+ * @property {Function} drain - a callback that is called when the last item
+ * from the `queue` has returned from the `worker`.
+ * @property {Function} error - a callback that is called when a task errors.
+ * Has the signature `function(error, task)`.
+ * @property {boolean} paused - a boolean for determining whether the queue is
+ * in a paused state.
+ * @property {Function} pause - a function that pauses the processing of tasks
+ * until `resume()` is called. Invoke with `queue.pause()`.
+ * @property {Function} resume - a function that resumes the processing of
+ * queued tasks when the queue is paused. Invoke with `queue.resume()`.
+ * @property {Function} kill - a function that removes the `drain` callback and
+ * empties remaining tasks from the queue forcing it to go idle. Invoke with `queue.kill()`.
+ */
+
+ /**
+ * Creates a `queue` object with the specified `concurrency`. Tasks added to the
+ * `queue` are processed in parallel (up to the `concurrency` limit). If all
+ * `worker`s are in progress, the task is queued until one becomes available.
+ * Once a `worker` completes a `task`, that `task`'s callback is called.
+ *
+ * @name queue
+ * @static
+ * @memberOf module:ControlFlow
+ * @method
+ * @category Control Flow
+ * @param {Function} worker - An asynchronous function for processing a queued
+ * task, which must call its `callback(err)` argument when finished, with an
+ * optional `error` as an argument. If you want to handle errors from an
+ * individual task, pass a callback to `q.push()`. Invoked with
+ * (task, callback).
+ * @param {number} [concurrency=1] - An `integer` for determining how many
+ * `worker` functions should be run in parallel. If omitted, the concurrency
+ * defaults to `1`. If the concurrency is `0`, an error is thrown.
+ * @returns {module:ControlFlow.QueueObject} A queue object to manage the tasks. Callbacks can
+ * attached as certain properties to listen for specific events during the
+ * lifecycle of the queue.
+ * @example
+ *
+ * // create a queue object with concurrency 2
+ * var q = async.queue(function(task, callback) {
+ * console.log('hello ' + task.name);
+ * callback();
+ * }, 2);
+ *
+ * // assign a callback
+ * q.drain = function() {
+ * console.log('all items have been processed');
+ * };
+ *
+ * // add some items to the queue
+ * q.push({name: 'foo'}, function(err) {
+ * console.log('finished processing foo');
+ * });
+ * q.push({name: 'bar'}, function (err) {
+ * console.log('finished processing bar');
+ * });
+ *
+ * // add some items to the queue (batch-wise)
+ * q.push([{name: 'baz'},{name: 'bay'},{name: 'bax'}], function(err) {
+ * console.log('finished processing item');
+ * });
+ *
+ * // add some items to the front of the queue
+ * q.unshift({name: 'bar'}, function (err) {
+ * console.log('finished processing bar');
+ * });
+ */
+ function queue$1 (worker, concurrency) {
+ return queue(function (items, cb) {
+ worker(items[0], cb);
+ }, concurrency, 1);
+ }
- if (opts) retry(opts, taskFn, callback);else retry(taskFn, callback);
- });
- }
-
- /**
- * Run the functions in the `tasks` collection in series, each one running once
- * the previous function has completed. If any functions in the series pass an
- * error to its callback, no more functions are run, and `callback` is
- * immediately called with the value of the error. Otherwise, `callback`
- * receives an array of results when `tasks` have completed.
- *
- * It is also possible to use an object instead of an array. Each property will
- * be run as a function, and the results will be passed to the final `callback`
- * as an object instead of an array. This can be a more readable way of handling
- * results from {@link async.series}.
- *
- * **Note** that while many implementations preserve the order of object
- * properties, the [ECMAScript Language Specification](http://www.ecma-international.org/ecma-262/5.1/#sec-8.6)
- * explicitly states that
- *
- * > The mechanics and order of enumerating the properties is not specified.
- *
- * So if you rely on the order in which your series of functions are executed,
- * and want this to work on all platforms, consider using an array.
- *
- * @name series
- * @static
- * @memberOf module:ControlFlow
- * @method
- * @category Control Flow
- * @param {Array|Iterable|Object} tasks - A collection containing functions to run, each
- * function is passed a `callback(err, result)` it must call on completion with
- * an error `err` (which can be `null`) and an optional `result` value.
- * @param {Function} [callback] - An optional callback to run once all the
- * functions have completed. This function gets a results array (or object)
- * containing all the result arguments passed to the `task` callbacks. Invoked
- * with (err, result).
- * @example
- * async.series([
- * function(callback) {
- * // do some stuff ...
- * callback(null, 'one');
- * },
- * function(callback) {
- * // do some more stuff ...
- * callback(null, 'two');
- * }
- * ],
- * // optional callback
- * function(err, results) {
- * // results is now equal to ['one', 'two']
- * });
- *
- * async.series({
- * one: function(callback) {
- * setTimeout(function() {
- * callback(null, 1);
- * }, 200);
- * },
- * two: function(callback){
- * setTimeout(function() {
- * callback(null, 2);
- * }, 100);
- * }
- * }, function(err, results) {
- * // results is now equal to: {one: 1, two: 2}
- * });
- */
- function series(tasks, callback) {
- _parallel(eachOfSeries, tasks, callback);
- }
-
- /**
- * The same as [`some`]{@link module:Collections.some} but runs a maximum of `limit` async operations at a time.
- *
- * @name someLimit
- * @static
- * @memberOf module:Collections
- * @method
- * @see [async.some]{@link module:Collections.some}
- * @alias anyLimit
- * @category Collection
- * @param {Array|Iterable|Object} coll - A collection to iterate over.
- * @param {number} limit - The maximum number of async operations at a time.
- * @param {Function} iteratee - A truth test to apply to each item in the array
- * in parallel. The iteratee is passed a `callback(err, truthValue)` which must
- * be called with a boolean argument once it has completed. Invoked with
- * (item, callback).
- * @param {Function} [callback] - A callback which is called as soon as any
- * iteratee returns `true`, or after all the iteratee functions have finished.
- * Result will be either `true` or `false` depending on the values of the async
- * tests. Invoked with (err, result).
- */
- var someLimit = _createTester(eachOfLimit, Boolean, identity);
-
- /**
- * Returns `true` if at least one element in the `coll` satisfies an async test.
- * If any iteratee call returns `true`, the main `callback` is immediately
- * called.
- *
- * @name some
- * @static
- * @memberOf module:Collections
- * @method
- * @alias any
- * @category Collection
- * @param {Array|Iterable|Object} coll - A collection to iterate over.
- * @param {Function} iteratee - A truth test to apply to each item in the array
- * in parallel. The iteratee is passed a `callback(err, truthValue)` which must
- * be called with a boolean argument once it has completed. Invoked with
- * (item, callback).
- * @param {Function} [callback] - A callback which is called as soon as any
- * iteratee returns `true`, or after all the iteratee functions have finished.
- * Result will be either `true` or `false` depending on the values of the async
- * tests. Invoked with (err, result).
- * @example
- *
- * async.some(['file1','file2','file3'], function(filePath, callback) {
- * fs.access(filePath, function(err) {
- * callback(null, !err)
- * });
- * }, function(err, result) {
- * // if result is true then at least one of the files exists
- * });
- */
- var some = doLimit(someLimit, Infinity);
-
- /**
- * The same as [`some`]{@link module:Collections.some} but runs only a single async operation at a time.
- *
- * @name someSeries
- * @static
- * @memberOf module:Collections
- * @method
- * @see [async.some]{@link module:Collections.some}
- * @alias anySeries
- * @category Collection
- * @param {Array|Iterable|Object} coll - A collection to iterate over.
- * @param {Function} iteratee - A truth test to apply to each item in the array
- * in parallel. The iteratee is passed a `callback(err, truthValue)` which must
- * be called with a boolean argument once it has completed. Invoked with
- * (item, callback).
- * @param {Function} [callback] - A callback which is called as soon as any
- * iteratee returns `true`, or after all the iteratee functions have finished.
- * Result will be either `true` or `false` depending on the values of the async
- * tests. Invoked with (err, result).
- */
- var someSeries = doLimit(someLimit, 1);
-
- /**
- * Sorts a list by the results of running each `coll` value through an async
- * `iteratee`.
- *
- * @name sortBy
- * @static
- * @memberOf module:Collections
- * @method
- * @category Collection
- * @param {Array|Iterable|Object} coll - A collection to iterate over.
- * @param {Function} iteratee - A function to apply to each item in `coll`.
- * The iteratee is passed a `callback(err, sortValue)` which must be called once
- * it has completed with an error (which can be `null`) and a value to use as
- * the sort criteria. Invoked with (item, callback).
- * @param {Function} callback - A callback which is called after all the
- * `iteratee` functions have finished, or an error occurs. Results is the items
- * from the original `coll` sorted by the values returned by the `iteratee`
- * calls. Invoked with (err, results).
- * @example
- *
- * async.sortBy(['file1','file2','file3'], function(file, callback) {
- * fs.stat(file, function(err, stats) {
- * callback(err, stats.mtime);
- * });
- * }, function(err, results) {
- * // results is now the original array of files sorted by
- * // modified date
- * });
- *
- * // By modifying the callback parameter the
- * // sorting order can be influenced:
- *
- * // ascending order
- * async.sortBy([1,9,3,5], function(x, callback) {
- * callback(null, x);
- * }, function(err,result) {
- * // result callback
- * });
- *
- * // descending order
- * async.sortBy([1,9,3,5], function(x, callback) {
- * callback(null, x*-1); //<- x*-1 instead of x, turns the order around
- * }, function(err,result) {
- * // result callback
- * });
- */
- function sortBy(coll, iteratee, callback) {
- map(coll, function (x, callback) {
- iteratee(x, function (err, criteria) {
- if (err) return callback(err);
- callback(null, { value: x, criteria: criteria });
- });
- }, function (err, results) {
- if (err) return callback(err);
- callback(null, arrayMap(results.sort(comparator), baseProperty('value')));
- });
-
- function comparator(left, right) {
- var a = left.criteria,
- b = right.criteria;
- return a < b ? -1 : a > b ? 1 : 0;
- }
- }
-
- /**
- * Sets a time limit on an asynchronous function. If the function does not call
- * its callback within the specified milliseconds, it will be called with a
- * timeout error. The code property for the error object will be `'ETIMEDOUT'`.
- *
- * @name timeout
- * @static
- * @memberOf module:Utils
- * @method
- * @category Util
- * @param {Function} asyncFn - The asynchronous function you want to set the
- * time limit.
- * @param {number} milliseconds - The specified time limit.
- * @param {*} [info] - Any variable you want attached (`string`, `object`, etc)
- * to timeout Error for more information..
- * @returns {Function} Returns a wrapped function that can be used with any of
- * the control flow functions.
- * @example
- *
- * async.timeout(function(callback) {
- * doAsyncTask(callback);
- * }, 1000);
- */
- function timeout(asyncFn, milliseconds, info) {
- var originalCallback, timer;
- var timedOut = false;
-
- function injectedCallback() {
- if (!timedOut) {
- originalCallback.apply(null, arguments);
- clearTimeout(timer);
- }
- }
+ /**
+ * The same as [async.queue]{@link module:ControlFlow.queue} only tasks are assigned a priority and
+ * completed in ascending priority order.
+ *
+ * @name priorityQueue
+ * @static
+ * @memberOf module:ControlFlow
+ * @method
+ * @see [async.queue]{@link module:ControlFlow.queue}
+ * @category Control Flow
+ * @param {Function} worker - An asynchronous function for processing a queued
+ * task, which must call its `callback(err)` argument when finished, with an
+ * optional `error` as an argument. If you want to handle errors from an
+ * individual task, pass a callback to `q.push()`. Invoked with
+ * (task, callback).
+ * @param {number} concurrency - An `integer` for determining how many `worker`
+ * functions should be run in parallel. If omitted, the concurrency defaults to
+ * `1`. If the concurrency is `0`, an error is thrown.
+ * @returns {module:ControlFlow.QueueObject} A priorityQueue object to manage the tasks. There are two
+ * differences between `queue` and `priorityQueue` objects:
+ * * `push(task, priority, [callback])` - `priority` should be a number. If an
+ * array of `tasks` is given, all tasks will be assigned the same priority.
+ * * The `unshift` method was removed.
+ */
+ function priorityQueue (worker, concurrency) {
+ // Start with a normal queue
+ var q = queue$1(worker, concurrency);
+
+ // Override push to accept second parameter representing priority
+ q.push = function (data, priority, callback) {
+ if (callback == null) callback = noop;
+ if (typeof callback !== 'function') {
+ throw new Error('task callback must be a function');
+ }
+ q.started = true;
+ if (!isArray(data)) {
+ data = [data];
+ }
+ if (data.length === 0) {
+ // call drain immediately if there are no tasks
+ return setImmediate$1(function () {
+ q.drain();
+ });
+ }
+
+ priority = priority || 0;
+ var nextNode = q._tasks.head;
+ while (nextNode && priority >= nextNode.priority) {
+ nextNode = nextNode.next;
+ }
+
+ arrayEach(data, function (task) {
+ var item = {
+ data: task,
+ priority: priority,
+ callback: callback
+ };
+
+ if (nextNode) {
+ q._tasks.insertBefore(nextNode, item);
+ } else {
+ q._tasks.push(item);
+ }
+ });
+ setImmediate$1(q.process);
+ };
+
+ // Remove unshift function
+ delete q.unshift;
+
+ return q;
+ }
- function timeoutCallback() {
- var name = asyncFn.name || 'anonymous';
- var error = new Error('Callback function "' + name + '" timed out.');
- error.code = 'ETIMEDOUT';
- if (info) {
- error.info = info;
- }
- timedOut = true;
- originalCallback(error);
- }
+ /**
+ * Runs the `tasks` array of functions in parallel, without waiting until the
+ * previous function has completed. Once any the `tasks` completed or pass an
+ * error to its callback, the main `callback` is immediately called. It's
+ * equivalent to `Promise.race()`.
+ *
+ * @name race
+ * @static
+ * @memberOf module:ControlFlow
+ * @method
+ * @category Control Flow
+ * @param {Array} tasks - An array containing functions to run. Each function
+ * is passed a `callback(err, result)` which it must call on completion with an
+ * error `err` (which can be `null`) and an optional `result` value.
+ * @param {Function} callback - A callback to run once any of the functions have
+ * completed. This function gets an error or result from the first function that
+ * completed. Invoked with (err, result).
+ * @returns undefined
+ * @example
+ *
+ * async.race([
+ * function(callback) {
+ * setTimeout(function() {
+ * callback(null, 'one');
+ * }, 200);
+ * },
+ * function(callback) {
+ * setTimeout(function() {
+ * callback(null, 'two');
+ * }, 100);
+ * }
+ * ],
+ * // main callback
+ * function(err, result) {
+ * // the result will be equal to 'two' as it finishes earlier
+ * });
+ */
+ function race(tasks, callback) {
+ callback = once(callback || noop);
+ if (!isArray(tasks)) return callback(new TypeError('First argument to race must be an array of functions'));
+ if (!tasks.length) return callback();
+ arrayEach(tasks, function (task) {
+ task(callback);
+ });
+ }
- return initialParams(function (args, origCallback) {
- originalCallback = origCallback;
- // setup timer and call original function
- timer = setTimeout(timeoutCallback, milliseconds);
- asyncFn.apply(null, args.concat(injectedCallback));
- });
- }
-
- /* Built-in method references for those with the same name as other `lodash` methods. */
- var nativeCeil = Math.ceil;
- var nativeMax$1 = Math.max;
- /**
- * The base implementation of `_.range` and `_.rangeRight` which doesn't
- * coerce arguments to numbers.
- *
- * @private
- * @param {number} start The start of the range.
- * @param {number} end The end of the range.
- * @param {number} step The value to increment or decrement by.
- * @param {boolean} [fromRight] Specify iterating from right to left.
- * @returns {Array} Returns the range of numbers.
- */
- function baseRange(start, end, step, fromRight) {
- var index = -1,
- length = nativeMax$1(nativeCeil((end - start) / (step || 1)), 0),
- result = Array(length);
-
- while (length--) {
- result[fromRight ? length : ++index] = start;
- start += step;
+ var slice = Array.prototype.slice;
+
+ /**
+ * Same as [`reduce`]{@link module:Collections.reduce}, only operates on `array` in reverse order.
+ *
+ * @name reduceRight
+ * @static
+ * @memberOf module:Collections
+ * @method
+ * @see [async.reduce]{@link module:Collections.reduce}
+ * @alias foldr
+ * @category Collection
+ * @param {Array} array - A collection to iterate over.
+ * @param {*} memo - The initial state of the reduction.
+ * @param {Function} iteratee - A function applied to each item in the
+ * array to produce the next step in the reduction. The `iteratee` is passed a
+ * `callback(err, reduction)` which accepts an optional error as its first
+ * argument, and the state of the reduction as the second. If an error is
+ * passed to the callback, the reduction is stopped and the main `callback` is
+ * immediately called with the error. Invoked with (memo, item, callback).
+ * @param {Function} [callback] - A callback which is called after all the
+ * `iteratee` functions have finished. Result is the reduced value. Invoked with
+ * (err, result).
+ */
+ function reduceRight(array, memo, iteratee, callback) {
+ var reversed = slice.call(array).reverse();
+ reduce(reversed, memo, iteratee, callback);
}
- return result;
- }
-
- /**
- * The same as [times]{@link module:ControlFlow.times} but runs a maximum of `limit` async operations at a
- * time.
- *
- * @name timesLimit
- * @static
- * @memberOf module:ControlFlow
- * @method
- * @see [async.times]{@link module:ControlFlow.times}
- * @category Control Flow
- * @param {number} count - The number of times to run the function.
- * @param {number} limit - The maximum number of async operations at a time.
- * @param {Function} iteratee - The function to call `n` times. Invoked with the
- * iteration index and a callback (n, next).
- * @param {Function} callback - see [async.map]{@link module:Collections.map}.
- */
- function timeLimit(count, limit, iteratee, callback) {
- mapLimit(baseRange(0, count, 1), limit, iteratee, callback);
- }
-
- /**
- * Calls the `iteratee` function `n` times, and accumulates results in the same
- * manner you would use with [map]{@link module:Collections.map}.
- *
- * @name times
- * @static
- * @memberOf module:ControlFlow
- * @method
- * @see [async.map]{@link module:Collections.map}
- * @category Control Flow
- * @param {number} n - The number of times to run the function.
- * @param {Function} iteratee - The function to call `n` times. Invoked with the
- * iteration index and a callback (n, next).
- * @param {Function} callback - see {@link module:Collections.map}.
- * @example
- *
- * // Pretend this is some complicated async factory
- * var createUser = function(id, callback) {
- * callback(null, {
- * id: 'user' + id
- * });
- * };
- *
- * // generate 5 users
- * async.times(5, function(n, next) {
- * createUser(n, function(err, user) {
- * next(err, user);
- * });
- * }, function(err, users) {
- * // we should now have 5 users
- * });
- */
- var times = doLimit(timeLimit, Infinity);
-
- /**
- * The same as [times]{@link module:ControlFlow.times} but runs only a single async operation at a time.
- *
- * @name timesSeries
- * @static
- * @memberOf module:ControlFlow
- * @method
- * @see [async.times]{@link module:ControlFlow.times}
- * @category Control Flow
- * @param {number} n - The number of times to run the function.
- * @param {Function} iteratee - The function to call `n` times. Invoked with the
- * iteration index and a callback (n, next).
- * @param {Function} callback - see {@link module:Collections.map}.
- */
- var timesSeries = doLimit(timeLimit, 1);
-
- /**
- * A relative of `reduce`. Takes an Object or Array, and iterates over each
- * element in series, each step potentially mutating an `accumulator` value.
- * The type of the accumulator defaults to the type of collection passed in.
- *
- * @name transform
- * @static
- * @memberOf module:Collections
- * @method
- * @category Collection
- * @param {Array|Iterable|Object} coll - A collection to iterate over.
- * @param {*} [accumulator] - The initial state of the transform. If omitted,
- * it will default to an empty Object or Array, depending on the type of `coll`
- * @param {Function} iteratee - A function applied to each item in the
- * collection that potentially modifies the accumulator. The `iteratee` is
- * passed a `callback(err)` which accepts an optional error as its first
- * argument. If an error is passed to the callback, the transform is stopped
- * and the main `callback` is immediately called with the error.
- * Invoked with (accumulator, item, key, callback).
- * @param {Function} [callback] - A callback which is called after all the
- * `iteratee` functions have finished. Result is the transformed accumulator.
- * Invoked with (err, result).
- * @example
- *
- * async.transform([1,2,3], function(acc, item, index, callback) {
- * // pointless async:
- * process.nextTick(function() {
- * acc.push(item * 2)
- * callback(null)
- * });
- * }, function(err, result) {
- * // result is now equal to [2, 4, 6]
- * });
- *
- * @example
- *
- * async.transform({a: 1, b: 2, c: 3}, function (obj, val, key, callback) {
- * setImmediate(function () {
- * obj[key] = val * 2;
- * callback();
- * })
- * }, function (err, result) {
- * // result is equal to {a: 2, b: 4, c: 6}
- * })
- */
- function transform(coll, accumulator, iteratee, callback) {
- if (arguments.length === 3) {
- callback = iteratee;
- iteratee = accumulator;
- accumulator = isArray(coll) ? [] : {};
- }
- callback = once(callback || noop);
-
- eachOf(coll, function (v, k, cb) {
- iteratee(accumulator, v, k, cb);
- }, function (err) {
- callback(err, accumulator);
- });
- }
-
- /**
- * Undoes a [memoize]{@link module:Utils.memoize}d function, reverting it to the original,
- * unmemoized form. Handy for testing.
- *
- * @name unmemoize
- * @static
- * @memberOf module:Utils
- * @method
- * @see [async.memoize]{@link module:Utils.memoize}
- * @category Util
- * @param {Function} fn - the memoized function
- * @returns {Function} a function that calls the original unmemoized function
- */
- function unmemoize(fn) {
- return function () {
- return (fn.unmemoized || fn).apply(null, arguments);
+
+ /**
+ * Wraps the function in another function that always returns data even when it
+ * errors.
+ *
+ * The object returned has either the property `error` or `value`.
+ *
+ * @name reflect
+ * @static
+ * @memberOf module:Utils
+ * @method
+ * @category Util
+ * @param {Function} fn - The function you want to wrap
+ * @returns {Function} - A function that always passes null to it's callback as
+ * the error. The second argument to the callback will be an `object` with
+ * either an `error` or a `value` property.
+ * @example
+ *
+ * async.parallel([
+ * async.reflect(function(callback) {
+ * // do some stuff ...
+ * callback(null, 'one');
+ * }),
+ * async.reflect(function(callback) {
+ * // do some more stuff but error ...
+ * callback('bad stuff happened');
+ * }),
+ * async.reflect(function(callback) {
+ * // do some more stuff ...
+ * callback(null, 'two');
+ * })
+ * ],
+ * // optional callback
+ * function(err, results) {
+ * // values
+ * // results[0].value = 'one'
+ * // results[1].error = 'bad stuff happened'
+ * // results[2].value = 'two'
+ * });
+ */
+ function reflect(fn) {
+ return initialParams(function reflectOn(args, reflectCallback) {
+ args.push(rest(function callback(err, cbArgs) {
+ if (err) {
+ reflectCallback(null, {
+ error: err
+ });
+ } else {
+ var value = null;
+ if (cbArgs.length === 1) {
+ value = cbArgs[0];
+ } else if (cbArgs.length > 1) {
+ value = cbArgs;
+ }
+ reflectCallback(null, {
+ value: value
+ });
+ }
+ }));
+
+ return fn.apply(this, args);
+ });
+ }
+
+ function reject$1(eachfn, arr, iteratee, callback) {
+ _filter(eachfn, arr, function (value, cb) {
+ iteratee(value, function (err, v) {
+ if (err) {
+ cb(err);
+ } else {
+ cb(null, !v);
+ }
+ });
+ }, callback);
+ }
+
+ /**
+ * The opposite of [`filter`]{@link module:Collections.filter}. Removes values that pass an `async` truth test.
+ *
+ * @name reject
+ * @static
+ * @memberOf module:Collections
+ * @method
+ * @see [async.filter]{@link module:Collections.filter}
+ * @category Collection
+ * @param {Array|Iterable|Object} coll - A collection to iterate over.
+ * @param {Function} iteratee - A truth test to apply to each item in `coll`.
+ * The `iteratee` is passed a `callback(err, truthValue)`, which must be called
+ * with a boolean argument once it has completed. Invoked with (item, callback).
+ * @param {Function} [callback] - A callback which is called after all the
+ * `iteratee` functions have finished. Invoked with (err, results).
+ * @example
+ *
+ * async.reject(['file1','file2','file3'], function(filePath, callback) {
+ * fs.access(filePath, function(err) {
+ * callback(null, !err)
+ * });
+ * }, function(err, results) {
+ * // results now equals an array of missing files
+ * createFiles(results);
+ * });
+ */
+ var reject = doParallel(reject$1);
+
+ /**
+ * A helper function that wraps an array or an object of functions with reflect.
+ *
+ * @name reflectAll
+ * @static
+ * @memberOf module:Utils
+ * @method
+ * @see [async.reflect]{@link module:Utils.reflect}
+ * @category Util
+ * @param {Array} tasks - The array of functions to wrap in `async.reflect`.
+ * @returns {Array} Returns an array of functions, each function wrapped in
+ * `async.reflect`
+ * @example
+ *
+ * let tasks = [
+ * function(callback) {
+ * setTimeout(function() {
+ * callback(null, 'one');
+ * }, 200);
+ * },
+ * function(callback) {
+ * // do some more stuff but error ...
+ * callback(new Error('bad stuff happened'));
+ * },
+ * function(callback) {
+ * setTimeout(function() {
+ * callback(null, 'two');
+ * }, 100);
+ * }
+ * ];
+ *
+ * async.parallel(async.reflectAll(tasks),
+ * // optional callback
+ * function(err, results) {
+ * // values
+ * // results[0].value = 'one'
+ * // results[1].error = Error('bad stuff happened')
+ * // results[2].value = 'two'
+ * });
+ *
+ * // an example using an object instead of an array
+ * let tasks = {
+ * one: function(callback) {
+ * setTimeout(function() {
+ * callback(null, 'one');
+ * }, 200);
+ * },
+ * two: function(callback) {
+ * callback('two');
+ * },
+ * three: function(callback) {
+ * setTimeout(function() {
+ * callback(null, 'three');
+ * }, 100);
+ * }
+ * };
+ *
+ * async.parallel(async.reflectAll(tasks),
+ * // optional callback
+ * function(err, results) {
+ * // values
+ * // results.one.value = 'one'
+ * // results.two.error = 'two'
+ * // results.three.value = 'three'
+ * });
+ */
+ function reflectAll(tasks) {
+ var results;
+ if (isArray(tasks)) {
+ results = arrayMap(tasks, reflect);
+ } else {
+ results = {};
+ baseForOwn(tasks, function (task, key) {
+ results[key] = reflect.call(this, task);
+ });
+ }
+ return results;
+ }
+
+ /**
+ * The same as [`reject`]{@link module:Collections.reject} but runs a maximum of `limit` async operations at a
+ * time.
+ *
+ * @name rejectLimit
+ * @static
+ * @memberOf module:Collections
+ * @method
+ * @see [async.reject]{@link module:Collections.reject}
+ * @category Collection
+ * @param {Array|Iterable|Object} coll - A collection to iterate over.
+ * @param {number} limit - The maximum number of async operations at a time.
+ * @param {Function} iteratee - A truth test to apply to each item in `coll`.
+ * The `iteratee` is passed a `callback(err, truthValue)`, which must be called
+ * with a boolean argument once it has completed. Invoked with (item, callback).
+ * @param {Function} [callback] - A callback which is called after all the
+ * `iteratee` functions have finished. Invoked with (err, results).
+ */
+ var rejectLimit = doParallelLimit(reject$1);
+
+ /**
+ * The same as [`reject`]{@link module:Collections.reject} but runs only a single async operation at a time.
+ *
+ * @name rejectSeries
+ * @static
+ * @memberOf module:Collections
+ * @method
+ * @see [async.reject]{@link module:Collections.reject}
+ * @category Collection
+ * @param {Array|Iterable|Object} coll - A collection to iterate over.
+ * @param {Function} iteratee - A truth test to apply to each item in `coll`.
+ * The `iteratee` is passed a `callback(err, truthValue)`, which must be called
+ * with a boolean argument once it has completed. Invoked with (item, callback).
+ * @param {Function} [callback] - A callback which is called after all the
+ * `iteratee` functions have finished. Invoked with (err, results).
+ */
+ var rejectSeries = doLimit(rejectLimit, 1);
+
+ /**
+ * Creates a function that returns `value`.
+ *
+ * @static
+ * @memberOf _
+ * @since 2.4.0
+ * @category Util
+ * @param {*} value The value to return from the new function.
+ * @returns {Function} Returns the new constant function.
+ * @example
+ *
+ * var objects = _.times(2, _.constant({ 'a': 1 }));
+ *
+ * console.log(objects);
+ * // => [{ 'a': 1 }, { 'a': 1 }]
+ *
+ * console.log(objects[0] === objects[1]);
+ * // => true
+ */
+ function constant$1(value) {
+ return function() {
+ return value;
};
- }
-
- /**
- * Repeatedly call `fn`, while `test` returns `true`. Calls `callback` when
- * stopped, or an error occurs.
- *
- * @name whilst
- * @static
- * @memberOf module:ControlFlow
- * @method
- * @category Control Flow
- * @param {Function} test - synchronous truth test to perform before each
- * execution of `fn`. Invoked with ().
- * @param {Function} iteratee - A function which is called each time `test` passes.
- * The function is passed a `callback(err)`, which must be called once it has
- * completed with an optional `err` argument. Invoked with (callback).
- * @param {Function} [callback] - A callback which is called after the test
- * function has failed and repeated execution of `fn` has stopped. `callback`
- * will be passed an error and any arguments passed to the final `fn`'s
- * callback. Invoked with (err, [results]);
- * @returns undefined
- * @example
- *
- * var count = 0;
- * async.whilst(
- * function() { return count < 5; },
- * function(callback) {
- * count++;
- * setTimeout(function() {
- * callback(null, count);
- * }, 1000);
- * },
- * function (err, n) {
- * // 5 seconds have passed, n = 5
- * }
- * );
- */
- function whilst(test, iteratee, callback) {
- callback = onlyOnce(callback || noop);
- if (!test()) return callback(null);
- var next = rest(function (err, args) {
- if (err) return callback(err);
- if (test()) return iteratee(next);
- callback.apply(null, [null].concat(args));
- });
- iteratee(next);
- }
-
- /**
- * Repeatedly call `fn` until `test` returns `true`. Calls `callback` when
- * stopped, or an error occurs. `callback` will be passed an error and any
- * arguments passed to the final `fn`'s callback.
- *
- * The inverse of [whilst]{@link module:ControlFlow.whilst}.
- *
- * @name until
- * @static
- * @memberOf module:ControlFlow
- * @method
- * @see [async.whilst]{@link module:ControlFlow.whilst}
- * @category Control Flow
- * @param {Function} test - synchronous truth test to perform before each
- * execution of `fn`. Invoked with ().
- * @param {Function} fn - A function which is called each time `test` fails.
- * The function is passed a `callback(err)`, which must be called once it has
- * completed with an optional `err` argument. Invoked with (callback).
- * @param {Function} [callback] - A callback which is called after the test
- * function has passed and repeated execution of `fn` has stopped. `callback`
- * will be passed an error and any arguments passed to the final `fn`'s
- * callback. Invoked with (err, [results]);
- */
- function until(test, fn, callback) {
- whilst(function () {
- return !test.apply(this, arguments);
- }, fn, callback);
- }
-
- /**
- * Runs the `tasks` array of functions in series, each passing their results to
- * the next in the array. However, if any of the `tasks` pass an error to their
- * own callback, the next function is not executed, and the main `callback` is
- * immediately called with the error.
- *
- * @name waterfall
- * @static
- * @memberOf module:ControlFlow
- * @method
- * @category Control Flow
- * @param {Array} tasks - An array of functions to run, each function is passed
- * a `callback(err, result1, result2, ...)` it must call on completion. The
- * first argument is an error (which can be `null`) and any further arguments
- * will be passed as arguments in order to the next task.
- * @param {Function} [callback] - An optional callback to run once all the
- * functions have completed. This will be passed the results of the last task's
- * callback. Invoked with (err, [results]).
- * @returns undefined
- * @example
- *
- * async.waterfall([
- * function(callback) {
- * callback(null, 'one', 'two');
- * },
- * function(arg1, arg2, callback) {
- * // arg1 now equals 'one' and arg2 now equals 'two'
- * callback(null, 'three');
- * },
- * function(arg1, callback) {
- * // arg1 now equals 'three'
- * callback(null, 'done');
- * }
- * ], function (err, result) {
- * // result now equals 'done'
- * });
- *
- * // Or, with named functions:
- * async.waterfall([
- * myFirstFunction,
- * mySecondFunction,
- * myLastFunction,
- * ], function (err, result) {
- * // result now equals 'done'
- * });
- * function myFirstFunction(callback) {
- * callback(null, 'one', 'two');
- * }
- * function mySecondFunction(arg1, arg2, callback) {
- * // arg1 now equals 'one' and arg2 now equals 'two'
- * callback(null, 'three');
- * }
- * function myLastFunction(arg1, callback) {
- * // arg1 now equals 'three'
- * callback(null, 'done');
- * }
- */
- function waterfall (tasks, callback) {
- callback = once(callback || noop);
- if (!isArray(tasks)) return callback(new Error('First argument to waterfall must be an array of functions'));
- if (!tasks.length) return callback();
- var taskIndex = 0;
-
- function nextTask(args) {
- if (taskIndex === tasks.length) {
- return callback.apply(null, [null].concat(args));
- }
+ }
- var taskCallback = onlyOnce(rest(function (err, args) {
- if (err) {
- return callback.apply(null, [err].concat(args));
- }
- nextTask(args);
- }));
+ /**
+ * Attempts to get a successful response from `task` no more than `times` times
+ * before returning an error. If the task is successful, the `callback` will be
+ * passed the result of the successful task. If all attempts fail, the callback
+ * will be passed the error and result (if any) of the final attempt.
+ *
+ * @name retry
+ * @static
+ * @memberOf module:ControlFlow
+ * @method
+ * @category Control Flow
+ * @param {Object|number} [opts = {times: 5, interval: 0}| 5] - Can be either an
+ * object with `times` and `interval` or a number.
+ * * `times` - The number of attempts to make before giving up. The default
+ * is `5`.
+ * * `interval` - The time to wait between retries, in milliseconds. The
+ * default is `0`. The interval may also be specified as a function of the
+ * retry count (see example).
+ * * If `opts` is a number, the number specifies the number of times to retry,
+ * with the default interval of `0`.
+ * @param {Function} task - A function which receives two arguments: (1) a
+ * `callback(err, result)` which must be called when finished, passing `err`
+ * (which can be `null`) and the `result` of the function's execution, and (2)
+ * a `results` object, containing the results of the previously executed
+ * functions (if nested inside another control flow). Invoked with
+ * (callback, results).
+ * @param {Function} [callback] - An optional callback which is called when the
+ * task has succeeded, or after the final failed attempt. It receives the `err`
+ * and `result` arguments of the last attempt at completing the `task`. Invoked
+ * with (err, results).
+ * @example
+ *
+ * // The `retry` function can be used as a stand-alone control flow by passing
+ * // a callback, as shown below:
+ *
+ * // try calling apiMethod 3 times
+ * async.retry(3, apiMethod, function(err, result) {
+ * // do something with the result
+ * });
+ *
+ * // try calling apiMethod 3 times, waiting 200 ms between each retry
+ * async.retry({times: 3, interval: 200}, apiMethod, function(err, result) {
+ * // do something with the result
+ * });
+ *
+ * // try calling apiMethod 10 times with exponential backoff
+ * // (i.e. intervals of 100, 200, 400, 800, 1600, ... milliseconds)
+ * async.retry({
+ * times: 10,
+ * interval: function(retryCount) {
+ * return 50 * Math.pow(2, retryCount);
+ * }
+ * }, apiMethod, function(err, result) {
+ * // do something with the result
+ * });
+ *
+ * // try calling apiMethod the default 5 times no delay between each retry
+ * async.retry(apiMethod, function(err, result) {
+ * // do something with the result
+ * });
+ *
+ * // It can also be embedded within other control flow functions to retry
+ * // individual methods that are not as reliable, like this:
+ * async.auto({
+ * users: api.getUsers.bind(api),
+ * payments: async.retry(3, api.getPayments.bind(api))
+ * }, function(err, results) {
+ * // do something with the results
+ * });
+ */
+ function retry(opts, task, callback) {
+ var DEFAULT_TIMES = 5;
+ var DEFAULT_INTERVAL = 0;
+
+ var options = {
+ times: DEFAULT_TIMES,
+ intervalFunc: constant$1(DEFAULT_INTERVAL)
+ };
+
+ function parseTimes(acc, t) {
+ if (typeof t === 'object') {
+ acc.times = +t.times || DEFAULT_TIMES;
+
+ acc.intervalFunc = typeof t.interval === 'function' ? t.interval : constant$1(+t.interval || DEFAULT_INTERVAL);
+ } else if (typeof t === 'number' || typeof t === 'string') {
+ acc.times = +t || DEFAULT_TIMES;
+ } else {
+ throw new Error("Invalid arguments for async.retry");
+ }
+ }
- args.push(taskCallback);
+ if (arguments.length < 3 && typeof opts === 'function') {
+ callback = task || noop;
+ task = opts;
+ } else {
+ parseTimes(options, opts);
+ callback = callback || noop;
+ }
+
+ if (typeof task !== 'function') {
+ throw new Error("Invalid arguments for async.retry");
+ }
+
+ var attempt = 1;
+ function retryAttempt() {
+ task(function (err) {
+ if (err && attempt++ < options.times) {
+ setTimeout(retryAttempt, options.intervalFunc(attempt));
+ } else {
+ callback.apply(null, arguments);
+ }
+ });
+ }
+
+ retryAttempt();
+ }
+
+ /**
+ * A close relative of [`retry`]{@link module:ControlFlow.retry}. This method wraps a task and makes it
+ * retryable, rather than immediately calling it with retries.
+ *
+ * @name retryable
+ * @static
+ * @memberOf module:ControlFlow
+ * @method
+ * @see [async.retry]{@link module:ControlFlow.retry}
+ * @category Control Flow
+ * @param {Object|number} [opts = {times: 5, interval: 0}| 5] - optional
+ * options, exactly the same as from `retry`
+ * @param {Function} task - the asynchronous function to wrap
+ * @returns {Functions} The wrapped function, which when invoked, will retry on
+ * an error, based on the parameters specified in `opts`.
+ * @example
+ *
+ * async.auto({
+ * dep1: async.retryable(3, getFromFlakyService),
+ * process: ["dep1", async.retryable(3, function (results, cb) {
+ * maybeProcessData(results.dep1, cb);
+ * })]
+ * }, callback);
+ */
+ function retryable (opts, task) {
+ if (!task) {
+ task = opts;
+ opts = null;
+ }
+ return initialParams(function (args, callback) {
+ function taskFn(cb) {
+ task.apply(null, args.concat([cb]));
+ }
+
+ if (opts) retry(opts, taskFn, callback);else retry(taskFn, callback);
+ });
+ }
+
+ /**
+ * Run the functions in the `tasks` collection in series, each one running once
+ * the previous function has completed. If any functions in the series pass an
+ * error to its callback, no more functions are run, and `callback` is
+ * immediately called with the value of the error. Otherwise, `callback`
+ * receives an array of results when `tasks` have completed.
+ *
+ * It is also possible to use an object instead of an array. Each property will
+ * be run as a function, and the results will be passed to the final `callback`
+ * as an object instead of an array. This can be a more readable way of handling
+ * results from {@link async.series}.
+ *
+ * **Note** that while many implementations preserve the order of object
+ * properties, the [ECMAScript Language Specification](http://www.ecma-international.org/ecma-262/5.1/#sec-8.6)
+ * explicitly states that
+ *
+ * > The mechanics and order of enumerating the properties is not specified.
+ *
+ * So if you rely on the order in which your series of functions are executed,
+ * and want this to work on all platforms, consider using an array.
+ *
+ * @name series
+ * @static
+ * @memberOf module:ControlFlow
+ * @method
+ * @category Control Flow
+ * @param {Array|Iterable|Object} tasks - A collection containing functions to run, each
+ * function is passed a `callback(err, result)` it must call on completion with
+ * an error `err` (which can be `null`) and an optional `result` value.
+ * @param {Function} [callback] - An optional callback to run once all the
+ * functions have completed. This function gets a results array (or object)
+ * containing all the result arguments passed to the `task` callbacks. Invoked
+ * with (err, result).
+ * @example
+ * async.series([
+ * function(callback) {
+ * // do some stuff ...
+ * callback(null, 'one');
+ * },
+ * function(callback) {
+ * // do some more stuff ...
+ * callback(null, 'two');
+ * }
+ * ],
+ * // optional callback
+ * function(err, results) {
+ * // results is now equal to ['one', 'two']
+ * });
+ *
+ * async.series({
+ * one: function(callback) {
+ * setTimeout(function() {
+ * callback(null, 1);
+ * }, 200);
+ * },
+ * two: function(callback){
+ * setTimeout(function() {
+ * callback(null, 2);
+ * }, 100);
+ * }
+ * }, function(err, results) {
+ * // results is now equal to: {one: 1, two: 2}
+ * });
+ */
+ function series(tasks, callback) {
+ _parallel(eachOfSeries, tasks, callback);
+ }
+
+ /**
+ * Returns `true` if at least one element in the `coll` satisfies an async test.
+ * If any iteratee call returns `true`, the main `callback` is immediately
+ * called.
+ *
+ * @name some
+ * @static
+ * @memberOf module:Collections
+ * @method
+ * @alias any
+ * @category Collection
+ * @param {Array|Iterable|Object} coll - A collection to iterate over.
+ * @param {Function} iteratee - A truth test to apply to each item in the array
+ * in parallel. The iteratee is passed a `callback(err, truthValue)` which must
+ * be called with a boolean argument once it has completed. Invoked with
+ * (item, callback).
+ * @param {Function} [callback] - A callback which is called as soon as any
+ * iteratee returns `true`, or after all the iteratee functions have finished.
+ * Result will be either `true` or `false` depending on the values of the async
+ * tests. Invoked with (err, result).
+ * @example
+ *
+ * async.some(['file1','file2','file3'], function(filePath, callback) {
+ * fs.access(filePath, function(err) {
+ * callback(null, !err)
+ * });
+ * }, function(err, result) {
+ * // if result is true then at least one of the files exists
+ * });
+ */
+ var some = _createTester(eachOf, Boolean, identity);
+
+ /**
+ * The same as [`some`]{@link module:Collections.some} but runs a maximum of `limit` async operations at a time.
+ *
+ * @name someLimit
+ * @static
+ * @memberOf module:Collections
+ * @method
+ * @see [async.some]{@link module:Collections.some}
+ * @alias anyLimit
+ * @category Collection
+ * @param {Array|Iterable|Object} coll - A collection to iterate over.
+ * @param {number} limit - The maximum number of async operations at a time.
+ * @param {Function} iteratee - A truth test to apply to each item in the array
+ * in parallel. The iteratee is passed a `callback(err, truthValue)` which must
+ * be called with a boolean argument once it has completed. Invoked with
+ * (item, callback).
+ * @param {Function} [callback] - A callback which is called as soon as any
+ * iteratee returns `true`, or after all the iteratee functions have finished.
+ * Result will be either `true` or `false` depending on the values of the async
+ * tests. Invoked with (err, result).
+ */
+ var someLimit = _createTester(eachOfLimit, Boolean, identity);
+
+ /**
+ * The same as [`some`]{@link module:Collections.some} but runs only a single async operation at a time.
+ *
+ * @name someSeries
+ * @static
+ * @memberOf module:Collections
+ * @method
+ * @see [async.some]{@link module:Collections.some}
+ * @alias anySeries
+ * @category Collection
+ * @param {Array|Iterable|Object} coll - A collection to iterate over.
+ * @param {Function} iteratee - A truth test to apply to each item in the array
+ * in parallel. The iteratee is passed a `callback(err, truthValue)` which must
+ * be called with a boolean argument once it has completed. Invoked with
+ * (item, callback).
+ * @param {Function} [callback] - A callback which is called as soon as any
+ * iteratee returns `true`, or after all the iteratee functions have finished.
+ * Result will be either `true` or `false` depending on the values of the async
+ * tests. Invoked with (err, result).
+ */
+ var someSeries = doLimit(someLimit, 1);
+
+ /**
+ * Sorts a list by the results of running each `coll` value through an async
+ * `iteratee`.
+ *
+ * @name sortBy
+ * @static
+ * @memberOf module:Collections
+ * @method
+ * @category Collection
+ * @param {Array|Iterable|Object} coll - A collection to iterate over.
+ * @param {Function} iteratee - A function to apply to each item in `coll`.
+ * The iteratee is passed a `callback(err, sortValue)` which must be called once
+ * it has completed with an error (which can be `null`) and a value to use as
+ * the sort criteria. Invoked with (item, callback).
+ * @param {Function} callback - A callback which is called after all the
+ * `iteratee` functions have finished, or an error occurs. Results is the items
+ * from the original `coll` sorted by the values returned by the `iteratee`
+ * calls. Invoked with (err, results).
+ * @example
+ *
+ * async.sortBy(['file1','file2','file3'], function(file, callback) {
+ * fs.stat(file, function(err, stats) {
+ * callback(err, stats.mtime);
+ * });
+ * }, function(err, results) {
+ * // results is now the original array of files sorted by
+ * // modified date
+ * });
+ *
+ * // By modifying the callback parameter the
+ * // sorting order can be influenced:
+ *
+ * // ascending order
+ * async.sortBy([1,9,3,5], function(x, callback) {
+ * callback(null, x);
+ * }, function(err,result) {
+ * // result callback
+ * });
+ *
+ * // descending order
+ * async.sortBy([1,9,3,5], function(x, callback) {
+ * callback(null, x*-1); //<- x*-1 instead of x, turns the order around
+ * }, function(err,result) {
+ * // result callback
+ * });
+ */
+ function sortBy(coll, iteratee, callback) {
+ map(coll, function (x, callback) {
+ iteratee(x, function (err, criteria) {
+ if (err) return callback(err);
+ callback(null, { value: x, criteria: criteria });
+ });
+ }, function (err, results) {
+ if (err) return callback(err);
+ callback(null, arrayMap(results.sort(comparator), baseProperty('value')));
+ });
+
+ function comparator(left, right) {
+ var a = left.criteria,
+ b = right.criteria;
+ return a < b ? -1 : a > b ? 1 : 0;
+ }
+ }
+
+ /**
+ * Sets a time limit on an asynchronous function. If the function does not call
+ * its callback within the specified milliseconds, it will be called with a
+ * timeout error. The code property for the error object will be `'ETIMEDOUT'`.
+ *
+ * @name timeout
+ * @static
+ * @memberOf module:Utils
+ * @method
+ * @category Util
+ * @param {Function} asyncFn - The asynchronous function you want to set the
+ * time limit.
+ * @param {number} milliseconds - The specified time limit.
+ * @param {*} [info] - Any variable you want attached (`string`, `object`, etc)
+ * to timeout Error for more information..
+ * @returns {Function} Returns a wrapped function that can be used with any of
+ * the control flow functions.
+ * @example
+ *
+ * async.timeout(function(callback) {
+ * doAsyncTask(callback);
+ * }, 1000);
+ */
+ function timeout(asyncFn, milliseconds, info) {
+ var originalCallback, timer;
+ var timedOut = false;
+
+ function injectedCallback() {
+ if (!timedOut) {
+ originalCallback.apply(null, arguments);
+ clearTimeout(timer);
+ }
+ }
+
+ function timeoutCallback() {
+ var name = asyncFn.name || 'anonymous';
+ var error = new Error('Callback function "' + name + '" timed out.');
+ error.code = 'ETIMEDOUT';
+ if (info) {
+ error.info = info;
+ }
+ timedOut = true;
+ originalCallback(error);
+ }
+
+ return initialParams(function (args, origCallback) {
+ originalCallback = origCallback;
+ // setup timer and call original function
+ timer = setTimeout(timeoutCallback, milliseconds);
+ asyncFn.apply(null, args.concat(injectedCallback));
+ });
+ }
- var task = tasks[taskIndex++];
- task.apply(null, args);
+ /* Built-in method references for those with the same name as other `lodash` methods. */
+ var nativeCeil = Math.ceil;
+ var nativeMax$1 = Math.max;
+ /**
+ * The base implementation of `_.range` and `_.rangeRight` which doesn't
+ * coerce arguments to numbers.
+ *
+ * @private
+ * @param {number} start The start of the range.
+ * @param {number} end The end of the range.
+ * @param {number} step The value to increment or decrement by.
+ * @param {boolean} [fromRight] Specify iterating from right to left.
+ * @returns {Array} Returns the range of numbers.
+ */
+ function baseRange(start, end, step, fromRight) {
+ var index = -1,
+ length = nativeMax$1(nativeCeil((end - start) / (step || 1)), 0),
+ result = Array(length);
+
+ while (length--) {
+ result[fromRight ? length : ++index] = start;
+ start += step;
}
+ return result;
+ }
+
+ /**
+ * The same as [times]{@link module:ControlFlow.times} but runs a maximum of `limit` async operations at a
+ * time.
+ *
+ * @name timesLimit
+ * @static
+ * @memberOf module:ControlFlow
+ * @method
+ * @see [async.times]{@link module:ControlFlow.times}
+ * @category Control Flow
+ * @param {number} count - The number of times to run the function.
+ * @param {number} limit - The maximum number of async operations at a time.
+ * @param {Function} iteratee - The function to call `n` times. Invoked with the
+ * iteration index and a callback (n, next).
+ * @param {Function} callback - see [async.map]{@link module:Collections.map}.
+ */
+ function timeLimit(count, limit, iteratee, callback) {
+ mapLimit(baseRange(0, count, 1), limit, iteratee, callback);
+ }
+
+ /**
+ * Calls the `iteratee` function `n` times, and accumulates results in the same
+ * manner you would use with [map]{@link module:Collections.map}.
+ *
+ * @name times
+ * @static
+ * @memberOf module:ControlFlow
+ * @method
+ * @see [async.map]{@link module:Collections.map}
+ * @category Control Flow
+ * @param {number} n - The number of times to run the function.
+ * @param {Function} iteratee - The function to call `n` times. Invoked with the
+ * iteration index and a callback (n, next).
+ * @param {Function} callback - see {@link module:Collections.map}.
+ * @example
+ *
+ * // Pretend this is some complicated async factory
+ * var createUser = function(id, callback) {
+ * callback(null, {
+ * id: 'user' + id
+ * });
+ * };
+ *
+ * // generate 5 users
+ * async.times(5, function(n, next) {
+ * createUser(n, function(err, user) {
+ * next(err, user);
+ * });
+ * }, function(err, users) {
+ * // we should now have 5 users
+ * });
+ */
+ var times = doLimit(timeLimit, Infinity);
+
+ /**
+ * The same as [times]{@link module:ControlFlow.times} but runs only a single async operation at a time.
+ *
+ * @name timesSeries
+ * @static
+ * @memberOf module:ControlFlow
+ * @method
+ * @see [async.times]{@link module:ControlFlow.times}
+ * @category Control Flow
+ * @param {number} n - The number of times to run the function.
+ * @param {Function} iteratee - The function to call `n` times. Invoked with the
+ * iteration index and a callback (n, next).
+ * @param {Function} callback - see {@link module:Collections.map}.
+ */
+ var timesSeries = doLimit(timeLimit, 1);
+
+ /**
+ * A relative of `reduce`. Takes an Object or Array, and iterates over each
+ * element in series, each step potentially mutating an `accumulator` value.
+ * The type of the accumulator defaults to the type of collection passed in.
+ *
+ * @name transform
+ * @static
+ * @memberOf module:Collections
+ * @method
+ * @category Collection
+ * @param {Array|Iterable|Object} coll - A collection to iterate over.
+ * @param {*} [accumulator] - The initial state of the transform. If omitted,
+ * it will default to an empty Object or Array, depending on the type of `coll`
+ * @param {Function} iteratee - A function applied to each item in the
+ * collection that potentially modifies the accumulator. The `iteratee` is
+ * passed a `callback(err)` which accepts an optional error as its first
+ * argument. If an error is passed to the callback, the transform is stopped
+ * and the main `callback` is immediately called with the error.
+ * Invoked with (accumulator, item, key, callback).
+ * @param {Function} [callback] - A callback which is called after all the
+ * `iteratee` functions have finished. Result is the transformed accumulator.
+ * Invoked with (err, result).
+ * @example
+ *
+ * async.transform([1,2,3], function(acc, item, index, callback) {
+ * // pointless async:
+ * process.nextTick(function() {
+ * acc.push(item * 2)
+ * callback(null)
+ * });
+ * }, function(err, result) {
+ * // result is now equal to [2, 4, 6]
+ * });
+ *
+ * @example
+ *
+ * async.transform({a: 1, b: 2, c: 3}, function (obj, val, key, callback) {
+ * setImmediate(function () {
+ * obj[key] = val * 2;
+ * callback();
+ * })
+ * }, function (err, result) {
+ * // result is equal to {a: 2, b: 4, c: 6}
+ * })
+ */
+ function transform(coll, accumulator, iteratee, callback) {
+ if (arguments.length === 3) {
+ callback = iteratee;
+ iteratee = accumulator;
+ accumulator = isArray(coll) ? [] : {};
+ }
+ callback = once(callback || noop);
+
+ eachOf(coll, function (v, k, cb) {
+ iteratee(accumulator, v, k, cb);
+ }, function (err) {
+ callback(err, accumulator);
+ });
+ }
+
+ /**
+ * Undoes a [memoize]{@link module:Utils.memoize}d function, reverting it to the original,
+ * unmemoized form. Handy for testing.
+ *
+ * @name unmemoize
+ * @static
+ * @memberOf module:Utils
+ * @method
+ * @see [async.memoize]{@link module:Utils.memoize}
+ * @category Util
+ * @param {Function} fn - the memoized function
+ * @returns {Function} a function that calls the original unmemoized function
+ */
+ function unmemoize(fn) {
+ return function () {
+ return (fn.unmemoized || fn).apply(null, arguments);
+ };
+ }
+
+ /**
+ * Repeatedly call `fn`, while `test` returns `true`. Calls `callback` when
+ * stopped, or an error occurs.
+ *
+ * @name whilst
+ * @static
+ * @memberOf module:ControlFlow
+ * @method
+ * @category Control Flow
+ * @param {Function} test - synchronous truth test to perform before each
+ * execution of `fn`. Invoked with ().
+ * @param {Function} iteratee - A function which is called each time `test` passes.
+ * The function is passed a `callback(err)`, which must be called once it has
+ * completed with an optional `err` argument. Invoked with (callback).
+ * @param {Function} [callback] - A callback which is called after the test
+ * function has failed and repeated execution of `fn` has stopped. `callback`
+ * will be passed an error and any arguments passed to the final `fn`'s
+ * callback. Invoked with (err, [results]);
+ * @returns undefined
+ * @example
+ *
+ * var count = 0;
+ * async.whilst(
+ * function() { return count < 5; },
+ * function(callback) {
+ * count++;
+ * setTimeout(function() {
+ * callback(null, count);
+ * }, 1000);
+ * },
+ * function (err, n) {
+ * // 5 seconds have passed, n = 5
+ * }
+ * );
+ */
+ function whilst(test, iteratee, callback) {
+ callback = onlyOnce(callback || noop);
+ if (!test()) return callback(null);
+ var next = rest(function (err, args) {
+ if (err) return callback(err);
+ if (test()) return iteratee(next);
+ callback.apply(null, [null].concat(args));
+ });
+ iteratee(next);
+ }
+
+ /**
+ * Repeatedly call `fn` until `test` returns `true`. Calls `callback` when
+ * stopped, or an error occurs. `callback` will be passed an error and any
+ * arguments passed to the final `fn`'s callback.
+ *
+ * The inverse of [whilst]{@link module:ControlFlow.whilst}.
+ *
+ * @name until
+ * @static
+ * @memberOf module:ControlFlow
+ * @method
+ * @see [async.whilst]{@link module:ControlFlow.whilst}
+ * @category Control Flow
+ * @param {Function} test - synchronous truth test to perform before each
+ * execution of `fn`. Invoked with ().
+ * @param {Function} fn - A function which is called each time `test` fails.
+ * The function is passed a `callback(err)`, which must be called once it has
+ * completed with an optional `err` argument. Invoked with (callback).
+ * @param {Function} [callback] - A callback which is called after the test
+ * function has passed and repeated execution of `fn` has stopped. `callback`
+ * will be passed an error and any arguments passed to the final `fn`'s
+ * callback. Invoked with (err, [results]);
+ */
+ function until(test, fn, callback) {
+ whilst(function () {
+ return !test.apply(this, arguments);
+ }, fn, callback);
+ }
+
+ /**
+ * Runs the `tasks` array of functions in series, each passing their results to
+ * the next in the array. However, if any of the `tasks` pass an error to their
+ * own callback, the next function is not executed, and the main `callback` is
+ * immediately called with the error.
+ *
+ * @name waterfall
+ * @static
+ * @memberOf module:ControlFlow
+ * @method
+ * @category Control Flow
+ * @param {Array} tasks - An array of functions to run, each function is passed
+ * a `callback(err, result1, result2, ...)` it must call on completion. The
+ * first argument is an error (which can be `null`) and any further arguments
+ * will be passed as arguments in order to the next task.
+ * @param {Function} [callback] - An optional callback to run once all the
+ * functions have completed. This will be passed the results of the last task's
+ * callback. Invoked with (err, [results]).
+ * @returns undefined
+ * @example
+ *
+ * async.waterfall([
+ * function(callback) {
+ * callback(null, 'one', 'two');
+ * },
+ * function(arg1, arg2, callback) {
+ * // arg1 now equals 'one' and arg2 now equals 'two'
+ * callback(null, 'three');
+ * },
+ * function(arg1, callback) {
+ * // arg1 now equals 'three'
+ * callback(null, 'done');
+ * }
+ * ], function (err, result) {
+ * // result now equals 'done'
+ * });
+ *
+ * // Or, with named functions:
+ * async.waterfall([
+ * myFirstFunction,
+ * mySecondFunction,
+ * myLastFunction,
+ * ], function (err, result) {
+ * // result now equals 'done'
+ * });
+ * function myFirstFunction(callback) {
+ * callback(null, 'one', 'two');
+ * }
+ * function mySecondFunction(arg1, arg2, callback) {
+ * // arg1 now equals 'one' and arg2 now equals 'two'
+ * callback(null, 'three');
+ * }
+ * function myLastFunction(arg1, callback) {
+ * // arg1 now equals 'three'
+ * callback(null, 'done');
+ * }
+ */
+ function waterfall (tasks, callback) {
+ callback = once(callback || noop);
+ if (!isArray(tasks)) return callback(new Error('First argument to waterfall must be an array of functions'));
+ if (!tasks.length) return callback();
+ var taskIndex = 0;
+
+ function nextTask(args) {
+ if (taskIndex === tasks.length) {
+ return callback.apply(null, [null].concat(args));
+ }
+
+ var taskCallback = onlyOnce(rest(function (err, args) {
+ if (err) {
+ return callback.apply(null, [err].concat(args));
+ }
+ nextTask(args);
+ }));
+
+ args.push(taskCallback);
+
+ var task = tasks[taskIndex++];
+ task.apply(null, args);
+ }
+
+ nextTask([]);
+ }
+
+ var index = {
+ applyEach: applyEach,
+ applyEachSeries: applyEachSeries,
+ apply: apply$1,
+ asyncify: asyncify,
+ auto: auto,
+ autoInject: autoInject,
+ cargo: cargo,
+ compose: compose,
+ concat: concat,
+ concatSeries: concatSeries,
+ constant: constant,
+ detect: detect,
+ detectLimit: detectLimit,
+ detectSeries: detectSeries,
+ dir: dir,
+ doDuring: doDuring,
+ doUntil: doUntil,
+ doWhilst: doWhilst,
+ during: during,
+ each: eachLimit,
+ eachLimit: eachLimit$1,
+ eachOf: eachOf,
+ eachOfLimit: eachOfLimit,
+ eachOfSeries: eachOfSeries,
+ eachSeries: eachSeries,
+ ensureAsync: ensureAsync,
+ every: every,
+ everyLimit: everyLimit,
+ everySeries: everySeries,
+ filter: filter,
+ filterLimit: filterLimit,
+ filterSeries: filterSeries,
+ forever: forever,
+ log: log,
+ map: map,
+ mapLimit: mapLimit,
+ mapSeries: mapSeries,
+ mapValues: mapValues,
+ mapValuesLimit: mapValuesLimit,
+ mapValuesSeries: mapValuesSeries,
+ memoize: memoize,
+ nextTick: nextTick,
+ parallel: parallelLimit,
+ parallelLimit: parallelLimit$1,
+ priorityQueue: priorityQueue,
+ queue: queue$1,
+ race: race,
+ reduce: reduce,
+ reduceRight: reduceRight,
+ reflect: reflect,
+ reflectAll: reflectAll,
+ reject: reject,
+ rejectLimit: rejectLimit,
+ rejectSeries: rejectSeries,
+ retry: retry,
+ retryable: retryable,
+ seq: seq,
+ series: series,
+ setImmediate: setImmediate$1,
+ some: some,
+ someLimit: someLimit,
+ someSeries: someSeries,
+ sortBy: sortBy,
+ timeout: timeout,
+ times: times,
+ timesLimit: timeLimit,
+ timesSeries: timesSeries,
+ transform: transform,
+ unmemoize: unmemoize,
+ until: until,
+ waterfall: waterfall,
+ whilst: whilst,
+
+ // aliases
+ all: every,
+ any: some,
+ forEach: eachLimit,
+ forEachSeries: eachSeries,
+ forEachLimit: eachLimit$1,
+ forEachOf: eachOf,
+ forEachOfSeries: eachOfSeries,
+ forEachOfLimit: eachOfLimit,
+ inject: reduce,
+ foldl: reduce,
+ foldr: reduceRight,
+ select: filter,
+ selectLimit: filterLimit,
+ selectSeries: filterSeries,
+ wrapSync: asyncify
+ };
- nextTask([]);
- }
-
- var index = {
- applyEach: applyEach,
- applyEachSeries: applyEachSeries,
- apply: apply$1,
- asyncify: asyncify,
- auto: auto,
- autoInject: autoInject,
- cargo: cargo,
- compose: compose,
- concat: concat,
- concatSeries: concatSeries,
- constant: constant,
- detect: detect,
- detectLimit: detectLimit,
- detectSeries: detectSeries,
- dir: dir,
- doDuring: doDuring,
- doUntil: doUntil,
- doWhilst: doWhilst,
- during: during,
- each: each,
- eachLimit: eachLimit,
- eachOf: eachOf,
- eachOfLimit: eachOfLimit,
- eachOfSeries: eachOfSeries,
- eachSeries: eachSeries,
- ensureAsync: ensureAsync,
- every: every,
- everyLimit: everyLimit,
- everySeries: everySeries,
- filter: filter,
- filterLimit: filterLimit,
- filterSeries: filterSeries,
- forever: forever,
- log: log,
- map: map,
- mapLimit: mapLimit,
- mapSeries: mapSeries,
- mapValues: mapValues,
- mapValuesLimit: mapValuesLimit,
- mapValuesSeries: mapValuesSeries,
- memoize: memoize,
- nextTick: nextTick,
- parallel: parallel,
- parallelLimit: parallelLimit,
- priorityQueue: priorityQueue,
- queue: queue$1,
- race: race,
- reduce: reduce,
- reduceRight: reduceRight,
- reflect: reflect,
- reflectAll: reflectAll,
- reject: reject,
- rejectLimit: rejectLimit,
- rejectSeries: rejectSeries,
- retry: retry,
- retryable: retryable,
- seq: seq,
- series: series,
- setImmediate: setImmediate$1,
- some: some,
- someLimit: someLimit,
- someSeries: someSeries,
- sortBy: sortBy,
- timeout: timeout,
- times: times,
- timesLimit: timeLimit,
- timesSeries: timesSeries,
- transform: transform,
- unmemoize: unmemoize,
- until: until,
- waterfall: waterfall,
- whilst: whilst,
-
- // aliases
- all: every,
- any: some,
- forEach: each,
- forEachSeries: eachSeries,
- forEachLimit: eachLimit,
- forEachOf: eachOf,
- forEachOfSeries: eachOfSeries,
- forEachOfLimit: eachOfLimit,
- inject: reduce,
- foldl: reduce,
- foldr: reduceRight,
- select: filter,
- selectLimit: filterLimit,
- selectSeries: filterSeries,
- wrapSync: asyncify
- };
-
- exports['default'] = index;
- exports.applyEach = applyEach;
- exports.applyEachSeries = applyEachSeries;
- exports.apply = apply$1;
- exports.asyncify = asyncify;
- exports.auto = auto;
- exports.autoInject = autoInject;
- exports.cargo = cargo;
- exports.compose = compose;
- exports.concat = concat;
- exports.concatSeries = concatSeries;
- exports.constant = constant;
- exports.detect = detect;
- exports.detectLimit = detectLimit;
- exports.detectSeries = detectSeries;
- exports.dir = dir;
- exports.doDuring = doDuring;
- exports.doUntil = doUntil;
- exports.doWhilst = doWhilst;
- exports.during = during;
- exports.each = each;
- exports.eachLimit = eachLimit;
- exports.eachOf = eachOf;
- exports.eachOfLimit = eachOfLimit;
- exports.eachOfSeries = eachOfSeries;
- exports.eachSeries = eachSeries;
- exports.ensureAsync = ensureAsync;
- exports.every = every;
- exports.everyLimit = everyLimit;
- exports.everySeries = everySeries;
- exports.filter = filter;
- exports.filterLimit = filterLimit;
- exports.filterSeries = filterSeries;
- exports.forever = forever;
- exports.log = log;
- exports.map = map;
- exports.mapLimit = mapLimit;
- exports.mapSeries = mapSeries;
- exports.mapValues = mapValues;
- exports.mapValuesLimit = mapValuesLimit;
- exports.mapValuesSeries = mapValuesSeries;
- exports.memoize = memoize;
- exports.nextTick = nextTick;
- exports.parallel = parallel;
- exports.parallelLimit = parallelLimit;
- exports.priorityQueue = priorityQueue;
- exports.queue = queue$1;
- exports.race = race;
- exports.reduce = reduce;
- exports.reduceRight = reduceRight;
- exports.reflect = reflect;
- exports.reflectAll = reflectAll;
- exports.reject = reject;
- exports.rejectLimit = rejectLimit;
- exports.rejectSeries = rejectSeries;
- exports.retry = retry;
- exports.retryable = retryable;
- exports.seq = seq;
- exports.series = series;
- exports.setImmediate = setImmediate$1;
- exports.some = some;
- exports.someLimit = someLimit;
- exports.someSeries = someSeries;
- exports.sortBy = sortBy;
- exports.timeout = timeout;
- exports.times = times;
- exports.timesLimit = timeLimit;
- exports.timesSeries = timesSeries;
- exports.transform = transform;
- exports.unmemoize = unmemoize;
- exports.until = until;
- exports.waterfall = waterfall;
- exports.whilst = whilst;
- exports.all = every;
- exports.allLimit = everyLimit;
- exports.allSeries = everySeries;
- exports.any = some;
- exports.anyLimit = someLimit;
- exports.anySeries = someSeries;
- exports.find = detect;
- exports.findLimit = detectLimit;
- exports.findSeries = detectSeries;
- exports.forEach = each;
- exports.forEachSeries = eachSeries;
- exports.forEachLimit = eachLimit;
- exports.forEachOf = eachOf;
- exports.forEachOfSeries = eachOfSeries;
- exports.forEachOfLimit = eachOfLimit;
- exports.inject = reduce;
- exports.foldl = reduce;
- exports.foldr = reduceRight;
- exports.select = filter;
- exports.selectLimit = filterLimit;
- exports.selectSeries = filterSeries;
- exports.wrapSync = asyncify;
+ exports['default'] = index;
+ exports.applyEach = applyEach;
+ exports.applyEachSeries = applyEachSeries;
+ exports.apply = apply$1;
+ exports.asyncify = asyncify;
+ exports.auto = auto;
+ exports.autoInject = autoInject;
+ exports.cargo = cargo;
+ exports.compose = compose;
+ exports.concat = concat;
+ exports.concatSeries = concatSeries;
+ exports.constant = constant;
+ exports.detect = detect;
+ exports.detectLimit = detectLimit;
+ exports.detectSeries = detectSeries;
+ exports.dir = dir;
+ exports.doDuring = doDuring;
+ exports.doUntil = doUntil;
+ exports.doWhilst = doWhilst;
+ exports.during = during;
+ exports.each = eachLimit;
+ exports.eachLimit = eachLimit$1;
+ exports.eachOf = eachOf;
+ exports.eachOfLimit = eachOfLimit;
+ exports.eachOfSeries = eachOfSeries;
+ exports.eachSeries = eachSeries;
+ exports.ensureAsync = ensureAsync;
+ exports.every = every;
+ exports.everyLimit = everyLimit;
+ exports.everySeries = everySeries;
+ exports.filter = filter;
+ exports.filterLimit = filterLimit;
+ exports.filterSeries = filterSeries;
+ exports.forever = forever;
+ exports.log = log;
+ exports.map = map;
+ exports.mapLimit = mapLimit;
+ exports.mapSeries = mapSeries;
+ exports.mapValues = mapValues;
+ exports.mapValuesLimit = mapValuesLimit;
+ exports.mapValuesSeries = mapValuesSeries;
+ exports.memoize = memoize;
+ exports.nextTick = nextTick;
+ exports.parallel = parallelLimit;
+ exports.parallelLimit = parallelLimit$1;
+ exports.priorityQueue = priorityQueue;
+ exports.queue = queue$1;
+ exports.race = race;
+ exports.reduce = reduce;
+ exports.reduceRight = reduceRight;
+ exports.reflect = reflect;
+ exports.reflectAll = reflectAll;
+ exports.reject = reject;
+ exports.rejectLimit = rejectLimit;
+ exports.rejectSeries = rejectSeries;
+ exports.retry = retry;
+ exports.retryable = retryable;
+ exports.seq = seq;
+ exports.series = series;
+ exports.setImmediate = setImmediate$1;
+ exports.some = some;
+ exports.someLimit = someLimit;
+ exports.someSeries = someSeries;
+ exports.sortBy = sortBy;
+ exports.timeout = timeout;
+ exports.times = times;
+ exports.timesLimit = timeLimit;
+ exports.timesSeries = timesSeries;
+ exports.transform = transform;
+ exports.unmemoize = unmemoize;
+ exports.until = until;
+ exports.waterfall = waterfall;
+ exports.whilst = whilst;
+ exports.all = every;
+ exports.allLimit = everyLimit;
+ exports.allSeries = everySeries;
+ exports.any = some;
+ exports.anyLimit = someLimit;
+ exports.anySeries = someSeries;
+ exports.find = detect;
+ exports.findLimit = detectLimit;
+ exports.findSeries = detectSeries;
+ exports.forEach = eachLimit;
+ exports.forEachSeries = eachSeries;
+ exports.forEachLimit = eachLimit$1;
+ exports.forEachOf = eachOf;
+ exports.forEachOfSeries = eachOfSeries;
+ exports.forEachOfLimit = eachOfLimit;
+ exports.inject = reduce;
+ exports.foldl = reduce;
+ exports.foldr = reduceRight;
+ exports.select = filter;
+ exports.selectLimit = filterLimit;
+ exports.selectSeries = filterSeries;
+ exports.wrapSync = asyncify;
})); \ No newline at end of file
diff --git a/dist/async.min.js b/dist/async.min.js
index de5316f..4d5d88a 100644
--- a/dist/async.min.js
+++ b/dist/async.min.js
@@ -1,2 +1,2 @@
-!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(n.async=n.async||{})}(this,function(n){"use strict";function t(n,t,e){var r=e.length;switch(r){case 0:return n.call(t);case 1:return n.call(t,e[0]);case 2:return n.call(t,e[0],e[1]);case 3:return n.call(t,e[0],e[1],e[2])}return n.apply(t,e)}function e(n){var t=typeof n;return!!n&&("object"==t||"function"==t)}function r(n){var t=e(n)?et.call(n):"";return t==Zn||t==nt}function u(n){return!!n&&"object"==typeof n}function i(n){return"symbol"==typeof n||u(n)&&it.call(n)==rt}function o(n){if("number"==typeof n)return n;if(i(n))return ot;if(e(n)){var t=r(n.valueOf)?n.valueOf():n;n=e(t)?t+"":t}if("string"!=typeof n)return 0===n?n:+n;n=n.replace(ct,"");var u=ft.test(n);return u||lt.test(n)?st(n.slice(2),u?2:8):at.test(n)?ot:+n}function c(n){if(!n)return 0===n?n:0;if(n=o(n),n===pt||n===-pt){var t=0>n?-1:1;return t*ht}return n===n?n:0}function a(n){var t=c(n),e=t%1;return t===t?e?t-e:t:0}function f(n,e){if("function"!=typeof n)throw new TypeError(vt);return e=yt(void 0===e?n.length-1:a(e),0),function(){for(var r=arguments,u=-1,i=yt(r.length-e,0),o=Array(i);++u<i;)o[u]=r[e+u];switch(e){case 0:return n.call(this,o);case 1:return n.call(this,r[0],o);case 2:return n.call(this,r[0],r[1],o)}var c=Array(e+1);for(u=-1;++u<e;)c[u]=r[u];return c[e]=o,t(n,this,c)}}function l(n){return f(function(t){var e=t.pop();n.call(this,t,e)})}function s(n){return f(function(t,e){var r=l(function(e,r){var u=this;return n(t,function(n,t){n.apply(u,e.concat([t]))},r)});return e.length?r.apply(this,e):r})}function p(){}function h(n){return function(){if(null!==n){var t=n;n=null,t.apply(this,arguments)}}}function v(n){return function(t){return null==t?void 0:t[n]}}function y(n){return"number"==typeof n&&n>-1&&n%1==0&&dt>=n}function m(n){return null!=n&&y(mt(n))&&!r(n)}function d(n){return gt&&n[gt]&&n[gt]()}function g(n){return bt(Object(n))}function b(n,t){return null!=n&&(jt.call(n,t)||"object"==typeof n&&t in n&&null===g(n))}function S(n){return kt(Object(n))}function j(n,t){for(var e=-1,r=Array(n);++e<n;)r[e]=t(e);return r}function k(n){return u(n)&&m(n)}function w(n){return k(n)&&Lt.call(n,"callee")&&(!Ot.call(n,"callee")||xt.call(n)==wt)}function E(n){return"string"==typeof n||!At(n)&&u(n)&&Tt.call(n)==It}function L(n){var t=n?n.length:void 0;return y(t)&&(At(n)||E(n)||w(n))?j(t,String):null}function x(n,t){return t=null==t?Ft:t,!!t&&("number"==typeof n||$t.test(n))&&n>-1&&n%1==0&&t>n}function O(n){var t=n&&n.constructor,e="function"==typeof t&&t.prototype||zt;return n===e}function A(n){var t=O(n);if(!t&&!m(n))return S(n);var e=L(n),r=!!e,u=e||[],i=u.length;for(var o in n)!b(n,o)||r&&("length"==o||x(o,i))||t&&"constructor"==o||u.push(o);return u}function I(n){var t,e=-1;if(m(n))return t=n.length,function(){return e++,t>e?{value:n[e],key:e}:null};var r=d(n);if(r)return function(){var n=r.next();return n.done?null:(e++,{value:n.value,key:e})};var u=A(n);return t=u.length,function(){e++;var r=u[e];return t>e?{value:n[r],key:r}:null}}function _(n){return function(){if(null===n)throw new Error("Callback was already called.");var t=n;n=null,t.apply(this,arguments)}}function T(n){return function(t,e,r){r=h(r||p),t=t||[];var u=I(t);if(0>=n)return r(null);var i=!1,o=0,c=!1;!function a(){if(i&&0>=o)return r(null);for(;n>o&&!c;){var t=u();if(null===t)return i=!0,void(0>=o&&r(null));o+=1,e(t.value,t.key,_(function(n){o-=1,n?(r(n),c=!0):a()}))}}()}}function F(n){return function(t,e,r,u){return n(T(e),t,r,u)}}function $(n,t,e,r){r=h(r||p),t=t||[];var u=[],i=0;n(t,function(n,t,r){var o=i++;e(n,function(n,t){u[o]=t,r(n)})},function(n){r(n,u)})}function z(n,t){return function(e,r,u){return n(e,t,r,u)}}function B(n){return l(function(t,r){var u;try{u=n.apply(this,t)}catch(i){return r(i)}e(u)&&"function"==typeof u.then?u.then(function(n){r(null,n)},function(n){r(n.message?n:new Error(n))}):r(null,u)})}function M(n,t){for(var e=-1,r=n?n.length:0;++e<r&&t(n[e],e,n)!==!1;);return n}function V(n){return function(t,e,r){for(var u=-1,i=Object(t),o=r(t),c=o.length;c--;){var a=o[n?c:++u];if(e(i[a],a,i)===!1)break}return t}}function q(n,t){return n&&Pt(n,t,A)}function C(n,t,e){for(var r=n.length,u=t+(e?1:-1);e?u--:++u<r;){var i=n[u];if(i!==i)return u}return-1}function D(n,t,e){if(t!==t)return C(n,e);for(var r=e-1,u=n.length;++r<u;)if(n[r]===t)return r;return-1}function P(n,t,e){function r(n,t){b.push(function(){c(n,t)})}function u(){if(0===b.length&&0===m)return e(null,y);for(;b.length&&t>m;){var n=b.shift();n()}}function i(n,t){var e=g[n];e||(e=g[n]=[]),e.push(t)}function o(n){var t=g[n]||[];M(t,function(n){n()}),u()}function c(n,t){if(!d){var r=_(f(function(t,r){if(m--,r.length<=1&&(r=r[0]),t){var u={};q(y,function(n,t){u[t]=n}),u[n]=r,d=!0,g=[],e(t,u)}else y[n]=r,o(n)}));m++;var u=t[t.length-1];t.length>1?u(y,r):u(r)}}function a(){for(var n,t=0;S.length;)n=S.pop(),t++,M(l(n),function(n){--j[n]||S.push(n)});if(t!==v)throw new Error("async.auto cannot execute tasks due to a recursive dependency")}function l(t){var e=[];return q(n,function(n,r){At(n)&&D(n,t,0)>=0&&e.push(r)}),e}"function"==typeof t&&(e=t,t=null),e=h(e||p);var s=A(n),v=s.length;if(!v)return e(null);t||(t=v);var y={},m=0,d=!1,g={},b=[],S=[],j={};q(n,function(t,e){if(!At(t))return r(e,[t]),void S.push(e);var u=t.slice(0,t.length-1),o=u.length;return 0===o?(r(e,t),void S.push(e)):(j[e]=o,void M(u,function(c){if(!n[c])throw new Error("async.auto task `"+e+"` has a non-existent dependency in "+u.join(", "));i(c,function(){o--,0===o&&r(e,t)})}))}),a(),u()}function R(n,t){for(var e=-1,r=n?n.length:0,u=Array(r);++e<r;)u[e]=t(n[e],e,n);return u}function U(n,t){var e=-1,r=n.length;for(t||(t=Array(r));++e<r;)t[e]=n[e];return t}function N(n){return n&&n.Object===Object?n:null}function Q(n){if("string"==typeof n)return n;if(i(n))return Jt?Jt.call(n):"";var t=n+"";return"0"==t&&1/n==-Gt?"-0":t}function W(n,t,e){var r=-1,u=n.length;0>t&&(t=-t>u?0:u+t),e=e>u?u:e,0>e&&(e+=u),u=t>e?0:e-t>>>0,t>>>=0;for(var i=Array(u);++r<u;)i[r]=n[r+t];return i}function G(n,t,e){var r=n.length;return e=void 0===e?r:e,!t&&e>=r?n:W(n,t,e)}function H(n,t){for(var e=n.length;e--&&D(t,n[e],0)>-1;);return e}function J(n,t){for(var e=-1,r=n.length;++e<r&&D(t,n[e],0)>-1;);return e}function K(n){return n.match(he)}function X(n){return null==n?"":Q(n)}function Y(n,t,e){if(n=X(n),n&&(e||void 0===t))return n.replace(ve,"");if(!n||!(t=Q(t)))return n;var r=K(n),u=K(t),i=J(r,u),o=H(r,u)+1;return G(r,i,o).join("")}function Z(n){return n=n.toString().replace(ge,""),n=n.match(ye)[2].replace(" ",""),n=n?n.split(me):[],n=n.map(function(n){return Y(n.replace(de,""))})}function nn(n,t){var e={};q(n,function(n,t){function r(t,e){var r=R(u,function(n){return t[n]});r.push(e),n.apply(null,r)}var u;if(At(n))u=U(n),n=u.pop(),e[t]=u.concat(u.length>0?r:n);else if(1===n.length)e[t]=n;else{if(u=Z(n),0===n.length&&0===u.length)throw new Error("autoInject task functions require explicit parameters.");u.pop(),e[t]=u.concat(r)}}),P(e,t)}function tn(n){setTimeout(n,0)}function en(n){return f(function(t,e){n(function(){t.apply(null,e)})})}function rn(){this.head=this.tail=null,this.length=0}function un(n,t){n.length=1,n.head=n.tail=t}function on(n,t,e){function r(n,t,e){if(null!=e&&"function"!=typeof e)throw new Error("task callback must be a function");return c.started=!0,At(n)||(n=[n]),0===n.length&&c.idle()?je(function(){c.drain()}):(M(n,function(n){var r={data:n,callback:e||p};t?c._tasks.unshift(r):c._tasks.push(r)}),void je(c.process))}function u(n){return f(function(t){i-=1,M(n,function(n){M(o,function(t,e){return t===n?(o.splice(e,1),!1):void 0}),n.callback.apply(n,t),null!=t[0]&&c.error(t[0],n.data)}),i<=c.concurrency-c.buffer&&c.unsaturated(),c.idle()&&c.drain(),c.process()})}if(null==t)t=1;else if(0===t)throw new Error("Concurrency must not be zero");var i=0,o=[],c={_tasks:new rn,concurrency:t,payload:e,saturated:p,unsaturated:p,buffer:t/4,empty:p,drain:p,error:p,started:!1,paused:!1,push:function(n,t){r(n,!1,t)},kill:function(){c.drain=p,c._tasks.empty()},unshift:function(n,t){r(n,!0,t)},process:function(){for(;!c.paused&&i<c.concurrency&&c._tasks.length;){var t=[],e=[],r=c._tasks.length;c.payload&&(r=Math.min(r,c.payload));for(var a=0;r>a;a++){var f=c._tasks.shift();t.push(f),e.push(f.data)}0===c._tasks.length&&c.empty(),i+=1,o.push(t[0]),i===c.concurrency&&c.saturated();var l=_(u(t));n(e,l)}},length:function(){return c._tasks.length},running:function(){return i},workersList:function(){return o},idle:function(){return c._tasks.length+i===0},pause:function(){c.paused=!0},resume:function(){if(c.paused!==!1){c.paused=!1;for(var n=Math.min(c.concurrency,c._tasks.length),t=1;n>=t;t++)je(c.process)}}};return c}function cn(n,t){return on(n,1,t)}function an(n,t,e,r){T(t)(n,e,r)}function fn(n,t,e,r){r=h(r||p),we(n,function(n,r,u){e(t,n,function(n,e){t=e,u(n)})},function(n){r(n,t)})}function ln(n,t,e,r){var u=[];n(t,function(n,t,r){e(n,function(n,t){u=u.concat(t||[]),r(n)})},function(n){r(n,u)})}function sn(n){return function(t,e,r){return n(xe,t,e,r)}}function pn(n){return function(t,e,r){return n(we,t,e,r)}}function hn(n){return n}function vn(n,t,e){return function(r,u,i,o){function c(n){o&&(n?o(n):o(null,e(!1)))}function a(n,r,u){return o?void i(n,function(r,c){o&&(r?(o(r),o=i=!1):t(c)&&(o(null,e(!0,n)),o=i=!1)),u()}):u()}arguments.length>3?(o=o||p,n(r,u,a,c)):(o=i,o=o||p,i=u,n(r,a,c))}}function yn(n,t){return t}function mn(n){return f(function(t,e){t.apply(null,e.concat([f(function(t,e){"object"==typeof console&&(t?console.error&&console.error(t):console[n]&&M(e,function(t){console[n](t)}))})]))})}function dn(n,t,e){function r(t,r){return t?e(t):r?void n(u):e(null)}e=_(e||p);var u=f(function(n,u){return n?e(n):(u.push(r),void t.apply(this,u))});r(null,!0)}function gn(n,t,e){e=_(e||p);var r=f(function(u,i){return u?e(u):t.apply(this,i)?n(r):void e.apply(null,[null].concat(i))});n(r)}function bn(n,t,e){gn(n,function(){return!t.apply(this,arguments)},e)}function Sn(n,t,e){function r(t){return t?e(t):void n(u)}function u(n,u){return n?e(n):u?void t(r):e(null)}e=_(e||p),n(u)}function jn(n){return function(t,e,r){return n(t,r)}}function kn(n,t,e,r){T(t)(n,jn(e),r)}function wn(n){return l(function(t,e){var r=!0;t.push(function(){var n=arguments;r?je(function(){e.apply(null,n)}):e.apply(null,n)}),n.apply(this,t),r=!1})}function En(n){return!n}function Ln(n,t,e,r){r=h(r||p);var u=[];n(t,function(n,t,r){e(n,function(e,i){e?r(e):(i&&u.push({index:t,value:n}),r())})},function(n){n?r(n):r(null,R(u.sort(function(n,t){return n.index-t.index}),v("value")))})}function xn(n,t){function e(n){return n?r(n):void u(e)}var r=_(t||p),u=wn(n);e()}function On(n,t,e,r){r=h(r||p);var u={};an(n,t,function(n,t,r){e(n,t,function(n,e){return n?r(n):(u[t]=e,void r())})},function(n){r(n,u)})}function An(n,t){return t in n}function In(n,t){var e=Object.create(null),r=Object.create(null);t=t||hn;var u=l(function(u,i){var o=t.apply(null,u);An(e,o)?je(function(){i.apply(null,e[o])}):An(r,o)?r[o].push(i):(r[o]=[i],n.apply(null,u.concat([f(function(n){e[o]=n;var t=r[o];delete r[o];for(var u=0,i=t.length;i>u;u++)t[u].apply(null,n)})])))});return u.memo=e,u.unmemoized=n,u}function _n(n,t,e){e=e||p;var r=m(t)?[]:{};n(t,function(n,t,e){n(f(function(n,u){u.length<=1&&(u=u[0]),r[t]=u,e(n)}))},function(n){e(n,r)})}function Tn(n,t,e){_n(T(t),n,e)}function Fn(n,t){return on(function(t,e){n(t[0],e)},t,1)}function $n(n,t){var e=Fn(n,t);return e.push=function(n,t,r){if(null==r&&(r=p),"function"!=typeof r)throw new Error("task callback must be a function");if(e.started=!0,At(n)||(n=[n]),0===n.length)return je(function(){e.drain()});t=t||0;for(var u=e._tasks.head;u&&t>=u.priority;)u=u.next;M(n,function(n){var i={data:n,priority:t,callback:r};u?e._tasks.insertBefore(u,i):e._tasks.push(i)}),je(e.process)},delete e.unshift,e}function zn(n,t){return t=h(t||p),At(n)?n.length?void M(n,function(n){n(t)}):t():t(new TypeError("First argument to race must be an array of functions"))}function Bn(n,t,e,r){var u=Ge.call(n).reverse();fn(u,t,e,r)}function Mn(n){return l(function(t,e){return t.push(f(function(n,t){if(n)e(null,{error:n});else{var r=null;1===t.length?r=t[0]:t.length>1&&(r=t),e(null,{value:r})}})),n.apply(this,t)})}function Vn(n,t,e,r){Ln(n,t,function(n,t){e(n,function(n,e){n?t(n):t(null,!e)})},r)}function qn(n){var t;return At(n)?t=R(n,Mn):(t={},q(n,function(n,e){t[e]=Mn.call(this,n)})),t}function Cn(n){return function(){return n}}function Dn(n,t,e){function r(n,t){if("object"==typeof t)n.times=+t.times||i,n.intervalFunc="function"==typeof t.interval?t.interval:Cn(+t.interval||o);else{if("number"!=typeof t&&"string"!=typeof t)throw new Error("Invalid arguments for async.retry");n.times=+t||i}}function u(){t(function(n){n&&a++<c.times?setTimeout(u,c.intervalFunc(a)):e.apply(null,arguments)})}var i=5,o=0,c={times:i,intervalFunc:Cn(o)};if(arguments.length<3&&"function"==typeof n?(e=t||p,t=n):(r(c,n),e=e||p),"function"!=typeof t)throw new Error("Invalid arguments for async.retry");var a=1;u()}function Pn(n,t){return t||(t=n,n=null),l(function(e,r){function u(n){t.apply(null,e.concat([n]))}n?Dn(n,u,r):Dn(u,r)})}function Rn(n,t){_n(we,n,t)}function Un(n,t,e){function r(n,t){var e=n.criteria,r=t.criteria;return r>e?-1:e>r?1:0}Mt(n,function(n,e){t(n,function(t,r){return t?e(t):void e(null,{value:n,criteria:r})})},function(n,t){return n?e(n):void e(null,R(t.sort(r),v("value")))})}function Nn(n,t,e){function r(){c||(i.apply(null,arguments),clearTimeout(o))}function u(){var t=n.name||"anonymous",r=new Error('Callback function "'+t+'" timed out.');r.code="ETIMEDOUT",e&&(r.info=e),c=!0,i(r)}var i,o,c=!1;return l(function(e,c){i=c,o=setTimeout(u,t),n.apply(null,e.concat(r))})}function Qn(n,t,e,r){for(var u=-1,i=tr(nr((t-n)/(e||1)),0),o=Array(i);i--;)o[r?i:++u]=n,n+=e;return o}function Wn(n,t,e,r){Bt(Qn(0,n,1),t,e,r)}function Gn(n,t,e,r){3===arguments.length&&(r=e,e=t,t=At(n)?[]:{}),r=h(r||p),xe(n,function(n,r,u){e(t,n,r,u)},function(n){r(n,t)})}function Hn(n){return function(){return(n.unmemoized||n).apply(null,arguments)}}function Jn(n,t,e){if(e=_(e||p),!n())return e(null);var r=f(function(u,i){return u?e(u):n()?t(r):void e.apply(null,[null].concat(i))});t(r)}function Kn(n,t,e){Jn(function(){return!n.apply(this,arguments)},t,e)}function Xn(n,t){function e(u){if(r===n.length)return t.apply(null,[null].concat(u));var i=_(f(function(n,r){return n?t.apply(null,[n].concat(r)):void e(r)}));u.push(i);var o=n[r++];o.apply(null,u)}if(t=h(t||p),!At(n))return t(new Error("First argument to waterfall must be an array of functions"));if(!n.length)return t();var r=0;e([])}var Yn,Zn="[object Function]",nt="[object GeneratorFunction]",tt=Object.prototype,et=tt.toString,rt="[object Symbol]",ut=Object.prototype,it=ut.toString,ot=NaN,ct=/^\s+|\s+$/g,at=/^[-+]0x[0-9a-f]+$/i,ft=/^0b[01]+$/i,lt=/^0o[0-7]+$/i,st=parseInt,pt=1/0,ht=1.7976931348623157e308,vt="Expected a function",yt=Math.max,mt=v("length"),dt=9007199254740991,gt="function"==typeof Symbol&&Symbol.iterator,bt=Object.getPrototypeOf,St=Object.prototype,jt=St.hasOwnProperty,kt=Object.keys,wt="[object Arguments]",Et=Object.prototype,Lt=Et.hasOwnProperty,xt=Et.toString,Ot=Et.propertyIsEnumerable,At=Array.isArray,It="[object String]",_t=Object.prototype,Tt=_t.toString,Ft=9007199254740991,$t=/^(?:0|[1-9]\d*)$/,zt=Object.prototype,Bt=F($),Mt=z(Bt,1/0),Vt=s(Mt),qt=z(Bt,1),Ct=s(qt),Dt=f(function(n,t){return f(function(e){return n.apply(null,t.concat(e))})}),Pt=V(),Rt=N("object"==typeof global&&global),Ut=N("object"==typeof self&&self),Nt=N("object"==typeof this&&this),Qt=Rt||Ut||Nt||Function("return this")(),Wt=Qt.Symbol,Gt=1/0,Ht=Wt?Wt.prototype:void 0,Jt=Ht?Ht.toString:void 0,Kt="\\ud800-\\udfff",Xt="\\u0300-\\u036f\\ufe20-\\ufe23",Yt="\\u20d0-\\u20f0",Zt="\\ufe0e\\ufe0f",ne="["+Kt+"]",te="["+Xt+Yt+"]",ee="\\ud83c[\\udffb-\\udfff]",re="(?:"+te+"|"+ee+")",ue="[^"+Kt+"]",ie="(?:\\ud83c[\\udde6-\\uddff]){2}",oe="[\\ud800-\\udbff][\\udc00-\\udfff]",ce="\\u200d",ae=re+"?",fe="["+Zt+"]?",le="(?:"+ce+"(?:"+[ue,ie,oe].join("|")+")"+fe+ae+")*",se=fe+ae+le,pe="(?:"+[ue+te+"?",te,ie,oe,ne].join("|")+")",he=RegExp(ee+"(?="+ee+")|"+pe+se,"g"),ve=/^\s+|\s+$/g,ye=/^(function)?\s*[^\(]*\(\s*([^\)]*)\)/m,me=/,/,de=/(=.+)?(\s*)$/,ge=/((\/\/.*$)|(\/\*[\s\S]*?\*\/))/gm,be="function"==typeof setImmediate&&setImmediate,Se="object"==typeof process&&"function"==typeof process.nextTick;Yn=be?setImmediate:Se?process.nextTick:tn;var je=en(Yn);rn.prototype.removeLink=function(n){return n.prev?n.prev.next=n.next:this.head=n.next,n.next?n.next.prev=n.prev:this.tail=n.prev,n.prev=n.next=null,this.length-=1,n},rn.prototype.empty=rn,rn.prototype.insertAfter=function(n,t){t.prev=n,t.next=n.next,n.next?n.next.prev=t:this.tail=t,n.next=t,this.length+=1},rn.prototype.insertBefore=function(n,t){t.prev=n.prev,t.next=n,n.prev?n.prev.next=t:this.head=t,n.prev=t,this.length+=1},rn.prototype.unshift=function(n){this.head?this.insertBefore(this.head,n):un(this,n)},rn.prototype.push=function(n){this.tail?this.insertAfter(this.tail,n):un(this,n)},rn.prototype.shift=function(){return this.head&&this.removeLink(this.head)},rn.prototype.pop=function(){return this.tail&&this.removeLink(this.tail)};var ke,we=z(an,1),Ee=f(function(n){return f(function(t){var e=this,r=t[t.length-1];"function"==typeof r?t.pop():r=p,fn(n,t,function(n,t,r){t.apply(e,n.concat([f(function(n,t){r(n,t)})]))},function(n,t){r.apply(e,[n].concat(t))})})}),Le=f(function(n){return Ee.apply(null,n.reverse())}),xe=z(an,1/0),Oe=sn(ln),Ae=pn(ln),Ie=f(function(n){var t=[null].concat(n);return l(function(n,e){return e.apply(this,t)})}),_e=vn(xe,hn,yn),Te=vn(an,hn,yn),Fe=vn(we,hn,yn),$e=mn("dir"),ze=z(kn,1/0),Be=z(kn,1),Me=vn(an,En,En),Ve=z(Me,1/0),qe=z(Me,1),Ce=F(Ln),De=z(Ce,1/0),Pe=z(Ce,1),Re=mn("log"),Ue=z(On,1/0),Ne=z(On,1);ke=Se?process.nextTick:be?setImmediate:tn;var Qe=en(ke),We=z(Tn,1/0),Ge=Array.prototype.slice,He=F(Vn),Je=z(He,1/0),Ke=z(He,1),Xe=vn(an,Boolean,hn),Ye=z(Xe,1/0),Ze=z(Xe,1),nr=Math.ceil,tr=Math.max,er=z(Wn,1/0),rr=z(Wn,1),ur={applyEach:Vt,applyEachSeries:Ct,apply:Dt,asyncify:B,auto:P,autoInject:nn,cargo:cn,compose:Le,concat:Oe,concatSeries:Ae,constant:Ie,detect:_e,detectLimit:Te,detectSeries:Fe,dir:$e,doDuring:dn,doUntil:bn,doWhilst:gn,during:Sn,each:ze,eachLimit:kn,eachOf:xe,eachOfLimit:an,eachOfSeries:we,eachSeries:Be,ensureAsync:wn,every:Ve,everyLimit:Me,everySeries:qe,filter:De,filterLimit:Ce,filterSeries:Pe,forever:xn,log:Re,map:Mt,mapLimit:Bt,mapSeries:qt,mapValues:Ue,mapValuesLimit:On,mapValuesSeries:Ne,memoize:In,nextTick:Qe,parallel:We,parallelLimit:Tn,priorityQueue:$n,queue:Fn,race:zn,reduce:fn,reduceRight:Bn,reflect:Mn,reflectAll:qn,reject:Je,rejectLimit:He,rejectSeries:Ke,retry:Dn,retryable:Pn,seq:Ee,series:Rn,setImmediate:je,some:Ye,someLimit:Xe,someSeries:Ze,sortBy:Un,timeout:Nn,times:er,timesLimit:Wn,timesSeries:rr,transform:Gn,unmemoize:Hn,until:Kn,waterfall:Xn,whilst:Jn,all:Ve,any:Ye,forEach:ze,forEachSeries:Be,forEachLimit:kn,forEachOf:xe,forEachOfSeries:we,forEachOfLimit:an,inject:fn,foldl:fn,foldr:Bn,select:De,selectLimit:Ce,selectSeries:Pe,wrapSync:B};n["default"]=ur,n.applyEach=Vt,n.applyEachSeries=Ct,n.apply=Dt,n.asyncify=B,n.auto=P,n.autoInject=nn,n.cargo=cn,n.compose=Le,n.concat=Oe,n.concatSeries=Ae,n.constant=Ie,n.detect=_e,n.detectLimit=Te,n.detectSeries=Fe,n.dir=$e,n.doDuring=dn,n.doUntil=bn,n.doWhilst=gn,n.during=Sn,n.each=ze,n.eachLimit=kn,n.eachOf=xe,n.eachOfLimit=an,n.eachOfSeries=we,n.eachSeries=Be,n.ensureAsync=wn,n.every=Ve,n.everyLimit=Me,n.everySeries=qe,n.filter=De,n.filterLimit=Ce,n.filterSeries=Pe,n.forever=xn,n.log=Re,n.map=Mt,n.mapLimit=Bt,n.mapSeries=qt,n.mapValues=Ue,n.mapValuesLimit=On,n.mapValuesSeries=Ne,n.memoize=In,n.nextTick=Qe,n.parallel=We,n.parallelLimit=Tn,n.priorityQueue=$n,n.queue=Fn,n.race=zn,n.reduce=fn,n.reduceRight=Bn,n.reflect=Mn,n.reflectAll=qn,n.reject=Je,n.rejectLimit=He,n.rejectSeries=Ke,n.retry=Dn,n.retryable=Pn,n.seq=Ee,n.series=Rn,n.setImmediate=je,n.some=Ye,n.someLimit=Xe,n.someSeries=Ze,n.sortBy=Un,n.timeout=Nn,n.times=er,n.timesLimit=Wn,n.timesSeries=rr,n.transform=Gn,n.unmemoize=Hn,n.until=Kn,n.waterfall=Xn,n.whilst=Jn,n.all=Ve,n.allLimit=Me,n.allSeries=qe,n.any=Ye,n.anyLimit=Xe,n.anySeries=Ze,n.find=_e,n.findLimit=Te,n.findSeries=Fe,n.forEach=ze,n.forEachSeries=Be,n.forEachLimit=kn,n.forEachOf=xe,n.forEachOfSeries=we,n.forEachOfLimit=an,n.inject=fn,n.foldl=fn,n.foldr=Bn,n.select=De,n.selectLimit=Ce,n.selectSeries=Pe,n.wrapSync=B});
+!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(n.async=n.async||{})}(this,function(n){"use strict";function t(n,t,e){var r=e.length;switch(r){case 0:return n.call(t);case 1:return n.call(t,e[0]);case 2:return n.call(t,e[0],e[1]);case 3:return n.call(t,e[0],e[1],e[2])}return n.apply(t,e)}function e(n){var t=typeof n;return!!n&&("object"==t||"function"==t)}function r(n){var t=e(n)?st.call(n):"";return t==ft||t==at}function u(n){return!!n&&"object"==typeof n}function i(n){return"symbol"==typeof n||u(n)&&vt.call(n)==pt}function o(n){if("number"==typeof n)return n;if(i(n))return yt;if(e(n)){var t=r(n.valueOf)?n.valueOf():n;n=e(t)?t+"":t}if("string"!=typeof n)return 0===n?n:+n;n=n.replace(mt,"");var u=gt.test(n);return u||bt.test(n)?St(n.slice(2),u?2:8):dt.test(n)?yt:+n}function c(n){if(!n)return 0===n?n:0;if(n=o(n),n===jt||n===-jt){var t=0>n?-1:1;return t*kt}return n===n?n:0}function f(n){var t=c(n),e=t%1;return t===t?e?t-e:t:0}function a(n,e){if("function"!=typeof n)throw new TypeError(wt);return e=Et(void 0===e?n.length-1:f(e),0),function(){for(var r=arguments,u=-1,i=Et(r.length-e,0),o=Array(i);++u<i;)o[u]=r[e+u];switch(e){case 0:return n.call(this,o);case 1:return n.call(this,r[0],o);case 2:return n.call(this,r[0],r[1],o)}var c=Array(e+1);for(u=-1;++u<e;)c[u]=r[u];return c[e]=o,t(n,this,c)}}function l(n){return a(function(t){var e=t.pop();n.call(this,t,e)})}function s(n){return a(function(t,e){var r=l(function(e,r){var u=this;return n(t,function(n,t){n.apply(u,e.concat([t]))},r)});return e.length?r.apply(this,e):r})}function p(n){return function(t){return null==t?void 0:t[n]}}function h(n){return"number"==typeof n&&n>-1&&n%1==0&&Lt>=n}function v(n){return null!=n&&h(xt(n))&&!r(n)}function y(){}function m(n){return function(){if(null!==n){var t=n;n=null,t.apply(this,arguments)}}}function d(n){return Ot&&n[Ot]&&n[Ot]()}function g(n){return At(Object(n))}function b(n,t){return null!=n&&(Tt.call(n,t)||"object"==typeof n&&t in n&&null===g(n))}function S(n){return _t(Object(n))}function j(n,t){for(var e=-1,r=Array(n);++e<n;)r[e]=t(e);return r}function k(n){return u(n)&&v(n)}function w(n){return k(n)&&zt.call(n,"callee")&&(!Mt.call(n,"callee")||Bt.call(n)==Ft)}function E(n){return"string"==typeof n||!Vt(n)&&u(n)&&Dt.call(n)==qt}function x(n){var t=n?n.length:void 0;return h(t)&&(Vt(n)||E(n)||w(n))?j(t,String):null}function L(n,t){return t=null==t?Pt:t,!!t&&("number"==typeof n||Rt.test(n))&&n>-1&&n%1==0&&t>n}function O(n){var t=n&&n.constructor,e="function"==typeof t&&t.prototype||Ut;return n===e}function A(n){var t=O(n);if(!t&&!v(n))return S(n);var e=x(n),r=!!e,u=e||[],i=u.length;for(var o in n)!b(n,o)||r&&("length"==o||L(o,i))||t&&"constructor"==o||u.push(o);return u}function I(n){var t=-1,e=n.length;return function(){return++t<e?{value:n[t],key:t}:null}}function T(n){var t=-1;return function(){var e=n.next();return e.done?null:(t++,{value:e.value,key:t})}}function _(n){var t=A(n),e=-1,r=t.length;return function(){var u=t[++e];return r>e?{value:n[u],key:u}:null}}function F(n){if(v(n))return I(n);var t=d(n);return t?T(t):_(n)}function $(n){return function(){if(null===n)throw new Error("Callback was already called.");var t=n;n=null,t.apply(this,arguments)}}function z(n){return function(t,e,r){function u(n){if(f-=1,n)c=!0,r(n);else{if(c&&0>=f)return r(null);i()}}function i(){for(;n>f&&!c;){var t=o();if(null===t)return c=!0,void(0>=f&&r(null));f+=1,e(t.value,t.key,$(u))}}if(r=m(r||y),0>=n||!t)return r(null);var o=F(t),c=!1,f=0;i()}}function B(n,t,e,r){z(t)(n,e,r)}function M(n,t){return function(e,r,u){return n(e,t,r,u)}}function V(n,t){var e;if("function"!=typeof t)throw new TypeError(Nt);return n=f(n),function(){return--n>0&&(e=t.apply(this,arguments)),1>=n&&(t=void 0),e}}function q(n){return V(2,n)}function C(n,t,e){function r(n){n?e(n):++i===o&&e(null)}e=q(e||y);var u=0,i=0,o=n.length;for(0===o&&e(null);o>u;u++)t(n[u],u,$(r))}function D(n,t,e){var r=v(n)?C:Qt;r(n,t,e)}function P(n){return function(t,e,r){return n(D,t,e,r)}}function R(n,t,e,r){r=m(r||y),t=t||[];var u=[],i=0;n(t,function(n,t,r){var o=i++;e(n,function(n,t){u[o]=t,r(n)})},function(n){r(n,u)})}function U(n){return function(t,e,r,u){return n(z(e),t,r,u)}}function N(n){return l(function(t,r){var u;try{u=n.apply(this,t)}catch(i){return r(i)}e(u)&&"function"==typeof u.then?u.then(function(n){r(null,n)},function(n){r(n.message?n:new Error(n))}):r(null,u)})}function Q(n,t){for(var e=-1,r=n?n.length:0;++e<r&&t(n[e],e,n)!==!1;);return n}function W(n){return function(t,e,r){for(var u=-1,i=Object(t),o=r(t),c=o.length;c--;){var f=o[n?c:++u];if(e(i[f],f,i)===!1)break}return t}}function G(n,t){return n&&Yt(n,t,A)}function H(n,t,e){for(var r=n.length,u=t+(e?1:-1);e?u--:++u<r;){var i=n[u];if(i!==i)return u}return-1}function J(n,t,e){if(t!==t)return H(n,e);for(var r=e-1,u=n.length;++r<u;)if(n[r]===t)return r;return-1}function K(n,t,e){function r(n,t){b.push(function(){c(n,t)})}function u(){if(0===b.length&&0===v)return e(null,h);for(;b.length&&t>v;){var n=b.shift();n()}}function i(n,t){var e=g[n];e||(e=g[n]=[]),e.push(t)}function o(n){var t=g[n]||[];Q(t,function(n){n()}),u()}function c(n,t){if(!d){var r=$(a(function(t,r){if(v--,r.length<=1&&(r=r[0]),t){var u={};G(h,function(n,t){u[t]=n}),u[n]=r,d=!0,g=[],e(t,u)}else h[n]=r,o(n)}));v++;var u=t[t.length-1];t.length>1?u(h,r):u(r)}}function f(){for(var n,t=0;S.length;)n=S.pop(),t++,Q(l(n),function(n){0===--j[n]&&S.push(n)});if(t!==p)throw new Error("async.auto cannot execute tasks due to a recursive dependency")}function l(t){var e=[];return G(n,function(n,r){Vt(n)&&J(n,t,0)>=0&&e.push(r)}),e}"function"==typeof t&&(e=t,t=null),e=m(e||y);var s=A(n),p=s.length;if(!p)return e(null);t||(t=p);var h={},v=0,d=!1,g={},b=[],S=[],j={};G(n,function(t,e){if(!Vt(t))return r(e,[t]),void S.push(e);var u=t.slice(0,t.length-1),o=u.length;return 0===o?(r(e,t),void S.push(e)):(j[e]=o,void Q(u,function(c){if(!n[c])throw new Error("async.auto task `"+e+"` has a non-existent dependency in "+u.join(", "));i(c,function(){o--,0===o&&r(e,t)})}))}),f(),u()}function X(n,t){for(var e=-1,r=n?n.length:0,u=Array(r);++e<r;)u[e]=t(n[e],e,n);return u}function Y(n,t){var e=-1,r=n.length;for(t||(t=Array(r));++e<r;)t[e]=n[e];return t}function Z(n){return n&&n.Object===Object?n:null}function nn(n){if("string"==typeof n)return n;if(i(n))return oe?oe.call(n):"";var t=n+"";return"0"==t&&1/n==-ue?"-0":t}function tn(n,t,e){var r=-1,u=n.length;0>t&&(t=-t>u?0:u+t),e=e>u?u:e,0>e&&(e+=u),u=t>e?0:e-t>>>0,t>>>=0;for(var i=Array(u);++r<u;)i[r]=n[r+t];return i}function en(n,t,e){var r=n.length;return e=void 0===e?r:e,!t&&e>=r?n:tn(n,t,e)}function rn(n,t){for(var e=n.length;e--&&J(t,n[e],0)>-1;);return e}function un(n,t){for(var e=-1,r=n.length;++e<r&&J(t,n[e],0)>-1;);return e}function on(n){return n.match(Ee)}function cn(n){return null==n?"":nn(n)}function fn(n,t,e){if(n=cn(n),n&&(e||void 0===t))return n.replace(xe,"");if(!n||!(t=nn(t)))return n;var r=on(n),u=on(t),i=un(r,u),o=rn(r,u)+1;return en(r,i,o).join("")}function an(n){return n=n.toString().replace(Ie,""),n=n.match(Le)[2].replace(" ",""),n=n?n.split(Oe):[],n=n.map(function(n){return fn(n.replace(Ae,""))})}function ln(n,t){var e={};G(n,function(n,t){function r(t,e){var r=X(u,function(n){return t[n]});r.push(e),n.apply(null,r)}var u;if(Vt(n))u=Y(n),n=u.pop(),e[t]=u.concat(u.length>0?r:n);else if(1===n.length)e[t]=n;else{if(u=an(n),0===n.length&&0===u.length)throw new Error("autoInject task functions require explicit parameters.");u.pop(),e[t]=u.concat(r)}}),K(e,t)}function sn(n){setTimeout(n,0)}function pn(n){return a(function(t,e){n(function(){t.apply(null,e)})})}function hn(){this.head=this.tail=null,this.length=0}function vn(n,t){n.length=1,n.head=n.tail=t}function yn(n,t,e){function r(n,t,e){if(null!=e&&"function"!=typeof e)throw new Error("task callback must be a function");return c.started=!0,Vt(n)||(n=[n]),0===n.length&&c.idle()?Fe(function(){c.drain()}):(Q(n,function(n){var r={data:n,callback:e||y};t?c._tasks.unshift(r):c._tasks.push(r)}),void Fe(c.process))}function u(n){return a(function(t){i-=1,Q(n,function(n){Q(o,function(t,e){return t===n?(o.splice(e,1),!1):void 0}),n.callback.apply(n,t),null!=t[0]&&c.error(t[0],n.data)}),i<=c.concurrency-c.buffer&&c.unsaturated(),c.idle()&&c.drain(),c.process()})}if(null==t)t=1;else if(0===t)throw new Error("Concurrency must not be zero");var i=0,o=[],c={_tasks:new hn,concurrency:t,payload:e,saturated:y,unsaturated:y,buffer:t/4,empty:y,drain:y,error:y,started:!1,paused:!1,push:function(n,t){r(n,!1,t)},kill:function(){c.drain=y,c._tasks.empty()},unshift:function(n,t){r(n,!0,t)},process:function(){for(;!c.paused&&i<c.concurrency&&c._tasks.length;){var t=[],e=[],r=c._tasks.length;c.payload&&(r=Math.min(r,c.payload));for(var f=0;r>f;f++){var a=c._tasks.shift();t.push(a),e.push(a.data)}0===c._tasks.length&&c.empty(),i+=1,o.push(t[0]),i===c.concurrency&&c.saturated();var l=$(u(t));n(e,l)}},length:function(){return c._tasks.length},running:function(){return i},workersList:function(){return o},idle:function(){return c._tasks.length+i===0},pause:function(){c.paused=!0},resume:function(){if(c.paused!==!1){c.paused=!1;for(var n=Math.min(c.concurrency,c._tasks.length),t=1;n>=t;t++)Fe(c.process)}}};return c}function mn(n,t){return yn(n,1,t)}function dn(n,t,e,r){r=m(r||y),ze(n,function(n,r,u){e(t,n,function(n,e){t=e,u(n)})},function(n){r(n,t)})}function gn(n,t,e,r){var u=[];n(t,function(n,t,r){e(n,function(n,t){u=u.concat(t||[]),r(n)})},function(n){r(n,u)})}function bn(n){return function(t,e,r){return n(ze,t,e,r)}}function Sn(n){return n}function jn(n,t,e){return function(r,u,i,o){function c(n){o&&(n?o(n):o(null,e(!1)))}function f(n,r,u){return o?void i(n,function(r,c){o&&(r?(o(r),o=i=!1):t(c)&&(o(null,e(!0,n)),o=i=!1)),u()}):u()}arguments.length>3?(o=o||y,n(r,u,f,c)):(o=i,o=o||y,i=u,n(r,f,c))}}function kn(n,t){return t}function wn(n){return a(function(t,e){t.apply(null,e.concat([a(function(t,e){"object"==typeof console&&(t?console.error&&console.error(t):console[n]&&Q(e,function(t){console[n](t)}))})]))})}function En(n,t,e){function r(t,r){return t?e(t):r?void n(u):e(null)}e=$(e||y);var u=a(function(n,u){return n?e(n):(u.push(r),void t.apply(this,u))});r(null,!0)}function xn(n,t,e){e=$(e||y);var r=a(function(u,i){return u?e(u):t.apply(this,i)?n(r):void e.apply(null,[null].concat(i))});n(r)}function Ln(n,t,e){xn(n,function(){return!t.apply(this,arguments)},e)}function On(n,t,e){function r(t){return t?e(t):void n(u)}function u(n,u){return n?e(n):u?void t(r):e(null)}e=$(e||y),n(u)}function An(n){return function(t,e,r){return n(t,r)}}function In(n,t,e){D(n,An(t),e)}function Tn(n,t,e,r){z(t)(n,An(e),r)}function _n(n){return l(function(t,e){var r=!0;t.push(function(){var n=arguments;r?Fe(function(){e.apply(null,n)}):e.apply(null,n)}),n.apply(this,t),r=!1})}function Fn(n){return!n}function $n(n,t,e,r){r=m(r||y);var u=[];n(t,function(n,t,r){e(n,function(e,i){e?r(e):(i&&u.push({index:t,value:n}),r())})},function(n){n?r(n):r(null,X(u.sort(function(n,t){return n.index-t.index}),p("value")))})}function zn(n,t){function e(n){return n?r(n):void u(e)}var r=$(t||y),u=_n(n);e()}function Bn(n,t,e,r){r=m(r||y);var u={};B(n,t,function(n,t,r){e(n,t,function(n,e){return n?r(n):(u[t]=e,void r())})},function(n){r(n,u)})}function Mn(n,t){return t in n}function Vn(n,t){var e=Object.create(null),r=Object.create(null);t=t||Sn;var u=l(function(u,i){var o=t.apply(null,u);Mn(e,o)?Fe(function(){i.apply(null,e[o])}):Mn(r,o)?r[o].push(i):(r[o]=[i],n.apply(null,u.concat([a(function(n){e[o]=n;var t=r[o];delete r[o];for(var u=0,i=t.length;i>u;u++)t[u].apply(null,n)})])))});return u.memo=e,u.unmemoized=n,u}function qn(n,t,e){e=e||y;var r=v(t)?[]:{};n(t,function(n,t,e){n(a(function(n,u){u.length<=1&&(u=u[0]),r[t]=u,e(n)}))},function(n){e(n,r)})}function Cn(n,t){qn(D,n,t)}function Dn(n,t,e){qn(z(t),n,e)}function Pn(n,t){return yn(function(t,e){n(t[0],e)},t,1)}function Rn(n,t){var e=Pn(n,t);return e.push=function(n,t,r){if(null==r&&(r=y),"function"!=typeof r)throw new Error("task callback must be a function");if(e.started=!0,Vt(n)||(n=[n]),0===n.length)return Fe(function(){e.drain()});t=t||0;for(var u=e._tasks.head;u&&t>=u.priority;)u=u.next;Q(n,function(n){var i={data:n,priority:t,callback:r};u?e._tasks.insertBefore(u,i):e._tasks.push(i)}),Fe(e.process)},delete e.unshift,e}function Un(n,t){return t=m(t||y),Vt(n)?n.length?void Q(n,function(n){n(t)}):t():t(new TypeError("First argument to race must be an array of functions"))}function Nn(n,t,e,r){var u=tr.call(n).reverse();dn(u,t,e,r)}function Qn(n){return l(function(t,e){return t.push(a(function(n,t){if(n)e(null,{error:n});else{var r=null;1===t.length?r=t[0]:t.length>1&&(r=t),e(null,{value:r})}})),n.apply(this,t)})}function Wn(n,t,e,r){$n(n,t,function(n,t){e(n,function(n,e){n?t(n):t(null,!e)})},r)}function Gn(n){var t;return Vt(n)?t=X(n,Qn):(t={},G(n,function(n,e){t[e]=Qn.call(this,n)})),t}function Hn(n){return function(){return n}}function Jn(n,t,e){function r(n,t){if("object"==typeof t)n.times=+t.times||i,n.intervalFunc="function"==typeof t.interval?t.interval:Hn(+t.interval||o);else{if("number"!=typeof t&&"string"!=typeof t)throw new Error("Invalid arguments for async.retry");n.times=+t||i}}function u(){t(function(n){n&&f++<c.times?setTimeout(u,c.intervalFunc(f)):e.apply(null,arguments)})}var i=5,o=0,c={times:i,intervalFunc:Hn(o)};if(arguments.length<3&&"function"==typeof n?(e=t||y,t=n):(r(c,n),e=e||y),"function"!=typeof t)throw new Error("Invalid arguments for async.retry");var f=1;u()}function Kn(n,t){return t||(t=n,n=null),l(function(e,r){function u(n){t.apply(null,e.concat([n]))}n?Jn(n,u,r):Jn(u,r)})}function Xn(n,t){qn(ze,n,t)}function Yn(n,t,e){function r(n,t){var e=n.criteria,r=t.criteria;return r>e?-1:e>r?1:0}Wt(n,function(n,e){t(n,function(t,r){return t?e(t):void e(null,{value:n,criteria:r})})},function(n,t){return n?e(n):void e(null,X(t.sort(r),p("value")))})}function Zn(n,t,e){function r(){c||(i.apply(null,arguments),clearTimeout(o))}function u(){var t=n.name||"anonymous",r=new Error('Callback function "'+t+'" timed out.');r.code="ETIMEDOUT",e&&(r.info=e),c=!0,i(r)}var i,o,c=!1;return l(function(e,c){i=c,o=setTimeout(u,t),n.apply(null,e.concat(r))})}function nt(n,t,e,r){for(var u=-1,i=ar(fr((t-n)/(e||1)),0),o=Array(i);i--;)o[r?i:++u]=n,n+=e;return o}function tt(n,t,e,r){Ht(nt(0,n,1),t,e,r)}function et(n,t,e,r){3===arguments.length&&(r=e,e=t,t=Vt(n)?[]:{}),r=m(r||y),D(n,function(n,r,u){e(t,n,r,u)},function(n){r(n,t)})}function rt(n){return function(){return(n.unmemoized||n).apply(null,arguments)}}function ut(n,t,e){if(e=$(e||y),!n())return e(null);var r=a(function(u,i){return u?e(u):n()?t(r):void e.apply(null,[null].concat(i))});t(r)}function it(n,t,e){ut(function(){return!n.apply(this,arguments)},t,e)}function ot(n,t){function e(u){if(r===n.length)return t.apply(null,[null].concat(u));var i=$(a(function(n,r){return n?t.apply(null,[n].concat(r)):void e(r)}));u.push(i);var o=n[r++];o.apply(null,u)}if(t=m(t||y),!Vt(n))return t(new Error("First argument to waterfall must be an array of functions"));if(!n.length)return t();var r=0;e([])}var ct,ft="[object Function]",at="[object GeneratorFunction]",lt=Object.prototype,st=lt.toString,pt="[object Symbol]",ht=Object.prototype,vt=ht.toString,yt=NaN,mt=/^\s+|\s+$/g,dt=/^[-+]0x[0-9a-f]+$/i,gt=/^0b[01]+$/i,bt=/^0o[0-7]+$/i,St=parseInt,jt=1/0,kt=1.7976931348623157e308,wt="Expected a function",Et=Math.max,xt=p("length"),Lt=9007199254740991,Ot="function"==typeof Symbol&&Symbol.iterator,At=Object.getPrototypeOf,It=Object.prototype,Tt=It.hasOwnProperty,_t=Object.keys,Ft="[object Arguments]",$t=Object.prototype,zt=$t.hasOwnProperty,Bt=$t.toString,Mt=$t.propertyIsEnumerable,Vt=Array.isArray,qt="[object String]",Ct=Object.prototype,Dt=Ct.toString,Pt=9007199254740991,Rt=/^(?:0|[1-9]\d*)$/,Ut=Object.prototype,Nt="Expected a function",Qt=M(B,1/0),Wt=P(R),Gt=s(Wt),Ht=U(R),Jt=M(Ht,1),Kt=s(Jt),Xt=a(function(n,t){return a(function(e){return n.apply(null,t.concat(e))})}),Yt=W(),Zt=Z("object"==typeof global&&global),ne=Z("object"==typeof self&&self),te=Z("object"==typeof this&&this),ee=Zt||ne||te||Function("return this")(),re=ee.Symbol,ue=1/0,ie=re?re.prototype:void 0,oe=ie?ie.toString:void 0,ce="\\ud800-\\udfff",fe="\\u0300-\\u036f\\ufe20-\\ufe23",ae="\\u20d0-\\u20f0",le="\\ufe0e\\ufe0f",se="["+ce+"]",pe="["+fe+ae+"]",he="\\ud83c[\\udffb-\\udfff]",ve="(?:"+pe+"|"+he+")",ye="[^"+ce+"]",me="(?:\\ud83c[\\udde6-\\uddff]){2}",de="[\\ud800-\\udbff][\\udc00-\\udfff]",ge="\\u200d",be=ve+"?",Se="["+le+"]?",je="(?:"+ge+"(?:"+[ye,me,de].join("|")+")"+Se+be+")*",ke=Se+be+je,we="(?:"+[ye+pe+"?",pe,me,de,se].join("|")+")",Ee=RegExp(he+"(?="+he+")|"+we+ke,"g"),xe=/^\s+|\s+$/g,Le=/^(function)?\s*[^\(]*\(\s*([^\)]*)\)/m,Oe=/,/,Ae=/(=.+)?(\s*)$/,Ie=/((\/\/.*$)|(\/\*[\s\S]*?\*\/))/gm,Te="function"==typeof setImmediate&&setImmediate,_e="object"==typeof process&&"function"==typeof process.nextTick;ct=Te?setImmediate:_e?process.nextTick:sn;var Fe=pn(ct);hn.prototype.removeLink=function(n){return n.prev?n.prev.next=n.next:this.head=n.next,n.next?n.next.prev=n.prev:this.tail=n.prev,n.prev=n.next=null,this.length-=1,n},hn.prototype.empty=hn,hn.prototype.insertAfter=function(n,t){t.prev=n,t.next=n.next,n.next?n.next.prev=t:this.tail=t,n.next=t,this.length+=1},hn.prototype.insertBefore=function(n,t){t.prev=n.prev,t.next=n,n.prev?n.prev.next=t:this.head=t,n.prev=t,this.length+=1},hn.prototype.unshift=function(n){this.head?this.insertBefore(this.head,n):vn(this,n)},hn.prototype.push=function(n){this.tail?this.insertAfter(this.tail,n):vn(this,n)},hn.prototype.shift=function(){return this.head&&this.removeLink(this.head)},hn.prototype.pop=function(){return this.tail&&this.removeLink(this.tail)};var $e,ze=M(B,1),Be=a(function(n){return a(function(t){var e=this,r=t[t.length-1];"function"==typeof r?t.pop():r=y,dn(n,t,function(n,t,r){t.apply(e,n.concat([a(function(n,t){r(n,t)})]))},function(n,t){r.apply(e,[n].concat(t))})})}),Me=a(function(n){return Be.apply(null,n.reverse())}),Ve=P(gn),qe=bn(gn),Ce=a(function(n){var t=[null].concat(n);return l(function(n,e){return e.apply(this,t)})}),De=jn(D,Sn,kn),Pe=jn(B,Sn,kn),Re=jn(ze,Sn,kn),Ue=wn("dir"),Ne=M(Tn,1),Qe=jn(D,Fn,Fn),We=jn(B,Fn,Fn),Ge=M(We,1),He=P($n),Je=U($n),Ke=M(Je,1),Xe=wn("log"),Ye=M(Bn,1/0),Ze=M(Bn,1);$e=_e?process.nextTick:Te?setImmediate:sn;var nr=pn($e),tr=Array.prototype.slice,er=P(Wn),rr=U(Wn),ur=M(rr,1),ir=jn(D,Boolean,Sn),or=jn(B,Boolean,Sn),cr=M(or,1),fr=Math.ceil,ar=Math.max,lr=M(tt,1/0),sr=M(tt,1),pr={applyEach:Gt,applyEachSeries:Kt,apply:Xt,asyncify:N,auto:K,autoInject:ln,cargo:mn,compose:Me,concat:Ve,concatSeries:qe,constant:Ce,detect:De,detectLimit:Pe,detectSeries:Re,dir:Ue,doDuring:En,doUntil:Ln,doWhilst:xn,during:On,each:In,eachLimit:Tn,eachOf:D,eachOfLimit:B,eachOfSeries:ze,eachSeries:Ne,ensureAsync:_n,every:Qe,everyLimit:We,everySeries:Ge,filter:He,filterLimit:Je,filterSeries:Ke,forever:zn,log:Xe,map:Wt,mapLimit:Ht,mapSeries:Jt,mapValues:Ye,mapValuesLimit:Bn,mapValuesSeries:Ze,memoize:Vn,nextTick:nr,parallel:Cn,parallelLimit:Dn,priorityQueue:Rn,queue:Pn,race:Un,reduce:dn,reduceRight:Nn,reflect:Qn,reflectAll:Gn,reject:er,rejectLimit:rr,rejectSeries:ur,retry:Jn,retryable:Kn,seq:Be,series:Xn,setImmediate:Fe,some:ir,someLimit:or,someSeries:cr,sortBy:Yn,timeout:Zn,times:lr,timesLimit:tt,timesSeries:sr,transform:et,unmemoize:rt,until:it,waterfall:ot,whilst:ut,all:Qe,any:ir,forEach:In,forEachSeries:Ne,forEachLimit:Tn,forEachOf:D,forEachOfSeries:ze,forEachOfLimit:B,inject:dn,foldl:dn,foldr:Nn,select:He,selectLimit:Je,selectSeries:Ke,wrapSync:N};n["default"]=pr,n.applyEach=Gt,n.applyEachSeries=Kt,n.apply=Xt,n.asyncify=N,n.auto=K,n.autoInject=ln,n.cargo=mn,n.compose=Me,n.concat=Ve,n.concatSeries=qe,n.constant=Ce,n.detect=De,n.detectLimit=Pe,n.detectSeries=Re,n.dir=Ue,n.doDuring=En,n.doUntil=Ln,n.doWhilst=xn,n.during=On,n.each=In,n.eachLimit=Tn,n.eachOf=D,n.eachOfLimit=B,n.eachOfSeries=ze,n.eachSeries=Ne,n.ensureAsync=_n,n.every=Qe,n.everyLimit=We,n.everySeries=Ge,n.filter=He,n.filterLimit=Je,n.filterSeries=Ke,n.forever=zn,n.log=Xe,n.map=Wt,n.mapLimit=Ht,n.mapSeries=Jt,n.mapValues=Ye,n.mapValuesLimit=Bn,n.mapValuesSeries=Ze,n.memoize=Vn,n.nextTick=nr,n.parallel=Cn,n.parallelLimit=Dn,n.priorityQueue=Rn,n.queue=Pn,n.race=Un,n.reduce=dn,n.reduceRight=Nn,n.reflect=Qn,n.reflectAll=Gn,n.reject=er,n.rejectLimit=rr,n.rejectSeries=ur,n.retry=Jn,n.retryable=Kn,n.seq=Be,n.series=Xn,n.setImmediate=Fe,n.some=ir,n.someLimit=or,n.someSeries=cr,n.sortBy=Yn,n.timeout=Zn,n.times=lr,n.timesLimit=tt,n.timesSeries=sr,n.transform=et,n.unmemoize=rt,n.until=it,n.waterfall=ot,n.whilst=ut,n.all=Qe,n.allLimit=We,n.allSeries=Ge,n.any=ir,n.anyLimit=or,n.anySeries=cr,n.find=De,n.findLimit=Pe,n.findSeries=Re,n.forEach=In,n.forEachSeries=Ne,n.forEachLimit=Tn,n.forEachOf=D,n.forEachOfSeries=ze,n.forEachOfLimit=B,n.inject=dn,n.foldl=dn,n.foldr=Nn,n.select=He,n.selectLimit=Je,n.selectSeries=Ke,n.wrapSync=N});
//# sourceMappingURL=async.min.map \ No newline at end of file
diff --git a/dist/async.min.map b/dist/async.min.map
index fddfcc4..1aa0840 100644
--- a/dist/async.min.map
+++ b/dist/async.min.map
@@ -1 +1 @@
-{"version":3,"file":"build/dist/async.min.js","sources":["build/dist/async.js"],"names":["global","factory","exports","module","define","amd","async","this","apply","func","thisArg","args","length","call","isObject","value","type","isFunction","tag","objectToString","funcTag","genTag","isObjectLike","isSymbol","objectToString$1","symbolTag","toNumber","NAN","other","valueOf","replace","reTrim","isBinary","reIsBinary","test","reIsOctal","freeParseInt","slice","reIsBadHex","toFinite","INFINITY","sign","MAX_INTEGER","toInteger","result","remainder","rest","start","TypeError","FUNC_ERROR_TEXT","nativeMax","undefined","arguments","index","array","Array","otherArgs","initialParams","fn","callback","pop","applyEach$1","eachfn","fns","go","that","cb","concat","noop","once","callFn","baseProperty","key","object","isLength","MAX_SAFE_INTEGER","isArrayLike","getLength","getIterator","coll","iteratorSymbol","getPrototype","nativeGetPrototype","Object","baseHas","hasOwnProperty","baseKeys","nativeKeys","baseTimes","n","iteratee","isArrayLikeObject","isArguments","hasOwnProperty$1","propertyIsEnumerable","objectToString$2","argsTag","isString","isArray","objectToString$3","stringTag","indexKeys","String","isIndex","MAX_SAFE_INTEGER$1","reIsUint","isPrototype","Ctor","constructor","proto","prototype","objectProto$5","keys","isProto","indexes","skipIndexes","push","iterator","len","i","iterate","item","next","done","okeys","onlyOnce","Error","_eachOfLimit","limit","obj","nextElem","running","errored","replenish","elem","err","doParallelLimit","_asyncMap","arr","results","counter","_","v","doLimit","iterable","asyncify","e","then","message","arrayEach","createBaseFor","fromRight","keysFunc","props","baseForOwn","baseFor","indexOfNaN","fromIndex","baseIndexOf","auto","tasks","concurrency","enqueueTask","task","readyTasks","runTask","processQueue","runningTasks","run","shift","addListener","taskName","taskListeners","listeners","taskComplete","hasError","taskCallback","safeResults","val","rkey","taskFn","checkForDeadlocks","currentTask","readyToCheck","getDependents","dependent","uncheckedDependencies","numTasks","keys$$","dependencies","remainingDependencies","dependencyName","join","arrayMap","copyArray","source","checkGlobal","baseToString","symbolToString","INFINITY$1","baseSlice","end","castSlice","charsEndIndex","strSymbols","chrSymbols","charsStartIndex","stringToArray","string","match","reComplexSymbol","toString","trim","chars","guard","reTrim$1","parseParams","STRIP_COMMENTS","FN_ARGS","split","FN_ARG_SPLIT","map","arg","FN_ARG","autoInject","newTasks","newTask","taskCb","newArgs","params","name","fallback","setTimeout","wrap","defer","DLL","head","tail","setInitial","dll","node","queue","worker","payload","_insert","data","pos","q","started","idle","setImmediate$1","drain","_tasks","unshift","process","_next","workers","workersList","splice","error","buffer","unsaturated","saturated","empty","paused","kill","l","Math","min","pause","resume","resumeCount","w","cargo","eachOfLimit","reduce","memo","eachOfSeries","x","concat$1","y","doParallel","eachOf","doSeries","identity","_createTester","check","getResult","wrappedIteratee","_findGetResult","consoleFunc","console","doDuring","truth","doWhilst","doUntil","during","_withoutIndex","eachLimit","ensureAsync","sync","innerArgs","notId","_filter","sort","a","b","forever","errback","mapValuesLimit","newObj","has","memoize","hasher","create","queues","memoized","unmemoized","_parallel","parallelLimit","queue$1","items","priorityQueue","priority","nextNode","insertBefore","race","reduceRight","reversed","reverse","reflect","reflectCallback","cbArgs","reject$1","reflectAll","constant$1","retry","opts","parseTimes","acc","t","times","DEFAULT_TIMES","intervalFunc","interval","DEFAULT_INTERVAL","retryAttempt","attempt","options","retryable","series","sortBy","comparator","left","right","criteria","timeout","asyncFn","milliseconds","info","injectedCallback","timedOut","originalCallback","clearTimeout","timer","timeoutCallback","code","origCallback","baseRange","step","nativeMax$1","nativeCeil","timeLimit","count","mapLimit","transform","accumulator","k","unmemoize","whilst","until","waterfall","nextTask","taskIndex","_defer","objectProto","objectProto$1","parseInt","max","Symbol","getPrototypeOf","objectProto$2","objectProto$3","objectProto$4","Infinity","applyEach","mapSeries","applyEachSeries","apply$1","callArgs","freeGlobal","freeSelf","self","thisGlobal","root","Function","Symbol$1","symbolProto","rsAstralRange","rsComboMarksRange","rsComboSymbolsRange","rsVarRange","rsAstral","rsCombo","rsFitz","rsModifier","rsNonAstral","rsRegional","rsSurrPair","rsZWJ","reOptMod","rsOptVar","rsOptJoin","rsSeq","rsSymbol","RegExp","hasSetImmediate","setImmediate","hasNextTick","nextTick","removeLink","prev","insertAfter","newNode","_defer$1","seq","functions","newargs","nextargs","compose","concatSeries","constant","values","ignoredArgs","detect","detectLimit","detectSeries","dir","each","eachSeries","everyLimit","every","everySeries","filterLimit","filter","filterSeries","log","mapValues","mapValuesSeries","parallel","rejectLimit","reject","rejectSeries","someLimit","Boolean","some","someSeries","ceil","timesSeries","timesLimit","all","any","forEach","forEachSeries","forEachLimit","forEachOf","forEachOfSeries","forEachOfLimit","inject","foldl","foldr","select","selectLimit","selectSeries","wrapSync","allLimit","allSeries","anyLimit","anySeries","find","findLimit","findSeries"],"mappings":"CAAC,SAAUA,EAAQC,GACE,gBAAZC,UAA0C,mBAAXC,QAAyBF,EAAQC,SACrD,kBAAXE,SAAyBA,OAAOC,IAAMD,QAAQ,WAAYH,GAChEA,EAASD,EAAOM,MAAQN,EAAOM,YAChCC,KAAM,SAAUL,GAAW,YAY3B,SAASM,GAAMC,EAAMC,EAASC,GAC5B,GAAIC,GAASD,EAAKC,MAClB,QAAQA,GACN,IAAK,GAAG,MAAOH,GAAKI,KAAKH,EACzB,KAAK,GAAG,MAAOD,GAAKI,KAAKH,EAASC,EAAK,GACvC,KAAK,GAAG,MAAOF,GAAKI,KAAKH,EAASC,EAAK,GAAIA,EAAK,GAChD,KAAK,GAAG,MAAOF,GAAKI,KAAKH,EAASC,EAAK,GAAIA,EAAK,GAAIA,EAAK,IAE3D,MAAOF,GAAKD,MAAME,EAASC,GA4B7B,QAASG,GAASC,GAChB,GAAIC,SAAcD,EAClB,SAASA,IAAkB,UAARC,GAA4B,YAARA,GAiCzC,QAASC,GAAWF,GAIlB,GAAIG,GAAMJ,EAASC,GAASI,GAAeN,KAAKE,GAAS,EACzD,OAAOG,IAAOE,IAAWF,GAAOG,GA2BlC,QAASC,GAAaP,GACpB,QAASA,GAAyB,gBAATA,GAkC3B,QAASQ,GAASR,GAChB,MAAuB,gBAATA,IACXO,EAAaP,IAAUS,GAAiBX,KAAKE,IAAUU,GA4C5D,QAASC,GAASX,GAChB,GAAoB,gBAATA,GACT,MAAOA,EAET,IAAIQ,EAASR,GACX,MAAOY,GAET,IAAIb,EAASC,GAAQ,CACnB,GAAIa,GAAQX,EAAWF,EAAMc,SAAWd,EAAMc,UAAYd,CAC1DA,GAAQD,EAASc,GAAUA,EAAQ,GAAMA,EAE3C,GAAoB,gBAATb,GACT,MAAiB,KAAV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,SAAWnC,GACnBhc,EAAQoe,UAAYlC,GACpBlc,EAAQqd,IAAMN,GACd/c,EAAQqe,SAAWxB,GACnB7c,EAAQse,UAAYtB,GACpBhd,EAAQue,KAAO7C,GACf1b,EAAQwe,UAAY7C,GACpB3b,EAAQye,WAAa7C,GACrB5b,EAAQsd,QAAUxB,GAClB9b,EAAQud,cAAgBxB,GACxB/b,EAAQwd,aAAehL,GACvBxS,EAAQyd,UAAYjM,GACpBxR,EAAQ0d,gBAAkBvM,GAC1BnR,EAAQ2d,eAAiB3M,GACzBhR,EAAQ4d,OAAS3M,GACjBjR,EAAQ6d,MAAQ5M,GAChBjR,EAAQ8d,MAAQzJ,GAChBrU,EAAQ+d,OAAS3B,GACjBpc,EAAQge,YAAc7B,GACtBnc,EAAQie,aAAe5B,GACvBrc,EAAQke,SAAWnV"} \ No newline at end of file
+{"version":3,"file":"build/dist/async.min.js","sources":["build/dist/async.js"],"names":["global","factory","exports","module","define","amd","async","this","apply","func","thisArg","args","length","call","isObject","value","type","isFunction","tag","objectToString","funcTag","genTag","isObjectLike","isSymbol","objectToString$1","symbolTag","toNumber","NAN","other","valueOf","replace","reTrim","isBinary","reIsBinary","test","reIsOctal","freeParseInt","slice","reIsBadHex","toFinite","INFINITY","sign","MAX_INTEGER","toInteger","result","remainder","rest","start","TypeError","FUNC_ERROR_TEXT","nativeMax","undefined","arguments","index","array","Array","otherArgs","initialParams","fn","callback","pop","applyEach$1","eachfn","fns","go","that","cb","concat","baseProperty","key","object","isLength","MAX_SAFE_INTEGER","isArrayLike","getLength","noop","once","callFn","getIterator","coll","iteratorSymbol","getPrototype","nativeGetPrototype","Object","baseHas","hasOwnProperty","baseKeys","nativeKeys","baseTimes","n","iteratee","isArrayLikeObject","isArguments","hasOwnProperty$1","propertyIsEnumerable","objectToString$2","argsTag","isString","isArray","objectToString$3","stringTag","indexKeys","String","isIndex","MAX_SAFE_INTEGER$1","reIsUint","isPrototype","Ctor","constructor","proto","prototype","objectProto$5","keys","isProto","indexes","skipIndexes","push","createArrayIterator","i","len","createES2015Iterator","iterator","item","next","done","createObjectIterator","obj","okeys","onlyOnce","Error","_eachOfLimit","limit","iterateeCallback","err","running","replenish","elem","nextElem","eachOfLimit","doLimit","iterable","before","FUNC_ERROR_TEXT$1","once$1","eachOfArrayLike","iteratorCallback","completed","eachOf","eachOfImplementation","eachOfGeneric","doParallel","_asyncMap","arr","results","counter","_","v","doParallelLimit","asyncify","e","then","message","arrayEach","createBaseFor","fromRight","keysFunc","props","baseForOwn","baseFor","indexOfNaN","fromIndex","baseIndexOf","auto","tasks","concurrency","enqueueTask","task","readyTasks","runTask","processQueue","runningTasks","run","shift","addListener","taskName","taskListeners","listeners","taskComplete","hasError","taskCallback","safeResults","val","rkey","taskFn","checkForDeadlocks","currentTask","readyToCheck","getDependents","dependent","uncheckedDependencies","numTasks","keys$$","dependencies","remainingDependencies","dependencyName","join","arrayMap","copyArray","source","checkGlobal","baseToString","symbolToString","INFINITY$1","baseSlice","end","castSlice","charsEndIndex","strSymbols","chrSymbols","charsStartIndex","stringToArray","string","match","reComplexSymbol","toString","trim","chars","guard","reTrim$1","parseParams","STRIP_COMMENTS","FN_ARGS","split","FN_ARG_SPLIT","map","arg","FN_ARG","autoInject","newTasks","newTask","taskCb","newArgs","params","name","fallback","setTimeout","wrap","defer","DLL","head","tail","setInitial","dll","node","queue","worker","payload","_insert","data","insertAtFront","q","started","idle","setImmediate$1","drain","_tasks","unshift","process","_next","workers","workersList","splice","error","buffer","unsaturated","saturated","empty","paused","kill","l","Math","min","pause","resume","resumeCount","w","cargo","reduce","memo","eachOfSeries","x","concat$1","y","doSeries","identity","_createTester","check","getResult","wrappedIteratee","_findGetResult","consoleFunc","console","doDuring","truth","doWhilst","doUntil","during","_withoutIndex","eachLimit","eachLimit$1","ensureAsync","sync","innerArgs","notId","_filter","sort","a","b","forever","errback","mapValuesLimit","newObj","has","memoize","hasher","create","queues","memoized","unmemoized","_parallel","parallelLimit","parallelLimit$1","queue$1","items","priorityQueue","priority","nextNode","insertBefore","race","reduceRight","reversed","reverse","reflect","reflectCallback","cbArgs","reject$1","reflectAll","constant$1","retry","opts","parseTimes","acc","t","times","DEFAULT_TIMES","intervalFunc","interval","DEFAULT_INTERVAL","retryAttempt","attempt","options","retryable","series","sortBy","comparator","left","right","criteria","timeout","asyncFn","milliseconds","info","injectedCallback","timedOut","originalCallback","clearTimeout","timer","timeoutCallback","code","origCallback","baseRange","step","nativeMax$1","nativeCeil","timeLimit","count","mapLimit","transform","accumulator","k","unmemoize","whilst","until","waterfall","nextTask","taskIndex","_defer","objectProto","objectProto$1","parseInt","max","Symbol","getPrototypeOf","objectProto$2","objectProto$3","objectProto$4","Infinity","applyEach","mapSeries","applyEachSeries","apply$1","callArgs","freeGlobal","freeSelf","self","thisGlobal","root","Function","Symbol$1","symbolProto","rsAstralRange","rsComboMarksRange","rsComboSymbolsRange","rsVarRange","rsAstral","rsCombo","rsFitz","rsModifier","rsNonAstral","rsRegional","rsSurrPair","rsZWJ","reOptMod","rsOptVar","rsOptJoin","rsSeq","rsSymbol","RegExp","hasSetImmediate","setImmediate","hasNextTick","nextTick","removeLink","prev","insertAfter","newNode","_defer$1","seq","functions","newargs","nextargs","compose","concatSeries","constant","values","ignoredArgs","detect","detectLimit","detectSeries","dir","eachSeries","every","everyLimit","everySeries","filter","filterLimit","filterSeries","log","mapValues","mapValuesSeries","reject","rejectLimit","rejectSeries","some","Boolean","someLimit","someSeries","ceil","timesSeries","each","parallel","timesLimit","all","any","forEach","forEachSeries","forEachLimit","forEachOf","forEachOfSeries","forEachOfLimit","inject","foldl","foldr","select","selectLimit","selectSeries","wrapSync","allLimit","allSeries","anyLimit","anySeries","find","findLimit","findSeries"],"mappings":"CAAC,SAAUA,EAAQC,GACI,gBAAZC,UAA0C,mBAAXC,QAAyBF,EAAQC,SACrD,kBAAXE,SAAyBA,OAAOC,IAAMD,QAAQ,WAAYH,GAChEA,EAASD,EAAOM,MAAQN,EAAOM,YAClCC,KAAM,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