diff options
author | Steve Robb <softnfuzzyrobb@gmail.com> | 2016-05-16 02:34:58 +0100 |
---|---|---|
committer | Steve Robb <softnfuzzyrobb@gmail.com> | 2016-05-16 02:34:58 +0100 |
commit | 79fd8872f1c9c549450142dbd6c5c4c6b0517d76 (patch) | |
tree | fb753580655fbabeac64b740e0601423db0e7005 | |
parent | 9f1834c169bbb5f8d56ad2033393101b4762a38c (diff) | |
parent | c54345d703a3d1959e6509c066c6966b2da6ee13 (diff) | |
download | async-79fd8872f1c9c549450142dbd6c5c4c6b0517d76.tar.gz |
Merge branch 'master' into es6arrows
# Conflicts:
# mocha_test/autoInject.js
83 files changed, 5282 insertions, 5158 deletions
diff --git a/.travis.yml b/.travis.yml index a866e55..9feb56a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,7 @@ node_js: - "0.10" - "0.12" - "4" - - "5" + - "6" sudo: false after_success: npm run coveralls @@ -16,7 +16,7 @@ DIST = dist SRC = lib/index.js SCRIPTS = ./support JS_SRC = $(shell find lib/ -type f -name '*.js') -LINT_FILES = lib/ test/ mocha_test/ $(shell find perf/ -maxdepth 2 -type f) support/ karma.conf.js +LINT_FILES = lib/ mocha_test/ $(shell find perf/ -maxdepth 2 -type f) support/ karma.conf.js UMD_BUNDLE = $(BUILDDIR)/dist/async.js UMD_BUNDLE_MIN = $(BUILDDIR)/dist/async.min.js @@ -120,5 +120,5 @@ release-major release-minor release-patch release-prerelease: all # build again to propagate the version $(MAKE) build-config $(MAKE) build-es-config - cd build/ && npm pack - cd build-es/ && npm pack + cd build/ && npm publish + cd build-es/ && npm publish @@ -1,7 +1,7 @@ # Async.js [![Build Status via Travis CI](https://travis-ci.org/caolan/async.svg?branch=master)](https://travis-ci.org/caolan/async) -[![NPM version](http://img.shields.io/npm/v/async.svg)](https://www.npmjs.org/package/async) +[![NPM version](https://img.shields.io/npm/v/async.svg)](https://www.npmjs.com/package/async) [![Coverage Status](https://coveralls.io/repos/caolan/async/badge.svg?branch=master)](https://coveralls.io/r/caolan/async?branch=master) [![Join the chat at https://gitter.im/caolan/async](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/caolan/async?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) @@ -9,13 +9,13 @@ Async is a utility module which provides straight-forward, powerful functions for working with asynchronous JavaScript. Although originally designed for -use with [Node.js](http://nodejs.org) and installable via `npm install --save async`, +use with [Node.js](https://nodejs.org/) and installable via `npm install --save async`, it can also be used directly in the browser. Async is also installable via: - [bower](http://bower.io/): `bower install async` -- [component](https://github.com/component/component): `component install caolan/async` +- [component](https://github.com/componentjs/component): `component install caolan/async` - [jam](http://jamjs.org/): `jam install async` Async provides around 70 functions that include the usual 'functional' @@ -221,6 +221,7 @@ Some functions are also available in the following forms: * [`filter`](#filter), `filterSeries`, `filterLimit` * [`reject`](#reject), `rejectSeries`, `rejectLimit` * [`reduce`](#reduce), [`reduceRight`](#reduceRight) +* [`transform`](#transform) * [`detect`](#detect), `detectSeries`, `detectLimit` * [`sortBy`](#sortBy) * [`some`](#some), `someLimit`, `someSeries` @@ -442,8 +443,7 @@ __Arguments__ * `coll` - A collection to iterate over. * `iteratee(item, callback)` - 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. + The `iteratee` is passed a `callback(err, truthValue)` , which must be called with a boolean argument once it has completed. **Callback arguments changed in 2.0** * `callback(err, results)` - *Optional* A callback which is called after all the `iteratee` functions have finished. @@ -548,9 +548,7 @@ If order within the original `coll` is important, then look at `detectSeries`. __Arguments__ * `coll` - A collection to iterate over. -* `iteratee(item, callback)` - 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. +* `iteratee(item, callback)` - 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. **Callback arguments changed in 2.0** * `callback(err, result)` - *Optional* 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 @@ -640,8 +638,7 @@ __Arguments__ * `coll` - A collection to iterate over. * `iteratee(item, callback)` - 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. + in parallel. The iteratee is passed a `callback(err, truthValue)` which must be called with a boolean argument once it has completed. **Callback arguments changed in 2.0** * `callback(err, result)` - *Optional* 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. @@ -677,9 +674,7 @@ If any iteratee call returns `false`, the main `callback` is immediately called. __Arguments__ * `coll` - A collection to iterate over. -* `iteratee(item, callback)` - 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. +* `iteratee(item, callback)` - 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. **Callback arguments changed in 2.0** * `callback(err, result)` - *Optional* 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. @@ -924,7 +919,7 @@ async.whilst( ### doWhilst(fn, test, callback) The post-check version of [`whilst`](#whilst). To reflect the difference in -the order of operations, the arguments `test` and `fn` are switched. +the order of operations, the arguments `test` and `fn` are switched. The `test` function is also passed the non-error callback results of `fn`. `doWhilst` is to `whilst` as `do while` is to `while` in plain JavaScript. @@ -946,7 +941,7 @@ The inverse of [`whilst`](#whilst). ### doUntil(fn, test, callback) -Like [`doWhilst`](#doWhilst), except the `test` is inverted. Note the argument ordering differs from `until`. +Like [`doWhilst`](#doWhilst), except the `test` is inverted. Note the argument ordering differs from `until`. The `test` function is also passed the non-error callback results of `fn`. --------------------------------------- @@ -956,18 +951,26 @@ Like [`doWhilst`](#doWhilst), except the `test` is inverted. Note the argument o Like [`whilst`](#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. +Additionaly `during` passes any arguments passed by the iteratee function (2nd function) to the test function (1st function). The test callback will allways be the last parameter. + __Example__ ```js var count = 0; async.during( - function (callback) { - return callback(null, count < 5); + function (result, callback) { + if(!callback) { + callback = result; + result = null; + } + return callback(null, !result || result.counter < 5); }, function (callback) { count++; - setTimeout(callback, 1000); + setTimeout(function() { + callback(null, { counter: count }); + }, 1000); }, function (err) { // 5 seconds have passed @@ -1408,8 +1411,8 @@ async.auto({ __Arguments__ * `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. + * a `results` object, containing the results of the previously executed functions, only passed if the task has any dependencies, **Argument order changed in 2.0** + * 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. **Argument order changed in 2.0** * `concurrency` - An optional `integer` for determining the maximum number of tasks that can be run in parallel. By default, as many as possible. * `callback(err, results)` - 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. @@ -1574,7 +1577,7 @@ __Arguments__ the function's execution, and (2) a `results` object, containing the results of the previously executed functions (if nested inside another control flow). * `callback(err, results)` - 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`. + task has succeeded, or after the final failed attempt. It receives the `err` and `result` arguments of the last attempt at completing the `task`. **Callback made optional in 2.0, use `retryable` for previous behavior.** The [`retry`](#retry) function can be used as a stand-alone control flow by passing a callback, as shown below: @@ -2143,7 +2146,7 @@ function(err, results){ --------------------------------------- <a name="reflectAll"></a> -### reflectAll() +### reflectAll(tasks) A helper function that wraps an array of functions with reflect. @@ -27,6 +27,7 @@ "es6-promise": "^2.3.0", "fs-extra": "^0.26.7", "jscs": "^1.13.1", + "jscs-jsdoc": "^1.3.2", "jshint": "~2.8.0", "karma": "^0.13.2", "karma-browserify": "^4.2.1", @@ -35,7 +36,6 @@ "karma-mocha-reporter": "^1.0.2", "mocha": "^2.2.5", "native-promise-only": "^0.8.0-a", - "nodeunit": ">0.0.0", "nyc": "^2.1.0", "recursive-readdir": "^1.3.0", "rimraf": "^2.5.0", @@ -62,4 +62,4 @@ "authors": [ "Caolan McMahon" ] -}
\ No newline at end of file +} diff --git a/component.json b/component.json index 7f408f5..13ac09e 100644 --- a/component.json +++ b/component.json @@ -1,7 +1,7 @@ { "name": "async", "description": "Higher-order functions and common patterns for asynchronous code", - "version": "2.0.0-rc.3", + "version": "2.0.0-rc.4", "keywords": [ "async", "callback", diff --git a/deps/nodeunit.css b/deps/nodeunit.css deleted file mode 100644 index 274434a..0000000 --- a/deps/nodeunit.css +++ /dev/null @@ -1,70 +0,0 @@ -/*! - * Styles taken from qunit.css - */ - -h1#nodeunit-header, h1.nodeunit-header { - padding: 15px; - font-size: large; - background-color: #06b; - color: white; - font-family: 'trebuchet ms', verdana, arial; - margin: 0; -} - -h1#nodeunit-header a { - color: white; -} - -h2#nodeunit-banner { - height: 2em; - border-bottom: 1px solid white; - background-color: #eee; - margin: 0; - font-family: 'trebuchet ms', verdana, arial; -} -h2#nodeunit-banner.pass { - background-color: green; -} -h2#nodeunit-banner.fail { - background-color: red; -} - -h2#nodeunit-userAgent, h2.nodeunit-userAgent { - padding: 10px; - background-color: #eee; - color: black; - margin: 0; - font-size: small; - font-weight: normal; - font-family: 'trebuchet ms', verdana, arial; - font-size: 10pt; -} - -div#nodeunit-testrunner-toolbar { - background: #eee; - border-top: 1px solid black; - padding: 10px; - font-family: 'trebuchet ms', verdana, arial; - margin: 0; - font-size: 10pt; -} - -ol#nodeunit-tests { - font-family: 'trebuchet ms', verdana, arial; - font-size: 10pt; -} -ol#nodeunit-tests li strong { - cursor:pointer; -} -ol#nodeunit-tests .pass { - color: green; -} -ol#nodeunit-tests .fail { - color: red; -} - -p#nodeunit-testresult { - margin-left: 1em; - font-size: 10pt; - font-family: 'trebuchet ms', verdana, arial; -} diff --git a/deps/nodeunit.js b/deps/nodeunit.js deleted file mode 100644 index 6251ba1..0000000 --- a/deps/nodeunit.js +++ /dev/null @@ -1,2117 +0,0 @@ -/*! - * Nodeunit - * https://github.com/caolan/nodeunit - * Copyright (c) 2010 Caolan McMahon - * MIT Licensed - * - * json2.js - * http://www.JSON.org/json2.js - * Public Domain. - * NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK. - */ -nodeunit = (function(){ -/* - http://www.JSON.org/json2.js - 2010-11-17 - - Public Domain. - - NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK. - - See http://www.JSON.org/js.html - - - This code should be minified before deployment. - See http://javascript.crockford.com/jsmin.html - - USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO - NOT CONTROL. - - - This file creates a global JSON object containing two methods: stringify - and parse. - - JSON.stringify(value, replacer, space) - value any JavaScript value, usually an object or array. - - replacer an optional parameter that determines how object - values are stringified for objects. It can be a - function or an array of strings. - - space an optional parameter that specifies the indentation - of nested structures. If it is omitted, the text will - be packed without extra whitespace. If it is a number, - it will specify the number of spaces to indent at each - level. If it is a string (such as '\t' or ' '), - it contains the characters used to indent at each level. - - This method produces a JSON text from a JavaScript value. - - When an object value is found, if the object contains a toJSON - method, its toJSON method will be called and the result will be - stringified. A toJSON method does not serialize: it returns the - value represented by the name/value pair that should be serialized, - or undefined if nothing should be serialized. The toJSON method - will be passed the key associated with the value, and this will be - bound to the value - - For example, this would serialize Dates as ISO strings. - - Date.prototype.toJSON = function (key) { - function f(n) { - // Format integers to have at least two digits. - return n < 10 ? '0' + n : n; - } - - return this.getUTCFullYear() + '-' + - f(this.getUTCMonth() + 1) + '-' + - f(this.getUTCDate()) + 'T' + - f(this.getUTCHours()) + ':' + - f(this.getUTCMinutes()) + ':' + - f(this.getUTCSeconds()) + 'Z'; - }; - - You can provide an optional replacer method. It will be passed the - key and value of each member, with this bound to the containing - object. The value that is returned from your method will be - serialized. If your method returns undefined, then the member will - be excluded from the serialization. - - If the replacer parameter is an array of strings, then it will be - used to select the members to be serialized. It filters the results - such that only members with keys listed in the replacer array are - stringified. - - Values that do not have JSON representations, such as undefined or - functions, will not be serialized. Such values in objects will be - dropped; in arrays they will be replaced with null. You can use - a replacer function to replace those with JSON values. - JSON.stringify(undefined) returns undefined. - - The optional space parameter produces a stringification of the - value that is filled with line breaks and indentation to make it - easier to read. - - If the space parameter is a non-empty string, then that string will - be used for indentation. If the space parameter is a number, then - the indentation will be that many spaces. - - Example: - - text = JSON.stringify(['e', {pluribus: 'unum'}]); - // text is '["e",{"pluribus":"unum"}]' - - - text = JSON.stringify(['e', {pluribus: 'unum'}], null, '\t'); - // text is '[\n\t"e",\n\t{\n\t\t"pluribus": "unum"\n\t}\n]' - - text = JSON.stringify([new Date()], function (key, value) { - return this[key] instanceof Date ? - 'Date(' + this[key] + ')' : value; - }); - // text is '["Date(---current time---)"]' - - - JSON.parse(text, reviver) - This method parses a JSON text to produce an object or array. - It can throw a SyntaxError exception. - - The optional reviver parameter is a function that can filter and - transform the results. It receives each of the keys and values, - and its return value is used instead of the original value. - If it returns what it received, then the structure is not modified. - If it returns undefined then the member is deleted. - - Example: - - // Parse the text. Values that look like ISO date strings will - // be converted to Date objects. - - myData = JSON.parse(text, function (key, value) { - var a; - if (typeof value === 'string') { - a = -/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value); - if (a) { - return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4], - +a[5], +a[6])); - } - } - return value; - }); - - myData = JSON.parse('["Date(09/09/2001)"]', function (key, value) { - var d; - if (typeof value === 'string' && - value.slice(0, 5) === 'Date(' && - value.slice(-1) === ')') { - d = new Date(value.slice(5, -1)); - if (d) { - return d; - } - } - return value; - }); - - - This is a reference implementation. You are free to copy, modify, or - redistribute. -*/ - -/*jslint evil: true, strict: false, regexp: false */ - -/*members "", "\b", "\t", "\n", "\f", "\r", "\"", JSON, "\\", apply, - call, charCodeAt, getUTCDate, getUTCFullYear, getUTCHours, - getUTCMinutes, getUTCMonth, getUTCSeconds, hasOwnProperty, join, - lastIndex, length, parse, prototype, push, replace, slice, stringify, - test, toJSON, toString, valueOf -*/ - - -// Create a JSON object only if one does not already exist. We create the -// methods in a closure to avoid creating global variables. - -var JSON = {}; - -(function () { - "use strict"; - - function f(n) { - // Format integers to have at least two digits. - return n < 10 ? '0' + n : n; - } - - if (typeof Date.prototype.toJSON !== 'function') { - - Date.prototype.toJSON = function (key) { - - return isFinite(this.valueOf()) ? - this.getUTCFullYear() + '-' + - f(this.getUTCMonth() + 1) + '-' + - f(this.getUTCDate()) + 'T' + - f(this.getUTCHours()) + ':' + - f(this.getUTCMinutes()) + ':' + - f(this.getUTCSeconds()) + 'Z' : null; - }; - - String.prototype.toJSON = - Number.prototype.toJSON = - Boolean.prototype.toJSON = function (key) { - return this.valueOf(); - }; - } - - var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, - escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, - gap, - indent, - meta = { // table of character substitutions - '\b': '\\b', - '\t': '\\t', - '\n': '\\n', - '\f': '\\f', - '\r': '\\r', - '"' : '\\"', - '\\': '\\\\' - }, - rep; - - - function quote(string) { - -// If the string contains no control characters, no quote characters, and no -// backslash characters, then we can safely slap some quotes around it. -// Otherwise we must also replace the offending characters with safe escape -// sequences. - - escapable.lastIndex = 0; - return escapable.test(string) ? - '"' + string.replace(escapable, function (a) { - var c = meta[a]; - return typeof c === 'string' ? c : - '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4); - }) + '"' : - '"' + string + '"'; - } - - - function str(key, holder) { - -// Produce a string from holder[key]. - - var i, // The loop counter. - k, // The member key. - v, // The member value. - length, - mind = gap, - partial, - value = holder[key]; - -// If the value has a toJSON method, call it to obtain a replacement value. - - if (value && typeof value === 'object' && - typeof value.toJSON === 'function') { - value = value.toJSON(key); - } - -// If we were called with a replacer function, then call the replacer to -// obtain a replacement value. - - if (typeof rep === 'function') { - value = rep.call(holder, key, value); - } - -// What happens next depends on the value's type. - - switch (typeof value) { - case 'string': - return quote(value); - - case 'number': - -// JSON numbers must be finite. Encode non-finite numbers as null. - - return isFinite(value) ? String(value) : 'null'; - - case 'boolean': - case 'null': - -// If the value is a boolean or null, convert it to a string. Note: -// typeof null does not produce 'null'. The case is included here in -// the remote chance that this gets fixed someday. - - return String(value); - -// If the type is 'object', we might be dealing with an object or an array or -// null. - - case 'object': - -// Due to a specification blunder in ECMAScript, typeof null is 'object', -// so watch out for that case. - - if (!value) { - return 'null'; - } - -// Make an array to hold the partial results of stringifying this object value. - - gap += indent; - partial = []; - -// Is the value an array? - - if (Object.prototype.toString.apply(value) === '[object Array]') { - -// The value is an array. Stringify every element. Use null as a placeholder -// for non-JSON values. - - length = value.length; - for (i = 0; i < length; i += 1) { - partial[i] = str(i, value) || 'null'; - } - -// Join all of the elements together, separated with commas, and wrap them in -// brackets. - - v = partial.length === 0 ? '[]' : - gap ? '[\n' + gap + - partial.join(',\n' + gap) + '\n' + - mind + ']' : - '[' + partial.join(',') + ']'; - gap = mind; - return v; - } - -// If the replacer is an array, use it to select the members to be stringified. - - if (rep && typeof rep === 'object') { - length = rep.length; - for (i = 0; i < length; i += 1) { - k = rep[i]; - if (typeof k === 'string') { - v = str(k, value); - if (v) { - partial.push(quote(k) + (gap ? ': ' : ':') + v); - } - } - } - } else { - -// Otherwise, iterate through all of the keys in the object. - - for (k in value) { - if (Object.hasOwnProperty.call(value, k)) { - v = str(k, value); - if (v) { - partial.push(quote(k) + (gap ? ': ' : ':') + v); - } - } - } - } - -// Join all of the member texts together, separated with commas, -// and wrap them in braces. - - v = partial.length === 0 ? '{}' : - gap ? '{\n' + gap + partial.join(',\n' + gap) + '\n' + - mind + '}' : '{' + partial.join(',') + '}'; - gap = mind; - return v; - } - } - -// If the JSON object does not yet have a stringify method, give it one. - - if (typeof JSON.stringify !== 'function') { - JSON.stringify = function (value, replacer, space) { - -// The stringify method takes a value and an optional replacer, and an optional -// space parameter, and returns a JSON text. The replacer can be a function -// that can replace values, or an array of strings that will select the keys. -// A default replacer method can be provided. Use of the space parameter can -// produce text that is more easily readable. - - var i; - gap = ''; - indent = ''; - -// If the space parameter is a number, make an indent string containing that -// many spaces. - - if (typeof space === 'number') { - for (i = 0; i < space; i += 1) { - indent += ' '; - } - -// If the space parameter is a string, it will be used as the indent string. - - } else if (typeof space === 'string') { - indent = space; - } - -// If there is a replacer, it must be a function or an array. -// Otherwise, throw an error. - - rep = replacer; - if (replacer && typeof replacer !== 'function' && - (typeof replacer !== 'object' || - typeof replacer.length !== 'number')) { - throw new Error('JSON.stringify'); - } - -// Make a fake root object containing our value under the key of ''. -// Return the result of stringifying the value. - - return str('', {'': value}); - }; - } - - -// If the JSON object does not yet have a parse method, give it one. - - if (typeof JSON.parse !== 'function') { - JSON.parse = function (text, reviver) { - -// The parse method takes a text and an optional reviver function, and returns -// a JavaScript value if the text is a valid JSON text. - - var j; - - function walk(holder, key) { - -// The walk method is used to recursively walk the resulting structure so -// that modifications can be made. - - var k, v, value = holder[key]; - if (value && typeof value === 'object') { - for (k in value) { - if (Object.hasOwnProperty.call(value, k)) { - v = walk(value, k); - if (v !== undefined) { - value[k] = v; - } else { - delete value[k]; - } - } - } - } - return reviver.call(holder, key, value); - } - - -// Parsing happens in four stages. In the first stage, we replace certain -// Unicode characters with escape sequences. JavaScript handles many characters -// incorrectly, either silently deleting them, or treating them as line endings. - - text = String(text); - cx.lastIndex = 0; - if (cx.test(text)) { - text = text.replace(cx, function (a) { - return '\\u' + - ('0000' + a.charCodeAt(0).toString(16)).slice(-4); - }); - } - -// In the second stage, we run the text against regular expressions that look -// for non-JSON patterns. We are especially concerned with '()' and 'new' -// because they can cause invocation, and '=' because it can cause mutation. -// But just to be safe, we want to reject all unexpected forms. - -// We split the second stage into 4 regexp operations in order to work around -// crippling inefficiencies in IE's and Safari's regexp engines. First we -// replace the JSON backslash pairs with '@' (a non-JSON character). Second, we -// replace all simple value tokens with ']' characters. Third, we delete all -// open brackets that follow a colon or comma or that begin the text. Finally, -// we look to see that the remaining characters are only whitespace or ']' or -// ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval. - - if (/^[\],:{}\s]*$/ -.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@') -.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']') -.replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) { - -// In the third stage we use the eval function to compile the text into a -// JavaScript structure. The '{' operator is subject to a syntactic ambiguity -// in JavaScript: it can begin a block or an object literal. We wrap the text -// in parens to eliminate the ambiguity. - - j = eval('(' + text + ')'); - -// In the optional fourth stage, we recursively walk the new structure, passing -// each name/value pair to a reviver function for possible transformation. - - return typeof reviver === 'function' ? - walk({'': j}, '') : j; - } - -// If the text is not JSON parseable, then a SyntaxError is thrown. - - throw new SyntaxError('JSON.parse'); - }; - } -}()); -var assert = this.assert = {}; -var types = {}; -var core = {}; -var nodeunit = {}; -var reporter = {}; -/*global setTimeout: false, console: false */ -(function () { - - var async = {}; - - // global on the server, window in the browser - var root = this, - previous_async = root.async; - - if (typeof module !== 'undefined' && module.exports) { - module.exports = async; - } - else { - root.async = async; - } - - async.noConflict = function () { - root.async = previous_async; - return async; - }; - - //// cross-browser compatiblity functions //// - - var _forEach = function (arr, iterator) { - if (arr.forEach) { - return arr.forEach(iterator); - } - for (var i = 0; i < arr.length; i += 1) { - iterator(arr[i], i, arr); - } - }; - - var _map = function (arr, iterator) { - if (arr.map) { - return arr.map(iterator); - } - var results = []; - _forEach(arr, function (x, i, a) { - results.push(iterator(x, i, a)); - }); - return results; - }; - - var _reduce = function (arr, iterator, memo) { - if (arr.reduce) { - return arr.reduce(iterator, memo); - } - _forEach(arr, function (x, i, a) { - memo = iterator(memo, x, i, a); - }); - return memo; - }; - - var _keys = function (obj) { - if (Object.keys) { - return Object.keys(obj); - } - var keys = []; - for (var k in obj) { - if (obj.hasOwnProperty(k)) { - keys.push(k); - } - } - return keys; - }; - - var _indexOf = function (arr, item) { - if (arr.indexOf) { - return arr.indexOf(item); - } - for (var i = 0; i < arr.length; i += 1) { - if (arr[i] === item) { - return i; - } - } - return -1; - }; - - //// exported async module functions //// - - //// nextTick implementation with browser-compatible fallback //// - if (typeof setImmediate === 'function') { - async.nextTick = function (fn) { - setImmediate(fn); - }; - } - else if (typeof process !== 'undefined' && process.nextTick) { - async.nextTick = process.nextTick; - } - else { - async.nextTick = function (fn) { - setTimeout(fn, 0); - }; - } - - async.forEach = function (arr, iterator, callback) { - if (!arr.length) { - return callback(); - } - var completed = 0; - _forEach(arr, function (x) { - iterator(x, function (err) { - if (err) { - callback(err); - callback = function () {}; - } - else { - completed += 1; - if (completed === arr.length) { - callback(); - } - } - }); - }); - }; - - async.forEachSeries = function (arr, iterator, callback) { - if (!arr.length) { - return callback(); - } - var completed = 0; - var iterate = function () { - iterator(arr[completed], function (err) { - if (err) { - callback(err); - callback = function () {}; - } - else { - completed += 1; - if (completed === arr.length) { - callback(); - } - else { - iterate(); - } - } - }); - }; - iterate(); - }; - - - var doParallel = function (fn) { - return function () { - var args = Array.prototype.slice.call(arguments); - return fn.apply(null, [async.forEach].concat(args)); - }; - }; - var doSeries = function (fn) { - return function () { - var args = Array.prototype.slice.call(arguments); - return fn.apply(null, [async.forEachSeries].concat(args)); - }; - }; - - - var _asyncMap = function (eachfn, arr, iterator, callback) { - var results = []; - arr = _map(arr, function (x, i) { - return {index: i, value: x}; - }); - eachfn(arr, function (x, callback) { - iterator(x.value, function (err, v) { - results[x.index] = v; - callback(err); - }); - }, function (err) { - callback(err, results); - }); - }; - async.map = doParallel(_asyncMap); - async.mapSeries = doSeries(_asyncMap); - - - // reduce only has a series version, as doing reduce in parallel won't - // work in many situations. - async.reduce = function (arr, memo, iterator, callback) { - async.forEachSeries(arr, function (x, callback) { - iterator(memo, x, function (err, v) { - memo = v; - callback(err); - }); - }, function (err) { - callback(err, memo); - }); - }; - // inject alias - async.inject = async.reduce; - // foldl alias - async.foldl = async.reduce; - - async.reduceRight = function (arr, memo, iterator, callback) { - var reversed = _map(arr, function (x) { - return x; - }).reverse(); - async.reduce(reversed, memo, iterator, callback); - }; - // foldr alias - async.foldr = async.reduceRight; - - var _filter = function (eachfn, arr, iterator, callback) { - var results = []; - arr = _map(arr, function (x, i) { - return {index: i, value: x}; - }); - eachfn(arr, function (x, callback) { - iterator(x.value, function (v) { - if (v) { - results.push(x); - } - callback(); - }); - }, function (err) { - callback(_map(results.sort(function (a, b) { - return a.index - b.index; - }), function (x) { - return x.value; - })); - }); - }; - async.filter = doParallel(_filter); - async.filterSeries = doSeries(_filter); - // select alias - async.select = async.filter; - async.selectSeries = async.filterSeries; - - var _reject = function (eachfn, arr, iterator, callback) { - var results = []; - arr = _map(arr, function (x, i) { - return {index: i, value: x}; - }); - eachfn(arr, function (x, callback) { - iterator(x.value, function (v) { - if (!v) { - results.push(x); - } - callback(); - }); - }, function (err) { - callback(_map(results.sort(function (a, b) { - return a.index - b.index; - }), function (x) { - return x.value; - })); - }); - }; - async.reject = doParallel(_reject); - async.rejectSeries = doSeries(_reject); - - var _detect = function (eachfn, arr, iterator, main_callback) { - eachfn(arr, function (x, callback) { - iterator(x, function (result) { - if (result) { - main_callback(x); - } - else { - callback(); - } - }); - }, function (err) { - main_callback(); - }); - }; - async.detect = doParallel(_detect); - async.detectSeries = doSeries(_detect); - - async.some = function (arr, iterator, main_callback) { - async.forEach(arr, function (x, callback) { - iterator(x, function (v) { - if (v) { - main_callback(true); - main_callback = function () {}; - } - callback(); - }); - }, function (err) { - main_callback(false); - }); - }; - // any alias - async.any = async.some; - - async.every = function (arr, iterator, main_callback) { - async.forEach(arr, function (x, callback) { - iterator(x, function (v) { - if (!v) { - main_callback(false); - main_callback = function () {}; - } - callback(); - }); - }, function (err) { - main_callback(true); - }); - }; - // all alias - async.all = async.every; - - async.sortBy = function (arr, iterator, callback) { - async.map(arr, function (x, callback) { - iterator(x, function (err, criteria) { - if (err) { - callback(err); - } - else { - callback(null, {value: x, criteria: criteria}); - } - }); - }, function (err, results) { - if (err) { - return callback(err); - } - else { - var fn = function (left, right) { - var a = left.criteria, b = right.criteria; - return a < b ? -1 : a > b ? 1 : 0; - }; - callback(null, _map(results.sort(fn), function (x) { - return x.value; - })); - } - }); - }; - - async.auto = function (tasks, callback) { - callback = callback || function () {}; - var keys = _keys(tasks); - if (!keys.length) { - return callback(null); - } - - var completed = []; - - var listeners = []; - var addListener = function (fn) { - listeners.unshift(fn); - }; - var removeListener = function (fn) { - for (var i = 0; i < listeners.length; i += 1) { - if (listeners[i] === fn) { - listeners.splice(i, 1); - return; - } - } - }; - var taskComplete = function () { - _forEach(listeners, function (fn) { - fn(); - }); - }; - - addListener(function () { - if (completed.length === keys.length) { - callback(null); - } - }); - - _forEach(keys, function (k) { - var task = (tasks[k] instanceof Function) ? [tasks[k]]: tasks[k]; - var taskCallback = function (err) { - if (err) { - callback(err); - // stop subsequent errors hitting callback multiple times - callback = function () {}; - } - else { - completed.push(k); - taskComplete(); - } - }; - var requires = task.slice(0, Math.abs(task.length - 1)) || []; - var ready = function () { - return _reduce(requires, function (a, x) { - return (a && _indexOf(completed, x) !== -1); - }, true); - }; - if (ready()) { - task[task.length - 1](taskCallback); - } - else { - var listener = function () { - if (ready()) { - removeListener(listener); - task[task.length - 1](taskCallback); - } - }; - addListener(listener); - } - }); - }; - - async.waterfall = function (tasks, callback) { - if (!tasks.length) { - return callback(); - } - callback = callback || function () {}; - var wrapIterator = function (iterator) { - return function (err) { - if (err) { - callback(err); - callback = function () {}; - } - else { - var args = Array.prototype.slice.call(arguments, 1); - var next = iterator.next(); - if (next) { - args.push(wrapIterator(next)); - } - else { - args.push(callback); - } - async.nextTick(function () { - iterator.apply(null, args); - }); - } - }; - }; - wrapIterator(async.iterator(tasks))(); - }; - - async.parallel = function (tasks, callback) { - callback = callback || function () {}; - if (tasks.constructor === Array) { - async.map(tasks, function (fn, callback) { - if (fn) { - fn(function (err) { - var args = Array.prototype.slice.call(arguments, 1); - if (args.length <= 1) { - args = args[0]; - } - callback.call(null, err, args || null); - }); - } - }, callback); - } - else { - var results = {}; - async.forEach(_keys(tasks), function (k, callback) { - tasks[k](function (err) { - var args = Array.prototype.slice.call(arguments, 1); - if (args.length <= 1) { - args = args[0]; - } - results[k] = args; - callback(err); - }); - }, function (err) { - callback(err, results); - }); - } - }; - - async.series = function (tasks, callback) { - callback = callback || function () {}; - if (tasks.constructor === Array) { - async.mapSeries(tasks, function (fn, callback) { - if (fn) { - fn(function (err) { - var args = Array.prototype.slice.call(arguments, 1); - if (args.length <= 1) { - args = args[0]; - } - callback.call(null, err, args || null); - }); - } - }, callback); - } - else { - var results = {}; - async.forEachSeries(_keys(tasks), function (k, callback) { - tasks[k](function (err) { - var args = Array.prototype.slice.call(arguments, 1); - if (args.length <= 1) { - args = args[0]; - } - results[k] = args; - callback(err); - }); - }, function (err) { - callback(err, results); - }); - } - }; - - async.iterator = function (tasks) { - var makeCallback = function (index) { - var fn = function () { - if (tasks.length) { - tasks[index].apply(null, arguments); - } - return fn.next(); - }; - fn.next = function () { - return (index < tasks.length - 1) ? makeCallback(index + 1): null; - }; - return fn; - }; - return makeCallback(0); - }; - - async.apply = function (fn) { - var args = Array.prototype.slice.call(arguments, 1); - return function () { - return fn.apply( - null, args.concat(Array.prototype.slice.call(arguments)) - ); - }; - }; - - var _concat = function (eachfn, arr, fn, callback) { - var r = []; - eachfn(arr, function (x, cb) { - fn(x, function (err, y) { - r = r.concat(y || []); - cb(err); - }); - }, function (err) { - callback(err, r); - }); - }; - async.concat = doParallel(_concat); - async.concatSeries = doSeries(_concat); - - async.whilst = function (test, iterator, callback) { - if (test()) { - iterator(function (err) { - if (err) { - return callback(err); - } - async.whilst(test, iterator, callback); - }); - } - else { - callback(); - } - }; - - async.until = function (test, iterator, callback) { - if (!test()) { - iterator(function (err) { - if (err) { - return callback(err); - } - async.until(test, iterator, callback); - }); - } - else { - callback(); - } - }; - - async.queue = function (worker, concurrency) { - var workers = 0; - var tasks = []; - var q = { - concurrency: concurrency, - push: function (data, callback) { - tasks.push({data: data, callback: callback}); - async.nextTick(q.process); - }, - process: function () { - if (workers < q.concurrency && tasks.length) { - var task = tasks.splice(0, 1)[0]; - workers += 1; - worker(task.data, function () { - workers -= 1; - if (task.callback) { - task.callback.apply(task, arguments); - } - q.process(); - }); - } - }, - length: function () { - return tasks.length; - } - }; - return q; - }; - - var _console_fn = function (name) { - return function (fn) { - var args = Array.prototype.slice.call(arguments, 1); - fn.apply(null, args.concat([function (err) { - var args = Array.prototype.slice.call(arguments, 1); - if (typeof console !== 'undefined') { - if (err) { - if (console.error) { - console.error(err); - } - } - else if (console[name]) { - _forEach(args, function (x) { - console[name](x); - }); - } - } - }])); - }; - }; - async.log = _console_fn('log'); - async.dir = _console_fn('dir'); - /*async.info = _console_fn('info'); - async.warn = _console_fn('warn'); - async.error = _console_fn('error');*/ - - async.memoize = function (fn, hasher) { - var memo = {}; - hasher = hasher || function (x) { - return x; - }; - return function () { - var args = Array.prototype.slice.call(arguments); - var callback = args.pop(); - var key = hasher.apply(null, args); - if (key in memo) { - callback.apply(null, memo[key]); - } - else { - fn.apply(null, args.concat([function () { - memo[key] = arguments; - callback.apply(null, arguments); - }])); - } - }; - }; - -}()); -(function(exports){ -/** - * This file is based on the node.js assert module, but with some small - * changes for browser-compatibility - * THIS FILE SHOULD BE BROWSER-COMPATIBLE JS! - */ - - -/** - * Added for browser compatibility - */ - -var _keys = function(obj){ - if(Object.keys) return Object.keys(obj); - if (typeof obj != 'object' && typeof obj != 'function') { - throw new TypeError('-'); - } - var keys = []; - for(var k in obj){ - if(obj.hasOwnProperty(k)) keys.push(k); - } - return keys; -}; - - - -// http://wiki.commonjs.org/wiki/Unit_Testing/1.0 -// -// THIS IS NOT TESTED NOR LIKELY TO WORK OUTSIDE V8! -// -// Originally from narwhal.js (http://narwhaljs.org) -// Copyright (c) 2009 Thomas Robinson <280north.com> -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the 'Software'), to -// deal in the Software without restriction, including without limitation the -// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -// sell copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - - -var pSlice = Array.prototype.slice; - -// 1. The assert module provides functions that throw -// AssertionError's when particular conditions are not met. The -// assert module must conform to the following interface. - -var assert = exports; - -// 2. The AssertionError is defined in assert. -// new assert.AssertionError({message: message, actual: actual, expected: expected}) - -assert.AssertionError = function AssertionError (options) { - this.name = "AssertionError"; - this.message = options.message; - this.actual = options.actual; - this.expected = options.expected; - this.operator = options.operator; - var stackStartFunction = options.stackStartFunction || fail; - - if (Error.captureStackTrace) { - Error.captureStackTrace(this, stackStartFunction); - } -}; -// code from util.inherits in node -assert.AssertionError.super_ = Error; - - -// EDITED FOR BROWSER COMPATIBILITY: replaced Object.create call -// TODO: test what effect this may have -var ctor = function () { this.constructor = assert.AssertionError; }; -ctor.prototype = Error.prototype; -assert.AssertionError.prototype = new ctor(); - - -assert.AssertionError.prototype.toString = function() { - if (this.message) { - return [this.name+":", this.message].join(' '); - } else { - return [ this.name+":" - , typeof this.expected !== 'undefined' ? JSON.stringify(this.expected) : 'undefined' - , this.operator - , typeof this.actual !== 'undefined' ? JSON.stringify(this.actual) : 'undefined' - ].join(" "); - } -}; - -// assert.AssertionError instanceof Error - -assert.AssertionError.__proto__ = Error.prototype; - -// At present only the three keys mentioned above are used and -// understood by the spec. Implementations or sub modules can pass -// other keys to the AssertionError's constructor - they will be -// ignored. - -// 3. All of the following functions must throw an AssertionError -// when a corresponding condition is not met, with a message that -// may be undefined if not provided. All assertion methods provide -// both the actual and expected values to the assertion error for -// display purposes. - -function fail(actual, expected, message, operator, stackStartFunction) { - throw new assert.AssertionError({ - message: message, - actual: actual, - expected: expected, - operator: operator, - stackStartFunction: stackStartFunction - }); -} - -// EXTENSION! allows for well behaved errors defined elsewhere. -assert.fail = fail; - -// 4. Pure assertion tests whether a value is truthy, as determined -// by !!guard. -// assert.ok(guard, message_opt); -// This statement is equivalent to assert.equal(true, guard, -// message_opt);. To test strictly for the value true, use -// assert.strictEqual(true, guard, message_opt);. - -assert.ok = function ok(value, message) { - if (!!!value) fail(value, true, message, "==", assert.ok); -}; - -// 5. The equality assertion tests shallow, coercive equality with -// ==. -// assert.equal(actual, expected, message_opt); - -assert.equal = function equal(actual, expected, message) { - if (actual != expected) fail(actual, expected, message, "==", assert.equal); -}; - -// 6. The non-equality assertion tests for whether two objects are not equal -// with != assert.notEqual(actual, expected, message_opt); - -assert.notEqual = function notEqual(actual, expected, message) { - if (actual == expected) { - fail(actual, expected, message, "!=", assert.notEqual); - } -}; - -// 7. The equivalence assertion tests a deep equality relation. -// assert.deepEqual(actual, expected, message_opt); - -assert.deepEqual = function deepEqual(actual, expected, message) { - if (!_deepEqual(actual, expected)) { - fail(actual, expected, message, "deepEqual", assert.deepEqual); - } -}; - -var Buffer = null; -if (typeof require !== 'undefined' && typeof process !== 'undefined') { - try { - Buffer = require('buffer').Buffer; - } - catch (e) { - // May be a CommonJS environment other than Node.js - Buffer = null; - } -} - -function _deepEqual(actual, expected) { - // 7.1. All identical values are equivalent, as determined by ===. - if (actual === expected) { - return true; - // 7.2. If the expected value is a Date object, the actual value is - // equivalent if it is also a Date object that refers to the same time. - } else if (actual instanceof Date && expected instanceof Date) { - return actual.getTime() === expected.getTime(); - - // 7.2.1 If the expcted value is a RegExp object, the actual value is - // equivalent if it is also a RegExp object that refers to the same source and options - } else if (actual instanceof RegExp && expected instanceof RegExp) { - return actual.source === expected.source && - actual.global === expected.global && - actual.ignoreCase === expected.ignoreCase && - actual.multiline === expected.multiline; - - } else if (Buffer && actual instanceof Buffer && expected instanceof Buffer) { - return (function() { - var i, len; - - for (i = 0, len = expected.length; i < len; i++) { - if (actual[i] !== expected[i]) { - return false; - } - } - return actual.length === expected.length; - })(); - // 7.3. Other pairs that do not both pass typeof value == "object", - // equivalence is determined by ==. - } else if (typeof actual != 'object' && typeof expected != 'object') { - return actual == expected; - - // 7.4. For all other Object pairs, including Array objects, equivalence is - // determined by having the same number of owned properties (as verified - // with Object.prototype.hasOwnProperty.call), the same set of keys - // (although not necessarily the same order), equivalent values for every - // corresponding key, and an identical "prototype" property. Note: this - // accounts for both named and indexed properties on Arrays. - } else { - return objEquiv(actual, expected); - } -} - -function isUndefinedOrNull (value) { - return value === null || value === undefined; -} - -function isArguments (object) { - return Object.prototype.toString.call(object) == '[object Arguments]'; -} - -function objEquiv (a, b) { - if (isUndefinedOrNull(a) || isUndefinedOrNull(b)) - return false; - // an identical "prototype" property. - if (a.prototype !== b.prototype) return false; - //~~~I've managed to break Object.keys through screwy arguments passing. - // Converting to array solves the problem. - if (isArguments(a)) { - if (!isArguments(b)) { - return false; - } - a = pSlice.call(a); - b = pSlice.call(b); - return _deepEqual(a, b); - } - try{ - var ka = _keys(a), - kb = _keys(b), - key, i; - } catch (e) {//happens when one is a string literal and the other isn't - return false; - } - // having the same number of owned properties (keys incorporates hasOwnProperty) - if (ka.length != kb.length) - return false; - //the same set of keys (although not necessarily the same order), - ka.sort(); - kb.sort(); - //~~~cheap key test - for (i = ka.length - 1; i >= 0; i--) { - if (ka[i] != kb[i]) - return false; - } - //equivalent values for every corresponding key, and - //~~~possibly expensive deep test - for (i = ka.length - 1; i >= 0; i--) { - key = ka[i]; - if (!_deepEqual(a[key], b[key] )) - return false; - } - return true; -} - -// 8. The non-equivalence assertion tests for any deep inequality. -// assert.notDeepEqual(actual, expected, message_opt); - -assert.notDeepEqual = function notDeepEqual(actual, expected, message) { - if (_deepEqual(actual, expected)) { - fail(actual, expected, message, "notDeepEqual", assert.notDeepEqual); - } -}; - -// 9. The strict equality assertion tests strict equality, as determined by ===. -// assert.strictEqual(actual, expected, message_opt); - -assert.strictEqual = function strictEqual(actual, expected, message) { - if (actual !== expected) { - fail(actual, expected, message, "===", assert.strictEqual); - } -}; - -// 10. The strict non-equality assertion tests for strict inequality, as determined by !==. -// assert.notStrictEqual(actual, expected, message_opt); - -assert.notStrictEqual = function notStrictEqual(actual, expected, message) { - if (actual === expected) { - fail(actual, expected, message, "!==", assert.notStrictEqual); - } -}; - -function expectedException(actual, expected) { - if (!actual || !expected) { - return false; - } - - if (expected instanceof RegExp) { - return expected.test(actual.message || actual); - } else if (actual instanceof expected) { - return true; - } else if (expected.call({}, actual) === true) { - return true; - } - - return false; -} - -function _throws(shouldThrow, block, expected, message) { - var actual; - - if (typeof expected === 'string') { - message = expected; - expected = null; - } - - try { - block(); - } catch (e) { - actual = e; - } - - message = (expected && expected.name ? ' (' + expected.name + ').' : '.') + - (message ? ' ' + message : '.'); - - if (shouldThrow && !actual) { - fail('Missing expected exception' + message); - } - - if (!shouldThrow && expectedException(actual, expected)) { - fail('Got unwanted exception' + message); - } - - if ((shouldThrow && actual && expected && - !expectedException(actual, expected)) || (!shouldThrow && actual)) { - throw actual; - } -} - -// 11. Expected to throw an error: -// assert.throws(block, Error_opt, message_opt); - -assert.throws = function(block, /*optional*/error, /*optional*/message) { - _throws.apply(this, [true].concat(pSlice.call(arguments))); -}; - -// EXTENSION! This is annoying to write outside this module. -assert.doesNotThrow = function(block, /*optional*/error, /*optional*/message) { - _throws.apply(this, [false].concat(pSlice.call(arguments))); -}; - -assert.ifError = function (err) { if (err) {throw err;}}; -})(assert); -(function(exports){ -/*! - * Nodeunit - * Copyright (c) 2010 Caolan McMahon - * MIT Licensed - * - * THIS FILE SHOULD BE BROWSER-COMPATIBLE JS! - * Only code on that line will be removed, it's mostly to avoid requiring code - * that is node specific - */ - -/** - * Module dependencies - */ - - - -/** - * Creates assertion objects representing the result of an assert call. - * Accepts an object or AssertionError as its argument. - * - * @param {object} obj - * @api public - */ - -exports.assertion = function (obj) { - return { - method: obj.method || '', - message: obj.message || (obj.error && obj.error.message) || '', - error: obj.error, - passed: function () { - return !this.error; - }, - failed: function () { - return Boolean(this.error); - } - }; -}; - -/** - * Creates an assertion list object representing a group of assertions. - * Accepts an array of assertion objects. - * - * @param {Array} arr - * @param {Number} duration - * @api public - */ - -exports.assertionList = function (arr, duration) { - var that = arr || []; - that.failures = function () { - var failures = 0; - for (var i = 0; i < this.length; i += 1) { - if (this[i].failed()) { - failures += 1; - } - } - return failures; - }; - that.passes = function () { - return that.length - that.failures(); - }; - that.duration = duration || 0; - return that; -}; - -/** - * Create a wrapper function for assert module methods. Executes a callback - * after it's complete with an assertion object representing the result. - * - * @param {Function} callback - * @api private - */ - -var assertWrapper = function (callback) { - return function (new_method, assert_method, arity) { - return function () { - var message = arguments[arity - 1]; - var a = exports.assertion({method: new_method, message: message}); - try { - assert[assert_method].apply(null, arguments); - } - catch (e) { - a.error = e; - } - callback(a); - }; - }; -}; - -/** - * Creates the 'test' object that gets passed to every test function. - * Accepts the name of the test function as its first argument, followed by - * the start time in ms, the options object and a callback function. - * - * @param {String} name - * @param {Number} start - * @param {Object} options - * @param {Function} callback - * @api public - */ - -exports.test = function (name, start, options, callback) { - var expecting; - var a_list = []; - - var wrapAssert = assertWrapper(function (a) { - a_list.push(a); - if (options.log) { - async.nextTick(function () { - options.log(a); - }); - } - }); - - var test = { - done: function (err) { - if (expecting !== undefined && expecting !== a_list.length) { - var e = new Error( - 'Expected ' + expecting + ' assertions, ' + - a_list.length + ' ran' - ); - var a1 = exports.assertion({method: 'expect', error: e}); - a_list.push(a1); - if (options.log) { - async.nextTick(function () { - options.log(a1); - }); - } - } - if (err) { - var a2 = exports.assertion({error: err}); - a_list.push(a2); - if (options.log) { - async.nextTick(function () { - options.log(a2); - }); - } - } - var end = new Date().getTime(); - async.nextTick(function () { - var assertion_list = exports.assertionList(a_list, end - start); - options.testDone(name, assertion_list); - callback(null, a_list); - }); - }, - ok: wrapAssert('ok', 'ok', 2), - same: wrapAssert('same', 'deepEqual', 3), - equals: wrapAssert('equals', 'equal', 3), - expect: function (num) { - expecting = num; - }, - _assertion_list: a_list - }; - // add all functions from the assert module - for (var k in assert) { - if (assert.hasOwnProperty(k)) { - test[k] = wrapAssert(k, k, assert[k].length); - } - } - return test; -}; - -/** - * Ensures an options object has all callbacks, adding empty callback functions - * if any are missing. - * - * @param {Object} opt - * @return {Object} - * @api public - */ - -exports.options = function (opt) { - var optionalCallback = function (name) { - opt[name] = opt[name] || function () {}; - }; - - optionalCallback('moduleStart'); - optionalCallback('moduleDone'); - optionalCallback('testStart'); - optionalCallback('testReady'); - optionalCallback('testDone'); - //optionalCallback('log'); - - // 'done' callback is not optional. - - return opt; -}; -})(types); -(function(exports){ -/*! - * Nodeunit - * Copyright (c) 2010 Caolan McMahon - * MIT Licensed - * - * THIS FILE SHOULD BE BROWSER-COMPATIBLE JS! - * Only code on that line will be removed, it's mostly to avoid requiring code - * that is node specific - */ - -/** - * Module dependencies - */ - - - -/** - * Added for browser compatibility - */ - -var _keys = function (obj) { - if (Object.keys) { - return Object.keys(obj); - } - var keys = []; - for (var k in obj) { - if (obj.hasOwnProperty(k)) { - keys.push(k); - } - } - return keys; -}; - - -var _copy = function (obj) { - var nobj = {}; - var keys = _keys(obj); - for (var i = 0; i < keys.length; i += 1) { - nobj[keys[i]] = obj[keys[i]]; - } - return nobj; -}; - - -/** - * Runs a test function (fn) from a loaded module. After the test function - * calls test.done(), the callback is executed with an assertionList as its - * second argument. - * - * @param {String} name - * @param {Function} fn - * @param {Object} opt - * @param {Function} callback - * @api public - */ - -exports.runTest = function (name, fn, opt, callback) { - var options = types.options(opt); - - options.testStart(name); - var start = new Date().getTime(); - var test = types.test(name, start, options, callback); - - options.testReady(test); - try { - fn(test); - } - catch (e) { - test.done(e); - } -}; - -/** - * Takes an object containing test functions or other test suites as properties - * and runs each in series. After all tests have completed, the callback is - * called with a list of all assertions as the second argument. - * - * If a name is passed to this function it is prepended to all test and suite - * names that run within it. - * - * @param {String} name - * @param {Object} suite - * @param {Object} opt - * @param {Function} callback - * @api public - */ - -exports.runSuite = function (name, suite, opt, callback) { - suite = wrapGroup(suite); - var keys = _keys(suite); - - async.concatSeries(keys, function (k, cb) { - var prop = suite[k], _name; - - _name = name ? [].concat(name, k) : [k]; - _name.toString = function () { - // fallback for old one - return this.join(' - '); - }; - - if (typeof prop === 'function') { - var in_name = false, - in_specific_test = (_name.toString() === opt.testFullSpec) ? true : false; - for (var i = 0; i < _name.length; i += 1) { - if (_name[i] === opt.testspec) { - in_name = true; - } - } - - if ((!opt.testFullSpec || in_specific_test) && (!opt.testspec || in_name)) { - if (opt.moduleStart) { - opt.moduleStart(); - } - exports.runTest(_name, suite[k], opt, cb); - } - else { - return cb(); - } - } - else { - exports.runSuite(_name, suite[k], opt, cb); - } - }, callback); -}; - -/** - * Run each exported test function or test suite from a loaded module. - * - * @param {String} name - * @param {Object} mod - * @param {Object} opt - * @param {Function} callback - * @api public - */ - -exports.runModule = function (name, mod, opt, callback) { - var options = _copy(types.options(opt)); - - var _run = false; - var _moduleStart = options.moduleStart; - - mod = wrapGroup(mod); - - function run_once() { - if (!_run) { - _run = true; - _moduleStart(name); - } - } - options.moduleStart = run_once; - - var start = new Date().getTime(); - - exports.runSuite(null, mod, options, function (err, a_list) { - var end = new Date().getTime(); - var assertion_list = types.assertionList(a_list, end - start); - options.moduleDone(name, assertion_list); - if (nodeunit.complete) { - nodeunit.complete(name, assertion_list); - } - callback(null, a_list); - }); -}; - -/** - * Treats an object literal as a list of modules keyed by name. Runs each - * module and finished with calling 'done'. You can think of this as a browser - * safe alternative to runFiles in the nodeunit module. - * - * @param {Object} modules - * @param {Object} opt - * @api public - */ - -// TODO: add proper unit tests for this function -exports.runModules = function (modules, opt) { - var all_assertions = []; - var options = types.options(opt); - var start = new Date().getTime(); - - async.concatSeries(_keys(modules), function (k, cb) { - exports.runModule(k, modules[k], options, cb); - }, - function (err, all_assertions) { - var end = new Date().getTime(); - options.done(types.assertionList(all_assertions, end - start)); - }); -}; - - -/** - * Wraps a test function with setUp and tearDown functions. - * Used by testCase. - * - * @param {Function} setUp - * @param {Function} tearDown - * @param {Function} fn - * @api private - */ - -var wrapTest = function (setUp, tearDown, fn) { - return function (test) { - var context = {}; - if (tearDown) { - var done = test.done; - test.done = function (err) { - try { - tearDown.call(context, function (err2) { - if (err && err2) { - test._assertion_list.push( - types.assertion({error: err}) - ); - return done(err2); - } - done(err || err2); - }); - } - catch (e) { - done(e); - } - }; - } - if (setUp) { - setUp.call(context, function (err) { - if (err) { - return test.done(err); - } - fn.call(context, test); - }); - } - else { - fn.call(context, test); - } - }; -}; - - -/** - * Returns a serial callback from two functions. - * - * @param {Function} funcFirst - * @param {Function} funcSecond - * @api private - */ - -var getSerialCallback = function (fns) { - if (!fns.length) { - return null; - } - return function (callback) { - var that = this; - var bound_fns = []; - for (var i = 0, len = fns.length; i < len; i++) { - (function (j) { - bound_fns.push(function () { - return fns[j].apply(that, arguments); - }); - })(i); - } - return async.series(bound_fns, callback); - }; -}; - - -/** - * Wraps a group of tests with setUp and tearDown functions. - * Used by testCase. - * - * @param {Object} group - * @param {Array} setUps - parent setUp functions - * @param {Array} tearDowns - parent tearDown functions - * @api private - */ - -var wrapGroup = function (group, setUps, tearDowns) { - var tests = {}; - - var setUps = setUps ? setUps.slice(): []; - var tearDowns = tearDowns ? tearDowns.slice(): []; - - if (group.setUp) { - setUps.push(group.setUp); - delete group.setUp; - } - if (group.tearDown) { - tearDowns.unshift(group.tearDown); - delete group.tearDown; - } - - var keys = _keys(group); - - for (var i = 0; i < keys.length; i += 1) { - var k = keys[i]; - if (typeof group[k] === 'function') { - tests[k] = wrapTest( - getSerialCallback(setUps), - getSerialCallback(tearDowns), - group[k] - ); - } - else if (typeof group[k] === 'object') { - tests[k] = wrapGroup(group[k], setUps, tearDowns); - } - } - return tests; -}; - - -/** - * Backwards compatibility for test suites using old testCase API - */ - -exports.testCase = function (suite) { - return suite; -}; -})(core); -(function(exports){ -/*! - * Nodeunit - * Copyright (c) 2010 Caolan McMahon - * MIT Licensed - * - * THIS FILE SHOULD BE BROWSER-COMPATIBLE JS! - * Only code on that line will be removed, its mostly to avoid requiring code - * that is node specific - */ - - -/** - * NOTE: this test runner is not listed in index.js because it cannot be - * used with the command-line tool, only inside the browser. - */ - - -/** - * Reporter info string - */ - -exports.info = "Browser-based test reporter"; - - -/** - * Run all tests within each module, reporting the results - * - * @param {Array} files - * @api public - */ - -exports.run = function (modules, options, callback) { - var start = new Date().getTime(), div; - options = options || {}; - div = options.div || document.body; - - function setText(el, txt) { - if ('innerText' in el) { - el.innerText = txt; - } - else if ('textContent' in el){ - el.textContent = txt; - } - } - - function getOrCreate(tag, id) { - var el = document.getElementById(id); - if (!el) { - el = document.createElement(tag); - el.id = id; - div.appendChild(el); - } - return el; - }; - - var header = getOrCreate('h1', 'nodeunit-header'); - var banner = getOrCreate('h2', 'nodeunit-banner'); - var userAgent = getOrCreate('h2', 'nodeunit-userAgent'); - var tests = getOrCreate('ol', 'nodeunit-tests'); - var result = getOrCreate('p', 'nodeunit-testresult'); - - setText(userAgent, navigator.userAgent); - - nodeunit.runModules(modules, { - moduleStart: function (name) { - /*var mheading = document.createElement('h2'); - mheading.innerText = name; - results.appendChild(mheading); - module = document.createElement('ol'); - results.appendChild(module);*/ - }, - testDone: function (name, assertions) { - var test = document.createElement('li'); - var strong = document.createElement('strong'); - strong.innerHTML = name + ' <b style="color: black;">(' + - '<b class="fail">' + assertions.failures() + '</b>, ' + - '<b class="pass">' + assertions.passes() + '</b>, ' + - assertions.length + - ')</b>'; - test.className = assertions.failures() ? 'fail': 'pass'; - test.appendChild(strong); - - var aList = document.createElement('ol'); - aList.style.display = 'none'; - test.onclick = function () { - var d = aList.style.display; - aList.style.display = (d == 'none') ? 'block': 'none'; - }; - for (var i=0; i<assertions.length; i++) { - var li = document.createElement('li'); - var a = assertions[i]; - if (a.failed()) { - li.innerHTML = (a.message || a.method || 'no message') + - '<pre>' + (a.error.stack || a.error) + '</pre>'; - li.className = 'fail'; - } - else { - li.innerHTML = a.message || a.method || 'no message'; - li.className = 'pass'; - } - aList.appendChild(li); - } - test.appendChild(aList); - tests.appendChild(test); - }, - done: function (assertions) { - var end = new Date().getTime(); - var duration = end - start; - - var failures = assertions.failures(); - banner.className = failures ? 'fail': 'pass'; - - result.innerHTML = 'Tests completed in ' + duration + - ' milliseconds.<br/><span class="passed">' + - assertions.passes() + '</span> assertions of ' + - '<span class="all">' + assertions.length + '<span> passed, ' + - assertions.failures() + ' failed.'; - - if (callback) callback(assertions.failures() ? new Error('We have got test failures.') : undefined); - } - }); -}; -})(reporter); -nodeunit = core; -nodeunit.assert = assert; -nodeunit.reporter = reporter; -nodeunit.run = reporter.run; -return nodeunit; })(); diff --git a/dist/async.js b/dist/async.js index 2062bea..02b0295 100644 --- a/dist/async.js +++ b/dist/async.js @@ -362,8 +362,9 @@ function once(fn) { return function () { if (fn === null) return; - fn.apply(this, arguments); + var callFn = fn; fn = null; + callFn.apply(this, arguments); }; } @@ -801,8 +802,9 @@ function onlyOnce(fn) { return function () { if (fn === null) throw new Error("Callback was already called."); - fn.apply(this, arguments); + var callFn = fn; fn = null; + callFn.apply(this, arguments); }; } @@ -867,6 +869,24 @@ }); } + /** + * The same as `map` but runs a maximum of `limit` async operations at a time. + * + * @name mapLimit + * @static + * @memberOf async + * @see async.map + * @category Collection + * @param {Array|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) { @@ -875,20 +895,213 @@ }; } + /** + * 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`. + * + * @name map + * @static + * @memberOf async + * @category Collection + * @param {Array|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 async + * @category Control Flow + * @param {Array|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` but runs only a single async operation at a time. + * + * @name mapSeries + * @static + * @memberOf async + * @see async.map + * @category Collection + * @param {Array|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` but runs only a single async operation at a time. + * + * @name applyEachSeries + * @static + * @memberOf async + * @see async.applyEach + * @category Control Flow + * @param {Array|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 async + * @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 async + * @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; @@ -2766,6 +2979,83 @@ 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 async + * @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). + * @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. @@ -2790,32 +3080,31 @@ 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 = {}; + forOwn(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; - - checkForDeadlocks(); - - function checkForDeadlocks() { - var len = dependencies.length; - var dep; - while (len--) { - if (!(dep = tasks[dependencies[len]])) { - throw new Error('async.auto task `' + key + '` has non-existent dependency in ' + dependencies.join(', ')); - } - if (isArray(dep) && baseIndexOf(dep, key, 0) >= 0) { - throw new Error('async.auto task `' + key + '`Has cyclic dependencies'); - } - } + if (!remainingDependencies) { + enqueueTask(key, [task]); + readyToCheck.push(key); } + 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) { @@ -2825,6 +3114,7 @@ }); }); + checkForDeadlocks(); processQueue(); function enqueueTask(key, task) { @@ -2892,6 +3182,37 @@ 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]) { + readyToCheck.push(dependent); + } + }); + } + + if (counter !== numTasks) { + throw new Error('async.auto cannot execute tasks due to a recursive dependency'); + } + } + + function getDependents(taskName) { + var result = []; + forOwn(tasks, function (task, key) { + if (isArray(task) && baseIndexOf(task, taskName, 0) >= 0) { + result.push(key); + } + }); + return result; + } } /** @@ -2919,6 +3240,92 @@ return func.toString().match(argsRegex)[1].split(/\s*\,\s*/); } + /** + * A dependency-injected version of the {@link async.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 {@link async.auto}. + * + * @name autoInject + * @static + * @memberOf async + * @see async.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. The remaining parameters are task names + * whose results you are interested in. This callback will only be called when + * all tasks have finished or an error has occurred, and so do not specify + * dependencies in the same way as `tasks` do. If an error occurs, no further + * `tasks` will be performed, and `results` will only be valid for those tasks + * which managed to complete. Invoked with (err, [results...]). + * @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, email_link) { + * console.log('err = ', err); + * console.log('email_link = ', 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. The final + * // results callback can be provided as an array in the same way. + * + * // 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'}); + * }] + * //... + * }, ['email_link', function(err, email_link) { + * console.log('err = ', err); + * console.log('email_link = ', email_link); + * }]); + */ function autoInject(tasks, callback) { var newTasks = {}; @@ -2951,23 +3358,7 @@ } }); - auto(newTasks, function (err, results) { - var params; - if (isArray(callback)) { - params = copyArray(callback); - callback = params.pop(); - } else { - params = parseParams(callback); - params.shift(); - } - - params = arrayMap(params, function (name) { - return results[name]; - }); - - params.unshift(err); - callback.apply(null, params); - }); + auto(newTasks, callback); } var _setImmediate = typeof setImmediate === 'function' && setImmediate; @@ -3126,16 +3517,169 @@ return q; } + /** + * A cargo of tasks for the worker function to complete. Cargo inherits all of + * the same methods and event callbacks as {@link async.queue}. + * @typedef {Object} cargo + * @property {Function} length - A function returning the number of items + * waiting to be processed. Invoke with (). + * @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 with (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 with (). + * @property {Function} pause - a function that pauses the processing of tasks + * until `resume()` is called. Invoke with (). + * @property {Function} resume - a function that resumes the processing of + * queued tasks when the queue is paused. Invoke with (). + * @property {Function} kill - a function that removes the `drain` callback and + * empties remaining tasks from the queue forcing it to go idle. Invoke with (). + */ + + /** + * 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](#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 async + * @see async.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 {cargo} 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); + return queue(worker, 1, payload); } + /** + * The same as `eachOf` but runs a maximum of `limit` async operations at a + * time. + * + * @name eachOfLimit + * @static + * @memberOf async + * @see async.eachOf + * @alias forEachOfLimit + * @category Collection + * @param {Array|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(obj, limit, iteratee, cb) { - _eachOfLimit(limit)(obj, iteratee, cb); + _eachOfLimit(limit)(obj, iteratee, cb); } + /** + * The same as `eachOf` but runs only a single async operation at a time. + * + * @name eachOfSeries + * @static + * @memberOf async + * @see async.eachOf + * @alias forEachOfSeries + * @category Collection + * @param {Array|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 async + * @alias inject, foldl + * @category Collection + * @param {Array|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(arr, memo, iteratee, cb) { eachOfSeries(arr, function (x, i, cb) { iteratee(memo, x, function (err, v) { @@ -3147,6 +3691,42 @@ }); } + /** + * 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 + * {@link async.compose} with the arguments reversed. + * + * Each function is executed with the `this` binding of the composed function. + * + * @name seq + * @static + * @memberOf async + * @see async.compose + * @category Control Flow + * @param {...Function} functions - the asynchronous functions to compose + * @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 }); + * } + * }); + * }); + */ function seq() /* functions... */{ var fns = arguments; return rest(function (args) { @@ -3171,8 +3751,40 @@ var reverse = Array.prototype.reverse; + /** + * 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 async + * @category Control Flow + * @param {...Function} functions - the asynchronous functions to compose + * @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 + * }); + */ function compose() /* functions... */{ - return seq.apply(null, reverse.call(arguments)); + return seq.apply(null, reverse.call(arguments)); } function concat$1(eachfn, arr, fn, callback) { @@ -3187,6 +3799,45 @@ }); } + /** + * Like `each`, except that it passes the key (or index) as the second argument + * to the iteratee. + * + * @name eachOf + * @static + * @memberOf async + * @alias forEachOf + * @category Collection + * @param {Array|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) { @@ -3195,6 +3846,32 @@ }; } + /** + * 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 async + * @category Collection + * @param {Array|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) { @@ -3203,8 +3880,67 @@ }; } + /** + * The same as `concat` but runs only a single async operation at a time. + * + * @name concatSeries + * @static + * @memberOf async + * @see async.concat + * @category Collection + * @param {Array|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`, or for plugging values in to + * `auto`. + * + * @name constant + * @static + * @memberOf async + * @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) { @@ -3254,10 +3990,84 @@ 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`. + * + * @name detect + * @static + * @memberOf async + * @alias find + * @category Collection + * @param {Array|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` but runs a maximum of `limit` async operations at a + * time. + * + * @name detectLimit + * @static + * @memberOf async + * @see async.detect + * @alias findLimit + * @category Collection + * @param {Array|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` but runs only a single async operation at a time. + * + * @name detectSeries + * @static + * @memberOf async + * @see async.detect + * @alias findSeries + * @category Collection + * @param {Array|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) { @@ -3278,8 +4088,72 @@ }); } + /** + * 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 log + * @static + * @memberOf async + * @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'); + /** + * Like {@link async.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 async + * @see async.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 and any arguments passed to the final `fn`'s + * callback. Invoked with (err, [results]); + * @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, iteratee, cb) { cb = cb || noop; @@ -3301,6 +4175,26 @@ test(check); } + /** + * The post-check version of {@link async.during}. To reflect the difference in + * the order of operations, the arguments `test` and `fn` are switched. + * + * Also a version of {@link async.doWhilst} with asynchronous `test` function. + * @name doDuring + * @static + * @memberOf async + * @see async.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 (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]); + */ function doDuring(iteratee, test, cb) { var calls = 0; @@ -3310,6 +4204,39 @@ }, iteratee, cb); } + /** + * Repeatedly call `fn`, while `test` returns `true`. Calls `callback` when + * stopped, or an error occurs. + * + * @name whilst + * @static + * @memberOf async + * @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` 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]); + * @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, cb) { cb = cb || noop; if (!test()) return cb(null); @@ -3321,6 +4248,27 @@ iteratee(next); } + /** + * The post-check version of {@link async.whilst}. To reflect the difference in + * the order of operations, the arguments `test` and `fn` are switched. + * + * `doWhilst` is to `whilst` as `do while` is to `while` in plain JavaScript. + * + * @name doWhilst + * @static + * @memberOf async + * @see async.whilst + * @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 - synchronous truth test to perform before each + * execution of `fn`. Invoked with (). + * @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]); + */ function doWhilst(iteratee, test, cb) { var calls = 0; return whilst(function () { @@ -3328,6 +4276,25 @@ }, iteratee, cb); } + /** + * Like {@link async.doWhilst}, except the `test` is inverted. Note the + * argument ordering differs from `until`. + * + * @name doUntil + * @static + * @memberOf async + * @see async.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 before each + * execution of `fn`. Invoked with (). + * @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(iteratee, test, cb) { return doWhilst(iteratee, function () { return !test.apply(this, arguments); @@ -3340,14 +4307,144 @@ }; } + /** + * The same as `each` but runs a maximum of `limit` async operations at a time. + * + * @name eachLimit + * @static + * @memberOf async + * @see async.each + * @alias forEachLimit + * @category Collection + * @param {Array|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(arr, limit, iteratee, cb) { - return _eachOfLimit(limit)(arr, _withoutIndex(iteratee), cb); + return _eachOfLimit(limit)(arr, _withoutIndex(iteratee), cb); } + /** + * 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 async + * @alias forEach + * @category Collection + * @param {Array|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` but runs only a single async operation at a time. + * + * @name eachSeries + * @static + * @memberOf async + * @see async.each + * @alias forEachSeries + * @category Collection + * @param {Array|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 async + * @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; @@ -3370,10 +4467,74 @@ return !v; } + /** + * The same as `every` but runs a maximum of `limit` async operations at a time. + * + * @name everyLimit + * @static + * @memberOf async + * @see async.every + * @alias allLimit + * @category Collection + * @param {Array|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 async + * @alias all + * @category Collection + * @param {Array|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` but runs only a single async operation at a time. + * + * @name everySeries + * @static + * @memberOf async + * @see async.every + * @alias allSeries + * @category Collection + * @param {Array|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) { @@ -3400,12 +4561,100 @@ }); } + /** + * The same as `filter` but runs a maximum of `limit` async operations at a + * time. + * + * @name filterLimit + * @static + * @memberOf async + * @see async.filter + * @alias selectLimit + * @category Collection + * @param {Array|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 async + * @alias select + * @category Collection + * @param {Array|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` but runs only a single async operation at a time. + * + * @name filterSeries + * @static + * @memberOf async + * @see async.filter + * @alias selectSeries + * @category Collection + * @param {Array|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 async + * @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, cb) { var done = onlyOnce(cb || noop); var task = ensureAsync(fn); @@ -3417,6 +4666,39 @@ next(); } + /** + * Creates an iterator function which calls the next function in the `tasks` + * array, returning a continuation to call the next one after that. It's also + * possible to “peek” at the next iterator with `iterator.next()`. + * + * This function is used internally by the `async` module, but can be useful + * when you want to manually control the flow of functions in series. + * + * @name iterator + * @static + * @memberOf async + * @category Control Flow + * @param {Array} tasks - An array of functions to run. + * @returns The next function to run in the series. + * @example + * + * var iterator = async.iterator([ + * function() { sys.p('one'); }, + * function() { sys.p('two'); }, + * function() { sys.p('three'); } + * ]); + * + * node> var iterator2 = iterator(); + * 'one' + * node> var iterator3 = iterator2(); + * 'two' + * node> iterator3(); + * 'three' + * node> var nextfn = iterator2.next(); + * node> nextfn(); + * 'three' + */ + function iterator$1 (tasks) { function makeCallback(index) { function fn() { @@ -3433,12 +4715,73 @@ return makeCallback(0); } + /** + * 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 async + * @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'); 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 async + * @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. + * @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$1(fn, hasher) { var memo = Object.create(null); var queues = Object.create(null); @@ -3485,18 +4828,221 @@ }); } + /** + * The same as `parallel` but runs a maximum of `limit` async operations at a + * time. + * + * @name parallel + * @static + * @memberOf async + * @see async.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, cb) { - return _parallel(_eachOfLimit(limit), tasks, cb); + return _parallel(_eachOfLimit(limit), tasks, cb); } + /** + * 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 async + * @category Control Flow + * @param {Array|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} queue + * @property {Function} length - a function returning the number of items + * waiting to be processed. Invoke with (). + * @property {Function} started - a function returning whether or not any + * items have been pushed and processed by the queue. Invoke with (). + * @property {Function} running - a function returning the number of items + * currently being processed. Invoke with (). + * @property {Function} workersList - a function returning the array of items + * currently being processed. Invoke with (). + * @property {Function} idle - a function returning false if there are items + * waiting or being processed, or true if not. Invoke with (). + * @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 (task, [callback]), + * @property {Function} unshift - add a new task to the front of the `queue`. + * Invoke with (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 {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 (). + * @property {Function} resume - a function that resumes the processing of + * queued tasks when the queue is paused. Invoke with (). + * @property {Function} kill - a function that removes the `drain` callback and + * empties remaining tasks from the queue forcing it to go idle. Invoke with (). + */ + + /** + * 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 async + * @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 {queue} 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); + return queue(function (items, cb) { + worker(items[0], cb); + }, concurrency, 1); } + /** + * The same as {@link async.queue} only tasks are assigned a priority and + * completed in ascending priority order. + * + * @name priorityQueue + * @static + * @memberOf async + * @see async.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 {queue} 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) { function _compareTasks(a, b) { return a.priority - b.priority; @@ -3539,12 +5085,6 @@ q.tasks.splice(_binarySearch(q.tasks, item, _compareTasks) + 1, 0, item); - if (q.tasks.length === q.concurrency) { - q.saturated(); - } - if (q.tasks.length <= q.concurrency - q.buffer) { - q.unsaturated(); - } setImmediate$1(q.process); }); } @@ -3637,6 +5177,41 @@ : baseEach(collection, baseIteratee(iteratee)); } + /** + * 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 async + * @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). + * @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, cb) { cb = once(cb || noop); if (!isArray(tasks)) return cb(new TypeError('First argument to race must be an array of functions')); @@ -3648,11 +5223,70 @@ var slice = Array.prototype.slice; + /** + * Same as `reduce`, only operates on `coll` in reverse order. + * + * @name reduceRight + * @static + * @memberOf async + * @see async.reduce + * @alias foldr + * @category Collection + * @param {Array|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). + */ function reduceRight(arr, memo, iteratee, cb) { - var reversed = slice.call(arr).reverse(); - reduce(reversed, memo, iteratee, cb); + var reversed = slice.call(arr).reverse(); + reduce(reversed, memo, iteratee, cb); } + /** + * 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 async + * @category Util + * @param {Function} function - 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) { @@ -3689,20 +5323,236 @@ }, callback); } + /** + * The same as `reject` but runs a maximum of `limit` async operations at a + * time. + * + * @name rejectLimit + * @static + * @memberOf async + * @see async.reject + * @category Collection + * @param {Array|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`. Removes values that pass an `async` truth test. + * + * @name reject + * @static + * @memberOf async + * @see async.filter + * @category Collection + * @param {Array|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 of functions with reflect. + * + * @name reflectAll + * @static + * @memberOf async + * @see async.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' + * }); + */ function reflectAll(tasks) { - return tasks.map(reflect); + return tasks.map(reflect); } + /** + * The same as `reject` but runs only a single async operation at a time. + * + * @name rejectSeries + * @static + * @memberOf async + * @see async.reject + * @category Collection + * @param {Array|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); + /** + * 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 async + * @category Control Flow + * @param {Array|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, cb) { - return _parallel(eachOfSeries, tasks, cb); + return _parallel(eachOfSeries, tasks, cb); } + /** + * 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 async + * @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`. + * * 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 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(times, task, callback) { var DEFAULT_TIMES = 5; var DEFAULT_INTERVAL = 0; @@ -3769,6 +5619,29 @@ } } + /** + * A close relative of `retry`. This method wraps a task and makes it + * retryable, rather than immediately calling it with retries. + * + * @name retryable + * @static + * @memberOf async + * @see async.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; @@ -3783,12 +5656,125 @@ }); } + /** + * The same as `some` but runs a maximum of `limit` async operations at a time. + * + * @name someLimit + * @static + * @memberOf async + * @see async.some + * @alias anyLimit + * @category Collection + * @param {Array|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 async + * @alias any + * @category Collection + * @param {Array|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` but runs only a single async operation at a time. + * + * @name someSeries + * @static + * @memberOf async + * @see async.some + * @alias anySeries + * @category Collection + * @param {Array|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 async + * @category Collection + * @param {Array|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(arr, iteratee, cb) { map(arr, function (x, cb) { iteratee(x, function (err, criteria) { @@ -3807,6 +5793,28 @@ } } + /** + * Sets a time limit on an asynchronous function. If the function does not call + * its callback within the specified miliseconds, it will be called with a + * timeout error. The code property for the error object will be `'ETIMEDOUT'`. + * + * @name timeout + * @static + * @memberOf async + * @category Util + * @param {Function} function - The asynchronous function you want to set the + * time limit. + * @param {number} miliseconds - 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, miliseconds, info) { var originalCallback, timer; var timedOut = false; @@ -3863,40 +5871,232 @@ return result; } + /** + * The same as {@link times} but runs a maximum of `limit` async operations at a + * time. + * + * @name timesLimit + * @static + * @memberOf async + * @see async.times + * @category Control Flow + * @param {number} n - 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 {@link async.map}. + */ function timeLimit(count, limit, iteratee, cb) { - return mapLimit(baseRange(0, count, 1), limit, iteratee, cb); + return mapLimit(baseRange(0, count, 1), limit, iteratee, cb); } + /** + * Calls the `iteratee` function `n` times, and accumulates results in the same + * manner you would use with {@link async.map}. + * + * @name times + * @static + * @memberOf async + * @see async.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 async.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 {@link async.times} but runs only a single async operation at a time. + * + * @name timesSeries + * @static + * @memberOf async + * @see async.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 async.map}. + */ var timesSeries = doLimit(timeLimit, 1); - function transform(arr, memo, iteratee, callback) { + /** + * 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 async + * @category Collection + * @param {Array|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(arr, acc, iteratee, callback) { if (arguments.length === 3) { callback = iteratee; - iteratee = memo; - memo = isArray(arr) ? [] : {}; + iteratee = acc; + acc = isArray(arr) ? [] : {}; } eachOf(arr, function (v, k, cb) { - iteratee(memo, v, k, cb); + iteratee(acc, v, k, cb); }, function (err) { - callback(err, memo); + callback(err, acc); }); } + /** + * Undoes a {@link async.memoize}d function, reverting it to the original, + * unmemoized form. Handy for testing. + * + * @name unmemoize + * @static + * @memberOf async + * @see async.memoize + * @category Util + * @param {Function} fn - the memoized function + */ + function unmemoize(fn) { return function () { return (fn.unmemoized || fn).apply(null, arguments); }; } + /** + * 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 {@link async.whilst}. + * + * @name until + * @static + * @memberOf async + * @see async.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, iteratee, cb) { return whilst(function () { return !test.apply(this, arguments); }, iteratee, cb); } + /** + * 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 async + * @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]). + * @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, cb) { cb = once(cb || noop); if (!isArray(tasks)) return cb(new Error('First argument to waterfall must be an array of functions')); diff --git a/dist/async.min.js b/dist/async.min.js index 4798cc7..6274bc3 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,r){var e=r.length;switch(e){case 0:return n.call(t);case 1:return n.call(t,r[0]);case 2:return n.call(t,r[0],r[1]);case 3:return n.call(t,r[0],r[1],r[2])}return n.apply(t,r)}function r(n){var t=typeof n;return!!n&&("object"==t||"function"==t)}function e(n){var t=r(n)?Ht.call(n):"";return t==Vt||t==Qt}function o(n){return!!n&&"object"==typeof n}function u(n){return"symbol"==typeof n||o(n)&&Xt.call(n)==Jt}function i(n){if("number"==typeof n)return n;if(u(n))return Yt;if(r(n)){var t=e(n.valueOf)?n.valueOf():n;n=r(t)?t+"":t}if("string"!=typeof n)return 0===n?n:+n;n=n.replace(Zt,"");var o=tr.test(n);return o||rr.test(n)?er(n.slice(2),o?2:8):nr.test(n)?Yt:+n}function c(n){if(!n)return 0===n?n:0;if(n=i(n),n===or||n===-or){var t=0>n?-1:1;return t*ur}var r=n%1;return n===n?r?n-r:n:0}function a(n,r){if("function"!=typeof n)throw new TypeError(ir);return r=cr(void 0===r?n.length-1:c(r),0),function(){for(var e=arguments,o=-1,u=cr(e.length-r,0),i=Array(u);++o<u;)i[o]=e[r+o];switch(r){case 0:return n.call(this,i);case 1:return n.call(this,e[0],i);case 2:return n.call(this,e[0],e[1],i)}var c=Array(r+1);for(o=-1;++o<r;)c[o]=e[o];return c[r]=i,t(n,this,c)}}function f(n){return a(function(t){var r=t.pop();n.call(this,t,r)})}function l(n){return a(function(t,r){var e=f(function(r,e){var o=this;return n(t,function(n,t){n.apply(o,r.concat([t]))},e)});return r.length?e.apply(this,r):e})}function s(){}function p(n){return function(){null!==n&&(n.apply(this,arguments),n=null)}}function y(n){return function(t){return null==t?void 0:t[n]}}function v(n){return"number"==typeof n&&n>-1&&n%1==0&&fr>=n}function h(n){return null!=n&&v(ar(n))&&!e(n)}function m(n){return lr&&n[lr]&&n[lr]()}function d(n){return sr(Object(n))}function g(n,t){return yr.call(n,t)||"object"==typeof n&&t in n&&null===d(n)}function b(n){return vr(Object(n))}function j(n,t){for(var r=-1,e=Array(n);++r<n;)e[r]=t(r);return e}function w(n){return o(n)&&h(n)}function _(n){return w(n)&&dr.call(n,"callee")&&(!br.call(n,"callee")||gr.call(n)==hr)}function O(n){return"string"==typeof n||!jr(n)&&o(n)&&Or.call(n)==wr}function S(n){var t=n?n.length:void 0;return v(t)&&(jr(n)||O(n)||_(n))?j(t,String):null}function k(n,t){return n="number"==typeof n||kr.test(n)?+n:-1,t=null==t?Sr:t,n>-1&&n%1==0&&t>n}function E(n){var t=n&&n.constructor,r="function"==typeof t&&t.prototype||Er;return n===r}function A(n){var t=E(n);if(!t&&!h(n))return b(n);var r=S(n),e=!!r,o=r||[],u=o.length;for(var i in n)!g(n,i)||e&&("length"==i||k(i,u))||t&&"constructor"==i||o.push(i);return o}function L(n){var t,r=-1;if(h(n))return t=n.length,function(){return r++,t>r?{value:n[r],key:r}:null};var e=m(n);if(e)return function(){var n=e.next();return n.done?null:(r++,{value:n.value,key:r})};var o=A(n);return t=o.length,function(){r++;var e=o[r];return t>r?{value:n[e],key:e}:null}}function x(n){return function(){if(null===n)throw new Error("Callback was already called.");n.apply(this,arguments),n=null}}function I(n){return function(t,r,e){e=p(e||s),t=t||[];var o=L(t);if(0>=n)return e(null);var u=!1,i=0,c=!1;!function a(){if(u&&0>=i)return e(null);for(;n>i&&!c;){var t=o();if(null===t)return u=!0,void(0>=i&&e(null));i+=1,r(t.value,t.key,x(function(n){i-=1,n?(e(n),c=!0):a()}))}}()}}function T(n){return function(t,r,e,o){return n(I(r),t,e,o)}}function M(n,t,r,e){e=p(e||s),t=t||[];var o=h(t)||m(t)?[]:{};n(t,function(n,t,e){r(n,function(n,r){o[t]=r,e(n)})},function(n){e(n,o)})}function $(n,t){return function(r,e,o){return n(r,t,e,o)}}function z(n){return f(function(t,e){var o;try{o=n.apply(this,t)}catch(u){return e(u)}r(o)&&"function"==typeof o.then?o.then(function(n){e(null,n)})["catch"](function(n){e(n.message?n:new Error(n))}):e(null,o)})}function F(n,t){for(var r=-1,e=n.length;++r<e&&t(n[r],r,n)!==!1;);return n}function P(n){return function(t,r,e){for(var o=-1,u=Object(t),i=e(t),c=i.length;c--;){var a=i[n?c:++o];if(r(u[a],a,u)===!1)break}return t}}function D(n,t){return n&&$r(n,t,A)}function B(){this.__data__={array:[],map:null}}function U(n,t){return n===t||n!==n&&t!==t}function C(n,t){for(var r=n.length;r--;)if(U(n[r][0],t))return r;return-1}function q(n,t){var r=C(n,t);if(0>r)return!1;var e=n.length-1;return r==e?n.pop():Fr.call(n,r,1),!0}function R(n){var t=this.__data__,r=t.array;return r?q(r,n):t.map["delete"](n)}function W(n,t){var r=C(n,t);return 0>r?void 0:n[r][1]}function N(n){var t=this.__data__,r=t.array;return r?W(r,n):t.map.get(n)}function V(n,t){return C(n,t)>-1}function Q(n){var t=this.__data__,r=t.array;return r?V(r,n):t.map.has(n)}function G(n){var t=!1;if(null!=n&&"function"!=typeof n.toString)try{t=!!(n+"")}catch(r){}return t}function H(n){return null==n?!1:e(n)?qr.test(Ur.call(n)):o(n)&&(G(n)?qr:Dr).test(n)}function J(n,t){var r=n[t];return H(r)?r:void 0}function K(){}function X(n){return n&&n.Object===Object?n:null}function Y(){this.__data__={hash:new K,map:Yr?new Yr:[],string:new K}}function Z(n,t){return Rr?void 0!==n[t]:ne.call(n,t)}function nn(n,t){return Z(n,t)&&delete n[t]}function tn(n){var t=typeof n;return"number"==t||"boolean"==t||"string"==t&&"__proto__"!=n||null==n}function rn(n){var t=this.__data__;return tn(n)?nn("string"==typeof n?t.string:t.hash,n):Yr?t.map["delete"](n):q(t.map,n)}function en(n,t){if(Rr){var r=n[t];return r===te?void 0:r}return ee.call(n,t)?n[t]:void 0}function on(n){var t=this.__data__;return tn(n)?en("string"==typeof n?t.string:t.hash,n):Yr?t.map.get(n):W(t.map,n)}function un(n){var t=this.__data__;return tn(n)?Z("string"==typeof n?t.string:t.hash,n):Yr?t.map.has(n):V(t.map,n)}function cn(n,t,r){var e=C(n,t);0>e?n.push([t,r]):n[e][1]=r}function an(n,t,r){n[t]=Rr&&void 0===r?oe:r}function fn(n,t){var r=this.__data__;return tn(n)?an("string"==typeof n?r.string:r.hash,n,t):Yr?r.map.set(n,t):cn(r.map,n,t),this}function ln(n){var t=-1,r=n?n.length:0;for(this.clear();++t<r;){var e=n[t];this.set(e[0],e[1])}}function sn(n,t){var r=this.__data__,e=r.array;e&&(e.length<ue-1?cn(e,n,t):(r.array=null,r.map=new ln(e)));var o=r.map;return o&&o.set(n,t),this}function pn(n){var t=-1,r=n?n.length:0;for(this.clear();++t<r;){var e=n[t];this.set(e[0],e[1])}}function yn(n,t){for(var r=-1,e=n.length;++r<e;)if(t(n[r],r,n))return!0;return!1}function vn(n,t,r,e,o,u){var i=-1,c=o&ce,a=o&ie,f=n.length,l=t.length;if(f!=l&&!(c&&l>f))return!1;var s=u.get(n);if(s)return s==t;var p=!0;for(u.set(n,t);++i<f;){var y=n[i],v=t[i];if(e)var h=c?e(v,y,i,t,n,u):e(y,v,i,n,t,u);if(void 0!==h){if(h)continue;p=!1;break}if(a){if(!yn(t,function(n){return y===n||r(y,n,e,o,u)})){p=!1;break}}else if(y!==v&&!r(y,v,e,o,u)){p=!1;break}}return u["delete"](n),p}function hn(n){var t=-1,r=Array(n.size);return n.forEach(function(n,e){r[++t]=[e,n]}),r}function mn(n){var t=-1,r=Array(n.size);return n.forEach(function(n){r[++t]=n}),r}function dn(n,t,r,e,o,u,i){switch(r){case _e:if(n.byteLength!=t.byteLength||n.byteOffset!=t.byteOffset)return!1;n=n.buffer,t=t.buffer;case we:return n.byteLength==t.byteLength&&e(new fe(n),new fe(t))?!0:!1;case pe:case ye:return+n==+t;case ve:return n.name==t.name&&n.message==t.message;case me:return n!=+n?t!=+t:n==+t;case de:case be:return n==t+"";case he:var c=hn;case ge:var a=u&se;if(c||(c=mn),n.size!=t.size&&!a)return!1;var f=i.get(n);return f?f==t:(u|=le,i.set(n,t),vn(c(n),c(t),e,o,u,i));case je:if(Se)return Se.call(n)==Se.call(t)}return!1}function gn(n,t,r,e,o,u){var i=o&ke,c=A(n),a=c.length,f=A(t),l=f.length;if(a!=l&&!i)return!1;for(var s=a;s--;){var p=c[s];if(!(i?p in t:g(t,p)))return!1}var y=u.get(n);if(y)return y==t;var v=!0;u.set(n,t);for(var h=i;++s<a;){p=c[s];var m=n[p],d=t[p];if(e)var b=i?e(d,m,p,t,n,u):e(m,d,p,n,t,u);if(!(void 0===b?m===d||r(m,d,e,o,u):b)){v=!1;break}h||(h="constructor"==p)}if(v&&!h){var j=n.constructor,w=t.constructor;j!=w&&"constructor"in n&&"constructor"in t&&!("function"==typeof j&&j instanceof j&&"function"==typeof w&&w instanceof w)&&(v=!1)}return u["delete"](n),v}function bn(n){return Be.call(n)}function jn(n){return o(n)&&v(n.length)&&!!ho[go.call(n)]}function wn(n,t,r,e,o,u){var i=jr(n),c=jr(t),a=wo,f=wo;i||(a=Ne(n),a=a==jo?_o:a),c||(f=Ne(t),f=f==jo?_o:f);var l=a==_o&&!G(n),s=f==_o&&!G(t),p=a==f;if(p&&!l)return u||(u=new pn),i||jn(n)?vn(n,t,r,e,o,u):dn(n,t,a,r,e,o,u);if(!(o&bo)){var y=l&&So.call(n,"__wrapped__"),v=s&&So.call(t,"__wrapped__");if(y||v){var h=y?n.value():n,m=v?t.value():t;return u||(u=new pn),r(h,m,e,o,u)}}return p?(u||(u=new pn),gn(n,t,r,e,o,u)):!1}function _n(n,t,e,u,i){return n===t?!0:null==n||null==t||!r(n)&&!o(t)?n!==n&&t!==t:wn(n,t,_n,e,u,i)}function On(n,t,r,e){var o=r.length,u=o,i=!e;if(null==n)return!u;for(n=Object(n);o--;){var c=r[o];if(i&&c[2]?c[1]!==n[c[0]]:!(c[0]in n))return!1}for(;++o<u;){c=r[o];var a=c[0],f=n[a],l=c[1];if(i&&c[2]){if(void 0===f&&!(a in n))return!1}else{var s=new pn;if(e)var p=e(f,l,a,n,t,s);if(!(void 0===p?_n(l,f,e,ko|Eo,s):p))return!1}}return!0}function Sn(n){return n===n&&!r(n)}function kn(n,t){for(var r=-1,e=n.length,o=Array(e);++r<e;)o[r]=t(n[r],r,n);return o}function En(n,t){return kn(t,function(t){return[t,n[t]]})}function An(n){return En(n,A(n))}function Ln(n){for(var t=An(n),r=t.length;r--;)t[r][2]=Sn(t[r][1]);return t}function xn(n){var t=Ln(n);if(1==t.length&&t[0][2]){var r=t[0][0],e=t[0][1];return function(n){return null==n?!1:n[r]===e&&(void 0!==e||r in Object(n))}}return function(r){return r===n||On(r,n,t)}}function In(n,t){if("function"!=typeof n||t&&"function"!=typeof t)throw new TypeError(Ao);var r=function(){var e=arguments,o=t?t.apply(this,e):e[0],u=r.cache;if(u.has(o))return u.get(o);var i=n.apply(this,e);return r.cache=u.set(o,i),i};return r.cache=new(In.Cache||ln),r}function Tn(n){if("string"==typeof n)return n;if(null==n)return"";if(u(n))return To?To.call(n):"";var t=n+"";return"0"==t&&1/n==-xo?"-0":t}function Mn(n){return jr(n)?n:zo(n)}function $n(n,t){var r=typeof n;return"number"==r||"symbol"==r?!0:!jr(n)&&(u(n)||Po.test(n)||!Fo.test(n)||null!=t&&n in Object(t))}function zn(n,t){t=$n(t,n)?[t]:Mn(t);for(var r=0,e=t.length;null!=n&&e>r;)n=n[t[r++]];return r&&r==e?n:void 0}function Fn(n,t,r){var e=null==n?void 0:zn(n,t);return void 0===e?r:e}function Pn(n,t){return t in Object(n)}function Dn(n,t,r){if(null==n)return!1;var e=r(n,t);if(!e&&!$n(t)){t=Mn(t);for(var o=-1,u=t.length;null!=n&&++o<u;){var i=t[o];if(!(e=r(n,i)))break;n=n[i]}}var u=n?n.length:void 0;return e||!!u&&v(u)&&k(t,u)&&(jr(n)||O(n)||_(n))}function Bn(n,t){return Dn(n,t,Pn)}function Un(n,t){return function(r){var e=Fn(r,n);return void 0===e&&e===t?Bn(r,n):_n(t,e,void 0,Do|Bo)}}function Cn(n){return n}function qn(n){return function(t){return zn(t,n)}}function Rn(n){return $n(n)?y(n):qn(n)}function Wn(n){return"function"==typeof n?n:null==n?Cn:"object"==typeof n?jr(n)?Un(n[0],n[1]):xn(n):Rn(n)}function Nn(n,t){return n&&D(n,Wn(t))}function Vn(n,t,r){for(var e=n.length,o=t+(r?0:-1);r?o--:++o<e;){var u=n[o];if(u!==u)return o}return-1}function Qn(n,t,r){if(t!==t)return Vn(n,r);for(var e=r-1,o=n.length;++e<o;)if(n[e]===t)return e;return-1}function Gn(n,t,r){function e(n,t){d.push(function(){c(n,t)})}function o(){if(0===d.length&&0===v)return r(null,y);for(;d.length&&t>v;){var n=d.shift();n()}}function u(n,t){var r=m[n];r||(r=m[n]=[]),r.push(t)}function i(n){var t=m[n]||[];F(t,function(n){n()}),o()}function c(n,t){if(!h){var e=x(a(function(t,e){if(v--,e.length<=1&&(e=e[0]),t){var o={};Nn(y,function(n,t){o[t]=n}),o[n]=e,h=!0,m=[],r(t,o)}else y[n]=e,i(n)}));v++;var o=t[t.length-1];t.length>1?o(y,e):o(e)}}"function"==typeof t&&(r=t,t=null),r=p(r||s);var f=A(n),l=f.length;if(!l)return r(null);t||(t=l);var y={},v=0,h=!1,m={},d=[];Nn(n,function(t,r){function o(){for(var t,e=i.length;e--;){if(!(t=n[i[e]]))throw new Error("async.auto task `"+r+"` has non-existent dependency in "+i.join(", "));if(jr(t)&&Qn(t,r,0)>=0)throw new Error("async.auto task `"+r+"`Has cyclic dependencies")}}if(!jr(t))return void e(r,[t]);var i=t.slice(0,t.length-1),c=i.length;o(),F(i,function(n){u(n,function(){c--,0===c&&e(r,t)})})}),o()}function Hn(n,t){var r=-1,e=n.length;for(t||(t=Array(e));++r<e;)t[r]=n[r];return t}function Jn(n){return n.toString().match(Uo)[1].split(/\s*\,\s*/)}function Kn(n,t){var r={};Nn(n,function(n,t){function e(t,r){var e=kn(o,function(n){return t[n]});e.push(r),n.apply(null,e)}var o;if(jr(n))o=Hn(n),n=o.pop(),r[t]=o.concat(e);else{if(0===n.length)throw new Error("autoInject task functions require explicit parameters.");1===n.length?r[t]=n:(o=Jn(n),o.pop(),r[t]=o.concat(e))}}),Gn(r,function(n,r){var e;jr(t)?(e=Hn(t),t=e.pop()):(e=Jn(t),e.shift()),e=kn(e,function(n){return r[n]}),e.unshift(n),t.apply(null,e)})}function Xn(n,t,r){function e(n,t,r,e){if(null!=e&&"function"!=typeof e)throw new Error("task callback must be a function");return n.started=!0,jr(t)||(t=[t]),0===t.length&&n.idle()?qo(function(){n.drain()}):(F(t,function(t){var o={data:t,callback:e||s};r?n.tasks.unshift(o):n.tasks.push(o)}),void qo(n.process))}function o(n,t){return function(){u-=1;var r=!1,e=arguments;F(t,function(n){F(i,function(t,e){t!==n||r||(i.splice(e,1),r=!0)}),n.callback.apply(n,e)}),u<=n.concurrency-n.buffer&&n.unsaturated(),n.tasks.length+u===0&&n.drain(),n.process()}}if(null==t)t=1;else if(0===t)throw new Error("Concurrency must not be zero");var u=0,i=[],c={tasks:[],concurrency:t,payload:r,saturated:s,unsaturated:s,buffer:t/4,empty:s,drain:s,started:!1,paused:!1,push:function(n,t){e(c,n,!1,t)},kill:function(){c.drain=s,c.tasks=[]},unshift:function(n,t){e(c,n,!0,t)},process:function(){for(;!c.paused&&u<c.concurrency&&c.tasks.length;){var t=c.payload?c.tasks.splice(0,c.payload):c.tasks.splice(0,c.tasks.length),r=kn(t,y("data"));0===c.tasks.length&&c.empty(),u+=1,i.push(t[0]),u===c.concurrency&&c.saturated();var e=x(o(c,t));n(r,e)}},length:function(){return c.tasks.length},running:function(){return u},workersList:function(){return i},idle:function(){return c.tasks.length+u===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++)qo(c.process)}}};return c}function Yn(n,t){return Xn(n,1,t)}function Zn(n,t,r,e){I(t)(n,r,e)}function nt(n,t,r,e){Ro(n,function(n,e,o){r(t,n,function(n,r){t=r,o(n)})},function(n){e(n,t)})}function tt(){var n=arguments;return a(function(t){var r=this,e=t[t.length-1];"function"==typeof e?t.pop():e=s,nt(n,t,function(n,t,e){t.apply(r,n.concat([a(function(n,t){e(n,t)})]))},function(n,t){e.apply(r,[n].concat(t))})})}function rt(){return tt.apply(null,Wo.call(arguments))}function et(n,t,r,e){var o=[];n(t,function(n,t,e){r(n,function(n,t){o=o.concat(t||[]),e(n)})},function(n){e(n,o)})}function ot(n){return function(t,r,e){return n(No,t,r,e)}}function ut(n){return function(t,r,e){return n(Ro,t,r,e)}}function it(n,t,r){return function(e,o,u,i){function c(n){i&&(n?i(n):i(null,r(!1)))}function a(n,e,o){return i?void u(n,function(e,c){i&&(e?(i(e),i=u=!1):t(c)&&(i(null,r(!0,n)),i=u=!1)),o()}):o()}arguments.length>3?(i=i||s,n(e,o,a,c)):(i=u,i=i||s,u=o,n(e,a,c))}}function ct(n,t){return t}function at(n){return a(function(t,r){t.apply(null,r.concat([a(function(t,r){"object"==typeof console&&(t?console.error&&console.error(t):console[n]&&F(r,function(t){console[n](t)}))})]))})}function ft(n,t,r){r=r||s;var e=a(function(t,e){t?r(t):(e.push(o),n.apply(this,e))}),o=function(n,o){return n?r(n):o?void t(e):r(null)};n(o)}function lt(n,t,r){var e=0;ft(function(n){return e++<1?n(null,!0):void t.apply(this,arguments)},n,r)}function st(n,t,r){if(r=r||s,!n())return r(null);var e=a(function(o,u){return o?r(o):n.apply(this,u)?t(e):void r.apply(null,[null].concat(u))});t(e)}function pt(n,t,r){var e=0;return st(function(){return++e<=1||t.apply(this,arguments)},n,r)}function yt(n,t,r){return pt(n,function(){return!t.apply(this,arguments)},r)}function vt(n){return function(t,r,e){return n(t,e)}}function ht(n,t,r,e){return I(t)(n,vt(r),e)}function mt(n){return f(function(t,r){var e=!0;t.push(function(){var n=arguments;e?qo(function(){r.apply(null,n)}):r.apply(null,n)}),n.apply(this,t),e=!1})}function dt(n){return!n}function gt(n,t,r,e){var o=[];n(t,function(n,t,e){r(n,function(r,u){r?e(r):(u&&o.push({index:t,value:n}),e())})},function(n){n?e(n):e(null,kn(o.sort(function(n,t){return n.index-t.index}),y("value")))})}function bt(n,t){function r(n){return n?e(n):void o(r)}var e=x(t||s),o=mt(n);r()}function jt(n){function t(r){function e(){return n.length&&n[r].apply(null,arguments),e.next()}return e.next=function(){return r<n.length-1?t(r+1):null},e}return t(0)}function wt(n,t){return t in n}function _t(n,t){var r=Object.create(null),e=Object.create(null);t=t||Cn;var o=f(function(o,u){var i=t.apply(null,o);wt(r,i)?qo(function(){u.apply(null,r[i])}):wt(e,i)?e[i].push(u):(e[i]=[u],n.apply(null,o.concat([a(function(n){r[i]=n;var t=e[i];delete e[i];for(var o=0,u=t.length;u>o;o++)t[o].apply(null,n)})])))});return o.memo=r,o.unmemoized=n,o}function Ot(n,t,r){r=r||s;var e=h(t)?[]:{};n(t,function(n,t,r){n(a(function(n,o){o.length<=1&&(o=o[0]),e[t]=o,r(n)}))},function(n){r(n,e)})}function St(n,t,r){return Ot(I(t),n,r)}function kt(n,t){return Xn(function(t,r){n(t[0],r)},t,1)}function Et(n,t){function r(n,t){return n.priority-t.priority}function e(n,t,r){for(var e=-1,o=n.length-1;o>e;){var u=e+(o-e+1>>>1);r(t,n[u])>=0?e=u:o=u-1}return e}function o(n,t,o,u){if(null!=u&&"function"!=typeof u)throw new Error("task callback must be a function");return n.started=!0,jr(t)||(t=[t]),0===t.length?qo(function(){n.drain()}):void F(t,function(t){var i={data:t,priority:o,callback:"function"==typeof u?u:s};n.tasks.splice(e(n.tasks,i,r)+1,0,i),n.tasks.length===n.concurrency&&n.saturated(),n.tasks.length<=n.concurrency-n.buffer&&n.unsaturated(),qo(n.process)})}var u=kt(n,t);return u.push=function(n,t,r){o(u,n,t,r)},delete u.unshift,u}function At(n,t){return function(r,e){if(null==r)return r;if(!h(r))return n(r,e);for(var o=r.length,u=t?o:-1,i=Object(r);(t?u--:++u<o)&&e(i[u],u,i)!==!1;);return r}}function Lt(n,t){return"function"==typeof t&&jr(n)?F(n,t):au(n,Wn(t))}function xt(n,t){return t=p(t||s),jr(n)?n.length?void Lt(n,function(n){n(t)}):t():t(new TypeError("First argument to race must be an array of functions"))}function It(n,t,r,e){var o=fu.call(n).reverse();nt(o,t,r,e)}function Tt(n){return f(function(t,r){return t.push(a(function(n,t){if(n)r(null,{error:n});else{var e=null;1===t.length?e=t[0]:t.length>1&&(e=t),r(null,{value:e})}})),n.apply(this,t)})}function Mt(n,t,r,e){gt(n,t,function(n,t){r(n,function(n,r){n?t(n):t(null,!r)})},e)}function $t(n){return n.map(Tt)}function zt(n,t){return Ot(Ro,n,t)}function Ft(n,t,r){function e(n,t){if("object"==typeof t)n.times=+t.times||i,n.interval=+t.interval||c;else{if("number"!=typeof t&&"string"!=typeof t)throw new Error("Invalid arguments for async.retry");n.times=+t||i}}function o(n){return function(r){t(function(t,e){r(!t||n,{err:t,result:e})})}}function u(n){return function(t){setTimeout(function(){t(null)},n)}}var i=5,c=0,a={times:i,interval:c};if(arguments.length<3&&"function"==typeof n?(r=t||s,t=n):(e(a,n),r=r||s),"function"!=typeof t)throw new Error("Invalid arguments for async.retry");for(var f=[];a.times;){var l=!(a.times-=1);f.push(o(l)),!l&&a.interval>0&&f.push(u(a.interval))}zt(f,function(n,t){t=t[t.length-1],r(t.err,t.result)})}function Pt(n,t){return t||(t=n,n=null),f(function(r,e){function o(n){t.apply(null,r.concat([n]))}n?Ft(n,o,e):Ft(o,e)})}function Dt(n,t,r){function e(n,t){var r=n.criteria,e=t.criteria;return e>r?-1:r>e?1:0}Lr(n,function(n,r){t(n,function(t,e){return t?r(t):void r(null,{value:n,criteria:e})})},function(n,t){return n?r(n):void r(null,kn(t.sort(e),y("value")))})}function Bt(n,t,r){function e(){c||(u.apply(null,arguments),clearTimeout(i))}function o(){var t=n.name||"anonymous",e=new Error('Callback function "'+t+'" timed out.');e.code="ETIMEDOUT",r&&(e.info=r),c=!0,u(e)}var u,i,c=!1;return f(function(r,c){u=c,i=setTimeout(o,t),n.apply(null,r.concat(e))})}function Ut(n,t,r,e){for(var o=-1,u=du(mu((t-n)/(r||1)),0),i=Array(u);u--;)i[e?u:++o]=n,n+=r;return i}function Ct(n,t,r,e){return Ar(Ut(0,n,1),t,r,e)}function qt(n,t,r,e){3===arguments.length&&(e=r,r=t,t=jr(n)?[]:{}),No(n,function(n,e,o){r(t,n,e,o)},function(n){e(n,t)})}function Rt(n){return function(){return(n.unmemoized||n).apply(null,arguments)}}function Wt(n,t,r){return st(function(){return!n.apply(this,arguments)},t,r)}function Nt(n,t){function r(o){if(e===n.length)return t.apply(null,[null].concat(o));var u=x(a(function(n,e){return n?t.apply(null,[n].concat(e)):void r(e)}));o.push(u);var i=n[e++];i.apply(null,o)}if(t=p(t||s),!jr(n))return t(new Error("First argument to waterfall must be an array of functions"));if(!n.length)return t();var e=0;r([])}var Vt="[object Function]",Qt="[object GeneratorFunction]",Gt=Object.prototype,Ht=Gt.toString,Jt="[object Symbol]",Kt=Object.prototype,Xt=Kt.toString,Yt=NaN,Zt=/^\s+|\s+$/g,nr=/^[-+]0x[0-9a-f]+$/i,tr=/^0b[01]+$/i,rr=/^0o[0-7]+$/i,er=parseInt,or=1/0,ur=1.7976931348623157e308,ir="Expected a function",cr=Math.max,ar=y("length"),fr=9007199254740991,lr="function"==typeof Symbol&&Symbol.iterator,sr=Object.getPrototypeOf,pr=Object.prototype,yr=pr.hasOwnProperty,vr=Object.keys,hr="[object Arguments]",mr=Object.prototype,dr=mr.hasOwnProperty,gr=mr.toString,br=mr.propertyIsEnumerable,jr=Array.isArray,wr="[object String]",_r=Object.prototype,Or=_r.toString,Sr=9007199254740991,kr=/^(?:0|[1-9]\d*)$/,Er=Object.prototype,Ar=T(M),Lr=$(Ar,1/0),xr=l(Lr),Ir=$(Ar,1),Tr=l(Ir),Mr=a(function(n,t){return a(function(r){return n.apply(null,t.concat(r))})}),$r=P(),zr=Array.prototype,Fr=zr.splice,Pr=/[\\^$.*+?()[\]{}|]/g,Dr=/^\[object .+?Constructor\]$/,Br=Object.prototype,Ur=Function.prototype.toString,Cr=Br.hasOwnProperty,qr=RegExp("^"+Ur.call(Cr).replace(Pr,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),Rr=J(Object,"create"),Wr=Object.prototype;K.prototype=Rr?Rr(null):Wr;var Nr={"function":!0,object:!0},Vr=Nr[typeof n]&&n&&!n.nodeType?n:void 0,Qr=Nr[typeof module]&&module&&!module.nodeType?module:void 0,Gr=X(Vr&&Qr&&"object"==typeof global&&global),Hr=X(Nr[typeof self]&&self),Jr=X(Nr[typeof window]&&window),Kr=X(Nr[typeof this]&&this),Xr=Gr||Jr!==(Kr&&Kr.window)&&Jr||Hr||Kr||Function("return this")(),Yr=J(Xr,"Map"),Zr=Object.prototype,ne=Zr.hasOwnProperty,te="__lodash_hash_undefined__",re=Object.prototype,ee=re.hasOwnProperty,oe="__lodash_hash_undefined__";ln.prototype.clear=Y,ln.prototype["delete"]=rn,ln.prototype.get=on,ln.prototype.has=un,ln.prototype.set=fn;var ue=200;pn.prototype.clear=B,pn.prototype["delete"]=R,pn.prototype.get=N,pn.prototype.has=Q,pn.prototype.set=sn;var ie=1,ce=2,ae=Xr.Symbol,fe=Xr.Uint8Array,le=1,se=2,pe="[object Boolean]",ye="[object Date]",ve="[object Error]",he="[object Map]",me="[object Number]",de="[object RegExp]",ge="[object Set]",be="[object String]",je="[object Symbol]",we="[object ArrayBuffer]",_e="[object DataView]",Oe=ae?ae.prototype:void 0,Se=Oe?Oe.valueOf:void 0,ke=2,Ee=J(Xr,"DataView"),Ae=J(Xr,"Promise"),Le=J(Xr,"Set"),xe=J(Xr,"WeakMap"),Ie="[object Map]",Te="[object Object]",Me="[object Promise]",$e="[object Set]",ze="[object WeakMap]",Fe="[object DataView]",Pe=Object.prototype,De=Function.prototype.toString,Be=Pe.toString,Ue=Ee?Ee+"":"",Ce=Yr?De.call(Yr):"",qe=Ae?De.call(Ae):"",Re=Le?De.call(Le):"",We=xe?De.call(xe):"";(Ee&&bn(new Ee(new ArrayBuffer(1)))!=Fe||Yr&&bn(new Yr)!=Ie||Ae&&bn(Ae.resolve())!=Me||Le&&bn(new Le)!=$e||xe&&bn(new xe)!=ze)&&(bn=function(n){var t=Be.call(n),r=t==Te?n.constructor:null,e="function"==typeof r?De.call(r):"";if(e)switch(e){case Ue:return Fe;case Ce:return Ie;case qe:return Me;case Re:return $e;case We:return ze}return t});var Ne=bn,Ve="[object Arguments]",Qe="[object Array]",Ge="[object Boolean]",He="[object Date]",Je="[object Error]",Ke="[object Function]",Xe="[object Map]",Ye="[object Number]",Ze="[object Object]",no="[object RegExp]",to="[object Set]",ro="[object String]",eo="[object WeakMap]",oo="[object ArrayBuffer]",uo="[object DataView]",io="[object Float32Array]",co="[object Float64Array]",ao="[object Int8Array]",fo="[object Int16Array]",lo="[object Int32Array]",so="[object Uint8Array]",po="[object Uint8ClampedArray]",yo="[object Uint16Array]",vo="[object Uint32Array]",ho={};ho[io]=ho[co]=ho[ao]=ho[fo]=ho[lo]=ho[so]=ho[po]=ho[yo]=ho[vo]=!0,ho[Ve]=ho[Qe]=ho[oo]=ho[Ge]=ho[uo]=ho[He]=ho[Je]=ho[Ke]=ho[Xe]=ho[Ye]=ho[Ze]=ho[no]=ho[to]=ho[ro]=ho[eo]=!1;var mo=Object.prototype,go=mo.toString,bo=2,jo="[object Arguments]",wo="[object Array]",_o="[object Object]",Oo=Object.prototype,So=Oo.hasOwnProperty,ko=1,Eo=2,Ao="Expected a function";In.Cache=ln;var Lo,xo=1/0,Io=ae?ae.prototype:void 0,To=Io?Io.toString:void 0,Mo=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]/g,$o=/\\(\\)?/g,zo=In(function(n){var t=[];return Tn(n).replace(Mo,function(n,r,e,o){t.push(e?o.replace($o,"$1"):r||n)}),t}),Fo=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,Po=/^\w*$/,Do=1,Bo=2,Uo=/^function\s*[^\(]*\(\s*([^\)]*)\)/m,Co="function"==typeof setImmediate&&setImmediate;Lo=Co?Co:"object"==typeof process&&"function"==typeof process.nextTick?process.nextTick:function(n){setTimeout(n,0)};var qo=a(function(n,t){Lo(function(){n.apply(null,t)})}),Ro=$(Zn,1),Wo=Array.prototype.reverse,No=$(Zn,1/0),Vo=ot(et),Qo=ut(et),Go=a(function(n){var t=[null].concat(n);return f(function(n,r){return r.apply(this,t)})}),Ho=it(No,Cn,ct),Jo=it(Zn,Cn,ct),Ko=it(Ro,Cn,ct),Xo=at("dir"),Yo=$(ht,1/0),Zo=$(ht,1),nu=it(Zn,dt,dt),tu=$(nu,1/0),ru=$(nu,1),eu=T(gt),ou=$(eu,1/0),uu=$(eu,1),iu=at("log"),cu=$(St,1/0),au=At(D),fu=Array.prototype.slice,lu=T(Mt),su=$(lu,1/0),pu=$(lu,1),yu=it(Zn,Boolean,Cn),vu=$(yu,1/0),hu=$(yu,1),mu=Math.ceil,du=Math.max,gu=$(Ct,1/0),bu=$(Ct,1),ju={applyEach:xr,applyEachSeries:Tr,apply:Mr,asyncify:z,auto:Gn,autoInject:Kn,cargo:Yn,compose:rt,concat:Vo,concatSeries:Qo,constant:Go,detect:Ho,detectLimit:Jo,detectSeries:Ko,dir:Xo,doDuring:lt,doUntil:yt,doWhilst:pt,during:ft,each:Yo,eachLimit:ht,eachOf:No,eachOfLimit:Zn,eachOfSeries:Ro,eachSeries:Zo,ensureAsync:mt,every:tu,everyLimit:nu,everySeries:ru,filter:ou,filterLimit:eu,filterSeries:uu,forever:bt,iterator:jt,log:iu,map:Lr,mapLimit:Ar,mapSeries:Ir,memoize:_t,nextTick:qo,parallel:cu,parallelLimit:St,priorityQueue:Et,queue:kt,race:xt,reduce:nt,reduceRight:It,reflect:Tt,reflectAll:$t,reject:su,rejectLimit:lu,rejectSeries:pu,retry:Ft,retryable:Pt,seq:tt,series:zt,setImmediate:qo,some:vu,someLimit:yu,someSeries:hu,sortBy:Dt,timeout:Bt,times:gu,timesLimit:Ct,timesSeries:bu,transform:qt,unmemoize:Rt,until:Wt,waterfall:Nt,whilst:st,all:tu,any:vu,forEach:Yo,forEachSeries:Zo,forEachLimit:ht,forEachOf:No,forEachOfSeries:Ro,forEachOfLimit:Zn,inject:nt,foldl:nt,foldr:It,select:ou,selectLimit:eu,selectSeries:uu,wrapSync:z};n["default"]=ju,n.applyEach=xr,n.applyEachSeries=Tr,n.apply=Mr,n.asyncify=z,n.auto=Gn,n.autoInject=Kn,n.cargo=Yn,n.compose=rt,n.concat=Vo,n.concatSeries=Qo,n.constant=Go,n.detect=Ho,n.detectLimit=Jo,n.detectSeries=Ko,n.dir=Xo,n.doDuring=lt,n.doUntil=yt,n.doWhilst=pt,n.during=ft,n.each=Yo,n.eachLimit=ht,n.eachOf=No,n.eachOfLimit=Zn,n.eachOfSeries=Ro,n.eachSeries=Zo,n.ensureAsync=mt,n.every=tu,n.everyLimit=nu,n.everySeries=ru,n.filter=ou,n.filterLimit=eu,n.filterSeries=uu,n.forever=bt,n.iterator=jt,n.log=iu,n.map=Lr,n.mapLimit=Ar,n.mapSeries=Ir,n.memoize=_t,n.nextTick=qo,n.parallel=cu,n.parallelLimit=St,n.priorityQueue=Et,n.queue=kt,n.race=xt,n.reduce=nt,n.reduceRight=It,n.reflect=Tt,n.reflectAll=$t,n.reject=su,n.rejectLimit=lu,n.rejectSeries=pu,n.retry=Ft,n.retryable=Pt,n.seq=tt,n.series=zt,n.setImmediate=qo,n.some=vu,n.someLimit=yu,n.someSeries=hu,n.sortBy=Dt,n.timeout=Bt,n.times=gu,n.timesLimit=Ct,n.timesSeries=bu,n.transform=qt,n.unmemoize=Rt,n.until=Wt,n.waterfall=Nt,n.whilst=st,n.all=tu,n.allLimit=nu,n.allSeries=ru,n.any=vu,n.anyLimit=yu,n.anySeries=hu,n.find=Ho,n.findLimit=Jo,n.findSeries=Ko,n.forEach=Yo,n.forEachSeries=Zo,n.forEachLimit=ht,n.forEachOf=No,n.forEachOfSeries=Ro,n.forEachOfLimit=Zn,n.inject=nt,n.foldl=nt,n.foldr=It,n.select=ou,n.selectLimit=eu,n.selectSeries=uu,n.wrapSync=z}); -//# sourceMappingURL=dist/async.min.map
\ No newline at end of file +!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,r){var e=r.length;switch(e){case 0:return n.call(t);case 1:return n.call(t,r[0]);case 2:return n.call(t,r[0],r[1]);case 3:return n.call(t,r[0],r[1],r[2])}return n.apply(t,r)}function r(n){var t=typeof n;return!!n&&("object"==t||"function"==t)}function e(n){var t=r(n)?Ht.call(n):"";return t==Vt||t==Qt}function o(n){return!!n&&"object"==typeof n}function u(n){return"symbol"==typeof n||o(n)&&Xt.call(n)==Jt}function i(n){if("number"==typeof n)return n;if(u(n))return Yt;if(r(n)){var t=e(n.valueOf)?n.valueOf():n;n=r(t)?t+"":t}if("string"!=typeof n)return 0===n?n:+n;n=n.replace(Zt,"");var o=tr.test(n);return o||rr.test(n)?er(n.slice(2),o?2:8):nr.test(n)?Yt:+n}function c(n){if(!n)return 0===n?n:0;if(n=i(n),n===or||n===-or){var t=0>n?-1:1;return t*ur}var r=n%1;return n===n?r?n-r:n:0}function a(n,r){if("function"!=typeof n)throw new TypeError(ir);return r=cr(void 0===r?n.length-1:c(r),0),function(){for(var e=arguments,o=-1,u=cr(e.length-r,0),i=Array(u);++o<u;)i[o]=e[r+o];switch(r){case 0:return n.call(this,i);case 1:return n.call(this,e[0],i);case 2:return n.call(this,e[0],e[1],i)}var c=Array(r+1);for(o=-1;++o<r;)c[o]=e[o];return c[r]=i,t(n,this,c)}}function f(n){return a(function(t){var r=t.pop();n.call(this,t,r)})}function l(n){return a(function(t,r){var e=f(function(r,e){var o=this;return n(t,function(n,t){n.apply(o,r.concat([t]))},e)});return r.length?e.apply(this,r):e})}function s(){}function p(n){return function(){if(null!==n){var t=n;n=null,t.apply(this,arguments)}}}function y(n){return function(t){return null==t?void 0:t[n]}}function v(n){return"number"==typeof n&&n>-1&&n%1==0&&fr>=n}function h(n){return null!=n&&v(ar(n))&&!e(n)}function m(n){return lr&&n[lr]&&n[lr]()}function d(n){return sr(Object(n))}function g(n,t){return yr.call(n,t)||"object"==typeof n&&t in n&&null===d(n)}function b(n){return vr(Object(n))}function j(n,t){for(var r=-1,e=Array(n);++r<n;)e[r]=t(r);return e}function w(n){return o(n)&&h(n)}function _(n){return w(n)&&dr.call(n,"callee")&&(!br.call(n,"callee")||gr.call(n)==hr)}function O(n){return"string"==typeof n||!jr(n)&&o(n)&&Or.call(n)==wr}function S(n){var t=n?n.length:void 0;return v(t)&&(jr(n)||O(n)||_(n))?j(t,String):null}function k(n,t){return n="number"==typeof n||kr.test(n)?+n:-1,t=null==t?Sr:t,n>-1&&n%1==0&&t>n}function E(n){var t=n&&n.constructor,r="function"==typeof t&&t.prototype||Er;return n===r}function A(n){var t=E(n);if(!t&&!h(n))return b(n);var r=S(n),e=!!r,o=r||[],u=o.length;for(var i in n)!g(n,i)||e&&("length"==i||k(i,u))||t&&"constructor"==i||o.push(i);return o}function L(n){var t,r=-1;if(h(n))return t=n.length,function(){return r++,t>r?{value:n[r],key:r}:null};var e=m(n);if(e)return function(){var n=e.next();return n.done?null:(r++,{value:n.value,key:r})};var o=A(n);return t=o.length,function(){r++;var e=o[r];return t>r?{value:n[e],key:e}:null}}function x(n){return function(){if(null===n)throw new Error("Callback was already called.");var t=n;n=null,t.apply(this,arguments)}}function I(n){return function(t,r,e){e=p(e||s),t=t||[];var o=L(t);if(0>=n)return e(null);var u=!1,i=0,c=!1;!function a(){if(u&&0>=i)return e(null);for(;n>i&&!c;){var t=o();if(null===t)return u=!0,void(0>=i&&e(null));i+=1,r(t.value,t.key,x(function(n){i-=1,n?(e(n),c=!0):a()}))}}()}}function T(n){return function(t,r,e,o){return n(I(r),t,e,o)}}function M(n,t,r,e){e=p(e||s),t=t||[];var o=h(t)||m(t)?[]:{};n(t,function(n,t,e){r(n,function(n,r){o[t]=r,e(n)})},function(n){e(n,o)})}function $(n,t){return function(r,e,o){return n(r,t,e,o)}}function z(n){return f(function(t,e){var o;try{o=n.apply(this,t)}catch(u){return e(u)}r(o)&&"function"==typeof o.then?o.then(function(n){e(null,n)})["catch"](function(n){e(n.message?n:new Error(n))}):e(null,o)})}function F(n,t){for(var r=-1,e=n.length;++r<e&&t(n[r],r,n)!==!1;);return n}function P(n){return function(t,r,e){for(var o=-1,u=Object(t),i=e(t),c=i.length;c--;){var a=i[n?c:++o];if(r(u[a],a,u)===!1)break}return t}}function D(n,t){return n&&$r(n,t,A)}function B(){this.__data__={array:[],map:null}}function U(n,t){return n===t||n!==n&&t!==t}function C(n,t){for(var r=n.length;r--;)if(U(n[r][0],t))return r;return-1}function q(n,t){var r=C(n,t);if(0>r)return!1;var e=n.length-1;return r==e?n.pop():Fr.call(n,r,1),!0}function R(n){var t=this.__data__,r=t.array;return r?q(r,n):t.map["delete"](n)}function W(n,t){var r=C(n,t);return 0>r?void 0:n[r][1]}function N(n){var t=this.__data__,r=t.array;return r?W(r,n):t.map.get(n)}function V(n,t){return C(n,t)>-1}function Q(n){var t=this.__data__,r=t.array;return r?V(r,n):t.map.has(n)}function G(n){var t=!1;if(null!=n&&"function"!=typeof n.toString)try{t=!!(n+"")}catch(r){}return t}function H(n){return null==n?!1:e(n)?qr.test(Ur.call(n)):o(n)&&(G(n)?qr:Dr).test(n)}function J(n,t){var r=n[t];return H(r)?r:void 0}function K(){}function X(n){return n&&n.Object===Object?n:null}function Y(){this.__data__={hash:new K,map:Yr?new Yr:[],string:new K}}function Z(n,t){return Rr?void 0!==n[t]:ne.call(n,t)}function nn(n,t){return Z(n,t)&&delete n[t]}function tn(n){var t=typeof n;return"number"==t||"boolean"==t||"string"==t&&"__proto__"!=n||null==n}function rn(n){var t=this.__data__;return tn(n)?nn("string"==typeof n?t.string:t.hash,n):Yr?t.map["delete"](n):q(t.map,n)}function en(n,t){if(Rr){var r=n[t];return r===te?void 0:r}return ee.call(n,t)?n[t]:void 0}function on(n){var t=this.__data__;return tn(n)?en("string"==typeof n?t.string:t.hash,n):Yr?t.map.get(n):W(t.map,n)}function un(n){var t=this.__data__;return tn(n)?Z("string"==typeof n?t.string:t.hash,n):Yr?t.map.has(n):V(t.map,n)}function cn(n,t,r){var e=C(n,t);0>e?n.push([t,r]):n[e][1]=r}function an(n,t,r){n[t]=Rr&&void 0===r?oe:r}function fn(n,t){var r=this.__data__;return tn(n)?an("string"==typeof n?r.string:r.hash,n,t):Yr?r.map.set(n,t):cn(r.map,n,t),this}function ln(n){var t=-1,r=n?n.length:0;for(this.clear();++t<r;){var e=n[t];this.set(e[0],e[1])}}function sn(n,t){var r=this.__data__,e=r.array;e&&(e.length<ue-1?cn(e,n,t):(r.array=null,r.map=new ln(e)));var o=r.map;return o&&o.set(n,t),this}function pn(n){var t=-1,r=n?n.length:0;for(this.clear();++t<r;){var e=n[t];this.set(e[0],e[1])}}function yn(n,t){for(var r=-1,e=n.length;++r<e;)if(t(n[r],r,n))return!0;return!1}function vn(n,t,r,e,o,u){var i=-1,c=o&ce,a=o&ie,f=n.length,l=t.length;if(f!=l&&!(c&&l>f))return!1;var s=u.get(n);if(s)return s==t;var p=!0;for(u.set(n,t);++i<f;){var y=n[i],v=t[i];if(e)var h=c?e(v,y,i,t,n,u):e(y,v,i,n,t,u);if(void 0!==h){if(h)continue;p=!1;break}if(a){if(!yn(t,function(n){return y===n||r(y,n,e,o,u)})){p=!1;break}}else if(y!==v&&!r(y,v,e,o,u)){p=!1;break}}return u["delete"](n),p}function hn(n){var t=-1,r=Array(n.size);return n.forEach(function(n,e){r[++t]=[e,n]}),r}function mn(n){var t=-1,r=Array(n.size);return n.forEach(function(n){r[++t]=n}),r}function dn(n,t,r,e,o,u,i){switch(r){case _e:if(n.byteLength!=t.byteLength||n.byteOffset!=t.byteOffset)return!1;n=n.buffer,t=t.buffer;case we:return n.byteLength==t.byteLength&&e(new fe(n),new fe(t))?!0:!1;case pe:case ye:return+n==+t;case ve:return n.name==t.name&&n.message==t.message;case me:return n!=+n?t!=+t:n==+t;case de:case be:return n==t+"";case he:var c=hn;case ge:var a=u&se;if(c||(c=mn),n.size!=t.size&&!a)return!1;var f=i.get(n);return f?f==t:(u|=le,i.set(n,t),vn(c(n),c(t),e,o,u,i));case je:if(Se)return Se.call(n)==Se.call(t)}return!1}function gn(n,t,r,e,o,u){var i=o&ke,c=A(n),a=c.length,f=A(t),l=f.length;if(a!=l&&!i)return!1;for(var s=a;s--;){var p=c[s];if(!(i?p in t:g(t,p)))return!1}var y=u.get(n);if(y)return y==t;var v=!0;u.set(n,t);for(var h=i;++s<a;){p=c[s];var m=n[p],d=t[p];if(e)var b=i?e(d,m,p,t,n,u):e(m,d,p,n,t,u);if(!(void 0===b?m===d||r(m,d,e,o,u):b)){v=!1;break}h||(h="constructor"==p)}if(v&&!h){var j=n.constructor,w=t.constructor;j!=w&&"constructor"in n&&"constructor"in t&&!("function"==typeof j&&j instanceof j&&"function"==typeof w&&w instanceof w)&&(v=!1)}return u["delete"](n),v}function bn(n){return Be.call(n)}function jn(n){return o(n)&&v(n.length)&&!!ho[go.call(n)]}function wn(n,t,r,e,o,u){var i=jr(n),c=jr(t),a=wo,f=wo;i||(a=Ne(n),a=a==jo?_o:a),c||(f=Ne(t),f=f==jo?_o:f);var l=a==_o&&!G(n),s=f==_o&&!G(t),p=a==f;if(p&&!l)return u||(u=new pn),i||jn(n)?vn(n,t,r,e,o,u):dn(n,t,a,r,e,o,u);if(!(o&bo)){var y=l&&So.call(n,"__wrapped__"),v=s&&So.call(t,"__wrapped__");if(y||v){var h=y?n.value():n,m=v?t.value():t;return u||(u=new pn),r(h,m,e,o,u)}}return p?(u||(u=new pn),gn(n,t,r,e,o,u)):!1}function _n(n,t,e,u,i){return n===t?!0:null==n||null==t||!r(n)&&!o(t)?n!==n&&t!==t:wn(n,t,_n,e,u,i)}function On(n,t,r,e){var o=r.length,u=o,i=!e;if(null==n)return!u;for(n=Object(n);o--;){var c=r[o];if(i&&c[2]?c[1]!==n[c[0]]:!(c[0]in n))return!1}for(;++o<u;){c=r[o];var a=c[0],f=n[a],l=c[1];if(i&&c[2]){if(void 0===f&&!(a in n))return!1}else{var s=new pn;if(e)var p=e(f,l,a,n,t,s);if(!(void 0===p?_n(l,f,e,ko|Eo,s):p))return!1}}return!0}function Sn(n){return n===n&&!r(n)}function kn(n,t){for(var r=-1,e=n.length,o=Array(e);++r<e;)o[r]=t(n[r],r,n);return o}function En(n,t){return kn(t,function(t){return[t,n[t]]})}function An(n){return En(n,A(n))}function Ln(n){for(var t=An(n),r=t.length;r--;)t[r][2]=Sn(t[r][1]);return t}function xn(n){var t=Ln(n);if(1==t.length&&t[0][2]){var r=t[0][0],e=t[0][1];return function(n){return null==n?!1:n[r]===e&&(void 0!==e||r in Object(n))}}return function(r){return r===n||On(r,n,t)}}function In(n,t){if("function"!=typeof n||t&&"function"!=typeof t)throw new TypeError(Ao);var r=function(){var e=arguments,o=t?t.apply(this,e):e[0],u=r.cache;if(u.has(o))return u.get(o);var i=n.apply(this,e);return r.cache=u.set(o,i),i};return r.cache=new(In.Cache||ln),r}function Tn(n){if("string"==typeof n)return n;if(null==n)return"";if(u(n))return To?To.call(n):"";var t=n+"";return"0"==t&&1/n==-xo?"-0":t}function Mn(n){return jr(n)?n:zo(n)}function $n(n,t){var r=typeof n;return"number"==r||"symbol"==r?!0:!jr(n)&&(u(n)||Po.test(n)||!Fo.test(n)||null!=t&&n in Object(t))}function zn(n,t){t=$n(t,n)?[t]:Mn(t);for(var r=0,e=t.length;null!=n&&e>r;)n=n[t[r++]];return r&&r==e?n:void 0}function Fn(n,t,r){var e=null==n?void 0:zn(n,t);return void 0===e?r:e}function Pn(n,t){return t in Object(n)}function Dn(n,t,r){if(null==n)return!1;var e=r(n,t);if(!e&&!$n(t)){t=Mn(t);for(var o=-1,u=t.length;null!=n&&++o<u;){var i=t[o];if(!(e=r(n,i)))break;n=n[i]}}var u=n?n.length:void 0;return e||!!u&&v(u)&&k(t,u)&&(jr(n)||O(n)||_(n))}function Bn(n,t){return Dn(n,t,Pn)}function Un(n,t){return function(r){var e=Fn(r,n);return void 0===e&&e===t?Bn(r,n):_n(t,e,void 0,Do|Bo)}}function Cn(n){return n}function qn(n){return function(t){return zn(t,n)}}function Rn(n){return $n(n)?y(n):qn(n)}function Wn(n){return"function"==typeof n?n:null==n?Cn:"object"==typeof n?jr(n)?Un(n[0],n[1]):xn(n):Rn(n)}function Nn(n,t){return n&&D(n,Wn(t))}function Vn(n,t,r){for(var e=n.length,o=t+(r?0:-1);r?o--:++o<e;){var u=n[o];if(u!==u)return o}return-1}function Qn(n,t,r){if(t!==t)return Vn(n,r);for(var e=r-1,o=n.length;++e<o;)if(n[e]===t)return e;return-1}function Gn(n,t,r){function e(n,t){b.push(function(){c(n,t)})}function o(){if(0===b.length&&0===m)return r(null,h);for(;b.length&&t>m;){var n=b.shift();n()}}function u(n,t){var r=g[n];r||(r=g[n]=[]),r.push(t)}function i(n){var t=g[n]||[];F(t,function(n){n()}),o()}function c(n,t){if(!d){var e=x(a(function(t,e){if(m--,e.length<=1&&(e=e[0]),t){var o={};Nn(h,function(n,t){o[t]=n}),o[n]=e,d=!0,g=[],r(t,o)}else h[n]=e,i(n)}));m++;var o=t[t.length-1];t.length>1?o(h,e):o(e)}}function f(){for(var n,t=0;j.length;)n=j.pop(),t++,F(l(n),function(n){--w[n]||j.push(n)});if(t!==v)throw new Error("async.auto cannot execute tasks due to a recursive dependency")}function l(t){var r=[];return Nn(n,function(n,e){jr(n)&&Qn(n,t,0)>=0&&r.push(e)}),r}"function"==typeof t&&(r=t,t=null),r=p(r||s);var y=A(n),v=y.length;if(!v)return r(null);t||(t=v);var h={},m=0,d=!1,g={},b=[],j=[],w={};Nn(n,function(t,r){if(!jr(t))return e(r,[t]),void j.push(r);var o=t.slice(0,t.length-1),i=o.length;i||(e(r,[t]),j.push(r)),w[r]=i,F(o,function(c){if(!n[c])throw new Error("async.auto task `"+r+"` has a non-existent dependency in "+o.join(", "));u(c,function(){i--,0===i&&e(r,t)})})}),f(),o()}function Hn(n,t){var r=-1,e=n.length;for(t||(t=Array(e));++r<e;)t[r]=n[r];return t}function Jn(n){return n.toString().match(Uo)[1].split(/\s*\,\s*/)}function Kn(n,t){var r={};Nn(n,function(n,t){function e(t,r){var e=kn(o,function(n){return t[n]});e.push(r),n.apply(null,e)}var o;if(jr(n))o=Hn(n),n=o.pop(),r[t]=o.concat(e);else{if(0===n.length)throw new Error("autoInject task functions require explicit parameters.");1===n.length?r[t]=n:(o=Jn(n),o.pop(),r[t]=o.concat(e))}}),Gn(r,t)}function Xn(n,t,r){function e(n,t,r,e){if(null!=e&&"function"!=typeof e)throw new Error("task callback must be a function");return n.started=!0,jr(t)||(t=[t]),0===t.length&&n.idle()?qo(function(){n.drain()}):(F(t,function(t){var o={data:t,callback:e||s};r?n.tasks.unshift(o):n.tasks.push(o)}),void qo(n.process))}function o(n,t){return function(){u-=1;var r=!1,e=arguments;F(t,function(n){F(i,function(t,e){t!==n||r||(i.splice(e,1),r=!0)}),n.callback.apply(n,e)}),u<=n.concurrency-n.buffer&&n.unsaturated(),n.tasks.length+u===0&&n.drain(),n.process()}}if(null==t)t=1;else if(0===t)throw new Error("Concurrency must not be zero");var u=0,i=[],c={tasks:[],concurrency:t,payload:r,saturated:s,unsaturated:s,buffer:t/4,empty:s,drain:s,started:!1,paused:!1,push:function(n,t){e(c,n,!1,t)},kill:function(){c.drain=s,c.tasks=[]},unshift:function(n,t){e(c,n,!0,t)},process:function(){for(;!c.paused&&u<c.concurrency&&c.tasks.length;){var t=c.payload?c.tasks.splice(0,c.payload):c.tasks.splice(0,c.tasks.length),r=kn(t,y("data"));0===c.tasks.length&&c.empty(),u+=1,i.push(t[0]),u===c.concurrency&&c.saturated();var e=x(o(c,t));n(r,e)}},length:function(){return c.tasks.length},running:function(){return u},workersList:function(){return i},idle:function(){return c.tasks.length+u===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++)qo(c.process)}}};return c}function Yn(n,t){return Xn(n,1,t)}function Zn(n,t,r,e){I(t)(n,r,e)}function nt(n,t,r,e){Ro(n,function(n,e,o){r(t,n,function(n,r){t=r,o(n)})},function(n){e(n,t)})}function tt(){var n=arguments;return a(function(t){var r=this,e=t[t.length-1];"function"==typeof e?t.pop():e=s,nt(n,t,function(n,t,e){t.apply(r,n.concat([a(function(n,t){e(n,t)})]))},function(n,t){e.apply(r,[n].concat(t))})})}function rt(){return tt.apply(null,Wo.call(arguments))}function et(n,t,r,e){var o=[];n(t,function(n,t,e){r(n,function(n,t){o=o.concat(t||[]),e(n)})},function(n){e(n,o)})}function ot(n){return function(t,r,e){return n(No,t,r,e)}}function ut(n){return function(t,r,e){return n(Ro,t,r,e)}}function it(n,t,r){return function(e,o,u,i){function c(n){i&&(n?i(n):i(null,r(!1)))}function a(n,e,o){return i?void u(n,function(e,c){i&&(e?(i(e),i=u=!1):t(c)&&(i(null,r(!0,n)),i=u=!1)),o()}):o()}arguments.length>3?(i=i||s,n(e,o,a,c)):(i=u,i=i||s,u=o,n(e,a,c))}}function ct(n,t){return t}function at(n){return a(function(t,r){t.apply(null,r.concat([a(function(t,r){"object"==typeof console&&(t?console.error&&console.error(t):console[n]&&F(r,function(t){console[n](t)}))})]))})}function ft(n,t,r){r=r||s;var e=a(function(t,e){t?r(t):(e.push(o),n.apply(this,e))}),o=function(n,o){return n?r(n):o?void t(e):r(null)};n(o)}function lt(n,t,r){var e=0;ft(function(n){return e++<1?n(null,!0):void t.apply(this,arguments)},n,r)}function st(n,t,r){if(r=r||s,!n())return r(null);var e=a(function(o,u){return o?r(o):n.apply(this,u)?t(e):void r.apply(null,[null].concat(u))});t(e)}function pt(n,t,r){var e=0;return st(function(){return++e<=1||t.apply(this,arguments)},n,r)}function yt(n,t,r){return pt(n,function(){return!t.apply(this,arguments)},r)}function vt(n){return function(t,r,e){return n(t,e)}}function ht(n,t,r,e){return I(t)(n,vt(r),e)}function mt(n){return f(function(t,r){var e=!0;t.push(function(){var n=arguments;e?qo(function(){r.apply(null,n)}):r.apply(null,n)}),n.apply(this,t),e=!1})}function dt(n){return!n}function gt(n,t,r,e){var o=[];n(t,function(n,t,e){r(n,function(r,u){r?e(r):(u&&o.push({index:t,value:n}),e())})},function(n){n?e(n):e(null,kn(o.sort(function(n,t){return n.index-t.index}),y("value")))})}function bt(n,t){function r(n){return n?e(n):void o(r)}var e=x(t||s),o=mt(n);r()}function jt(n){function t(r){function e(){return n.length&&n[r].apply(null,arguments),e.next()}return e.next=function(){return r<n.length-1?t(r+1):null},e}return t(0)}function wt(n,t){return t in n}function _t(n,t){var r=Object.create(null),e=Object.create(null);t=t||Cn;var o=f(function(o,u){var i=t.apply(null,o);wt(r,i)?qo(function(){u.apply(null,r[i])}):wt(e,i)?e[i].push(u):(e[i]=[u],n.apply(null,o.concat([a(function(n){r[i]=n;var t=e[i];delete e[i];for(var o=0,u=t.length;u>o;o++)t[o].apply(null,n)})])))});return o.memo=r,o.unmemoized=n,o}function Ot(n,t,r){r=r||s;var e=h(t)?[]:{};n(t,function(n,t,r){n(a(function(n,o){o.length<=1&&(o=o[0]),e[t]=o,r(n)}))},function(n){r(n,e)})}function St(n,t,r){return Ot(I(t),n,r)}function kt(n,t){return Xn(function(t,r){n(t[0],r)},t,1)}function Et(n,t){function r(n,t){return n.priority-t.priority}function e(n,t,r){for(var e=-1,o=n.length-1;o>e;){var u=e+(o-e+1>>>1);r(t,n[u])>=0?e=u:o=u-1}return e}function o(n,t,o,u){if(null!=u&&"function"!=typeof u)throw new Error("task callback must be a function");return n.started=!0,jr(t)||(t=[t]),0===t.length?qo(function(){n.drain()}):void F(t,function(t){var i={data:t,priority:o,callback:"function"==typeof u?u:s};n.tasks.splice(e(n.tasks,i,r)+1,0,i),qo(n.process)})}var u=kt(n,t);return u.push=function(n,t,r){o(u,n,t,r)},delete u.unshift,u}function At(n,t){return function(r,e){if(null==r)return r;if(!h(r))return n(r,e);for(var o=r.length,u=t?o:-1,i=Object(r);(t?u--:++u<o)&&e(i[u],u,i)!==!1;);return r}}function Lt(n,t){return"function"==typeof t&&jr(n)?F(n,t):au(n,Wn(t))}function xt(n,t){return t=p(t||s),jr(n)?n.length?void Lt(n,function(n){n(t)}):t():t(new TypeError("First argument to race must be an array of functions"))}function It(n,t,r,e){var o=fu.call(n).reverse();nt(o,t,r,e)}function Tt(n){return f(function(t,r){return t.push(a(function(n,t){if(n)r(null,{error:n});else{var e=null;1===t.length?e=t[0]:t.length>1&&(e=t),r(null,{value:e})}})),n.apply(this,t)})}function Mt(n,t,r,e){gt(n,t,function(n,t){r(n,function(n,r){n?t(n):t(null,!r)})},e)}function $t(n){return n.map(Tt)}function zt(n,t){return Ot(Ro,n,t)}function Ft(n,t,r){function e(n,t){if("object"==typeof t)n.times=+t.times||i,n.interval=+t.interval||c;else{if("number"!=typeof t&&"string"!=typeof t)throw new Error("Invalid arguments for async.retry");n.times=+t||i}}function o(n){return function(r){t(function(t,e){r(!t||n,{err:t,result:e})})}}function u(n){return function(t){setTimeout(function(){t(null)},n)}}var i=5,c=0,a={times:i,interval:c};if(arguments.length<3&&"function"==typeof n?(r=t||s,t=n):(e(a,n),r=r||s),"function"!=typeof t)throw new Error("Invalid arguments for async.retry");for(var f=[];a.times;){var l=!(a.times-=1);f.push(o(l)),!l&&a.interval>0&&f.push(u(a.interval))}zt(f,function(n,t){t=t[t.length-1],r(t.err,t.result)})}function Pt(n,t){return t||(t=n,n=null),f(function(r,e){function o(n){t.apply(null,r.concat([n]))}n?Ft(n,o,e):Ft(o,e)})}function Dt(n,t,r){function e(n,t){var r=n.criteria,e=t.criteria;return e>r?-1:r>e?1:0}Lr(n,function(n,r){t(n,function(t,e){return t?r(t):void r(null,{value:n,criteria:e})})},function(n,t){return n?r(n):void r(null,kn(t.sort(e),y("value")))})}function Bt(n,t,r){function e(){c||(u.apply(null,arguments),clearTimeout(i))}function o(){var t=n.name||"anonymous",e=new Error('Callback function "'+t+'" timed out.');e.code="ETIMEDOUT",r&&(e.info=r),c=!0,u(e)}var u,i,c=!1;return f(function(r,c){u=c,i=setTimeout(o,t),n.apply(null,r.concat(e))})}function Ut(n,t,r,e){for(var o=-1,u=du(mu((t-n)/(r||1)),0),i=Array(u);u--;)i[e?u:++o]=n,n+=r;return i}function Ct(n,t,r,e){return Ar(Ut(0,n,1),t,r,e)}function qt(n,t,r,e){3===arguments.length&&(e=r,r=t,t=jr(n)?[]:{}),No(n,function(n,e,o){r(t,n,e,o)},function(n){e(n,t)})}function Rt(n){return function(){return(n.unmemoized||n).apply(null,arguments)}}function Wt(n,t,r){return st(function(){return!n.apply(this,arguments)},t,r)}function Nt(n,t){function r(o){if(e===n.length)return t.apply(null,[null].concat(o));var u=x(a(function(n,e){return n?t.apply(null,[n].concat(e)):void r(e)}));o.push(u);var i=n[e++];i.apply(null,o)}if(t=p(t||s),!jr(n))return t(new Error("First argument to waterfall must be an array of functions"));if(!n.length)return t();var e=0;r([])}var Vt="[object Function]",Qt="[object GeneratorFunction]",Gt=Object.prototype,Ht=Gt.toString,Jt="[object Symbol]",Kt=Object.prototype,Xt=Kt.toString,Yt=NaN,Zt=/^\s+|\s+$/g,nr=/^[-+]0x[0-9a-f]+$/i,tr=/^0b[01]+$/i,rr=/^0o[0-7]+$/i,er=parseInt,or=1/0,ur=1.7976931348623157e308,ir="Expected a function",cr=Math.max,ar=y("length"),fr=9007199254740991,lr="function"==typeof Symbol&&Symbol.iterator,sr=Object.getPrototypeOf,pr=Object.prototype,yr=pr.hasOwnProperty,vr=Object.keys,hr="[object Arguments]",mr=Object.prototype,dr=mr.hasOwnProperty,gr=mr.toString,br=mr.propertyIsEnumerable,jr=Array.isArray,wr="[object String]",_r=Object.prototype,Or=_r.toString,Sr=9007199254740991,kr=/^(?:0|[1-9]\d*)$/,Er=Object.prototype,Ar=T(M),Lr=$(Ar,1/0),xr=l(Lr),Ir=$(Ar,1),Tr=l(Ir),Mr=a(function(n,t){return a(function(r){return n.apply(null,t.concat(r))})}),$r=P(),zr=Array.prototype,Fr=zr.splice,Pr=/[\\^$.*+?()[\]{}|]/g,Dr=/^\[object .+?Constructor\]$/,Br=Object.prototype,Ur=Function.prototype.toString,Cr=Br.hasOwnProperty,qr=RegExp("^"+Ur.call(Cr).replace(Pr,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),Rr=J(Object,"create"),Wr=Object.prototype;K.prototype=Rr?Rr(null):Wr;var Nr={"function":!0,object:!0},Vr=Nr[typeof n]&&n&&!n.nodeType?n:void 0,Qr=Nr[typeof module]&&module&&!module.nodeType?module:void 0,Gr=X(Vr&&Qr&&"object"==typeof global&&global),Hr=X(Nr[typeof self]&&self),Jr=X(Nr[typeof window]&&window),Kr=X(Nr[typeof this]&&this),Xr=Gr||Jr!==(Kr&&Kr.window)&&Jr||Hr||Kr||Function("return this")(),Yr=J(Xr,"Map"),Zr=Object.prototype,ne=Zr.hasOwnProperty,te="__lodash_hash_undefined__",re=Object.prototype,ee=re.hasOwnProperty,oe="__lodash_hash_undefined__";ln.prototype.clear=Y,ln.prototype["delete"]=rn,ln.prototype.get=on,ln.prototype.has=un,ln.prototype.set=fn;var ue=200;pn.prototype.clear=B,pn.prototype["delete"]=R,pn.prototype.get=N,pn.prototype.has=Q,pn.prototype.set=sn;var ie=1,ce=2,ae=Xr.Symbol,fe=Xr.Uint8Array,le=1,se=2,pe="[object Boolean]",ye="[object Date]",ve="[object Error]",he="[object Map]",me="[object Number]",de="[object RegExp]",ge="[object Set]",be="[object String]",je="[object Symbol]",we="[object ArrayBuffer]",_e="[object DataView]",Oe=ae?ae.prototype:void 0,Se=Oe?Oe.valueOf:void 0,ke=2,Ee=J(Xr,"DataView"),Ae=J(Xr,"Promise"),Le=J(Xr,"Set"),xe=J(Xr,"WeakMap"),Ie="[object Map]",Te="[object Object]",Me="[object Promise]",$e="[object Set]",ze="[object WeakMap]",Fe="[object DataView]",Pe=Object.prototype,De=Function.prototype.toString,Be=Pe.toString,Ue=Ee?Ee+"":"",Ce=Yr?De.call(Yr):"",qe=Ae?De.call(Ae):"",Re=Le?De.call(Le):"",We=xe?De.call(xe):"";(Ee&&bn(new Ee(new ArrayBuffer(1)))!=Fe||Yr&&bn(new Yr)!=Ie||Ae&&bn(Ae.resolve())!=Me||Le&&bn(new Le)!=$e||xe&&bn(new xe)!=ze)&&(bn=function(n){var t=Be.call(n),r=t==Te?n.constructor:null,e="function"==typeof r?De.call(r):"";if(e)switch(e){case Ue:return Fe;case Ce:return Ie;case qe:return Me;case Re:return $e;case We:return ze}return t});var Ne=bn,Ve="[object Arguments]",Qe="[object Array]",Ge="[object Boolean]",He="[object Date]",Je="[object Error]",Ke="[object Function]",Xe="[object Map]",Ye="[object Number]",Ze="[object Object]",no="[object RegExp]",to="[object Set]",ro="[object String]",eo="[object WeakMap]",oo="[object ArrayBuffer]",uo="[object DataView]",io="[object Float32Array]",co="[object Float64Array]",ao="[object Int8Array]",fo="[object Int16Array]",lo="[object Int32Array]",so="[object Uint8Array]",po="[object Uint8ClampedArray]",yo="[object Uint16Array]",vo="[object Uint32Array]",ho={};ho[io]=ho[co]=ho[ao]=ho[fo]=ho[lo]=ho[so]=ho[po]=ho[yo]=ho[vo]=!0,ho[Ve]=ho[Qe]=ho[oo]=ho[Ge]=ho[uo]=ho[He]=ho[Je]=ho[Ke]=ho[Xe]=ho[Ye]=ho[Ze]=ho[no]=ho[to]=ho[ro]=ho[eo]=!1;var mo=Object.prototype,go=mo.toString,bo=2,jo="[object Arguments]",wo="[object Array]",_o="[object Object]",Oo=Object.prototype,So=Oo.hasOwnProperty,ko=1,Eo=2,Ao="Expected a function";In.Cache=ln;var Lo,xo=1/0,Io=ae?ae.prototype:void 0,To=Io?Io.toString:void 0,Mo=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]/g,$o=/\\(\\)?/g,zo=In(function(n){var t=[];return Tn(n).replace(Mo,function(n,r,e,o){t.push(e?o.replace($o,"$1"):r||n)}),t}),Fo=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,Po=/^\w*$/,Do=1,Bo=2,Uo=/^function\s*[^\(]*\(\s*([^\)]*)\)/m,Co="function"==typeof setImmediate&&setImmediate;Lo=Co?Co:"object"==typeof process&&"function"==typeof process.nextTick?process.nextTick:function(n){setTimeout(n,0)};var qo=a(function(n,t){Lo(function(){n.apply(null,t)})}),Ro=$(Zn,1),Wo=Array.prototype.reverse,No=$(Zn,1/0),Vo=ot(et),Qo=ut(et),Go=a(function(n){var t=[null].concat(n);return f(function(n,r){return r.apply(this,t)})}),Ho=it(No,Cn,ct),Jo=it(Zn,Cn,ct),Ko=it(Ro,Cn,ct),Xo=at("dir"),Yo=$(ht,1/0),Zo=$(ht,1),nu=it(Zn,dt,dt),tu=$(nu,1/0),ru=$(nu,1),eu=T(gt),ou=$(eu,1/0),uu=$(eu,1),iu=at("log"),cu=$(St,1/0),au=At(D),fu=Array.prototype.slice,lu=T(Mt),su=$(lu,1/0),pu=$(lu,1),yu=it(Zn,Boolean,Cn),vu=$(yu,1/0),hu=$(yu,1),mu=Math.ceil,du=Math.max,gu=$(Ct,1/0),bu=$(Ct,1),ju={applyEach:xr,applyEachSeries:Tr,apply:Mr,asyncify:z,auto:Gn,autoInject:Kn,cargo:Yn,compose:rt,concat:Vo,concatSeries:Qo,constant:Go,detect:Ho,detectLimit:Jo,detectSeries:Ko,dir:Xo,doDuring:lt,doUntil:yt,doWhilst:pt,during:ft,each:Yo,eachLimit:ht,eachOf:No,eachOfLimit:Zn,eachOfSeries:Ro,eachSeries:Zo,ensureAsync:mt,every:tu,everyLimit:nu,everySeries:ru,filter:ou,filterLimit:eu,filterSeries:uu,forever:bt,iterator:jt,log:iu,map:Lr,mapLimit:Ar,mapSeries:Ir,memoize:_t,nextTick:qo,parallel:cu,parallelLimit:St,priorityQueue:Et,queue:kt,race:xt,reduce:nt,reduceRight:It,reflect:Tt,reflectAll:$t,reject:su,rejectLimit:lu,rejectSeries:pu,retry:Ft,retryable:Pt,seq:tt,series:zt,setImmediate:qo,some:vu,someLimit:yu,someSeries:hu,sortBy:Dt,timeout:Bt,times:gu,timesLimit:Ct,timesSeries:bu,transform:qt,unmemoize:Rt,until:Wt,waterfall:Nt,whilst:st,all:tu,any:vu,forEach:Yo,forEachSeries:Zo,forEachLimit:ht,forEachOf:No,forEachOfSeries:Ro,forEachOfLimit:Zn,inject:nt,foldl:nt,foldr:It,select:ou,selectLimit:eu,selectSeries:uu,wrapSync:z};n["default"]=ju,n.applyEach=xr,n.applyEachSeries=Tr,n.apply=Mr,n.asyncify=z,n.auto=Gn,n.autoInject=Kn,n.cargo=Yn,n.compose=rt,n.concat=Vo,n.concatSeries=Qo,n.constant=Go,n.detect=Ho,n.detectLimit=Jo,n.detectSeries=Ko,n.dir=Xo,n.doDuring=lt,n.doUntil=yt,n.doWhilst=pt,n.during=ft,n.each=Yo,n.eachLimit=ht,n.eachOf=No,n.eachOfLimit=Zn,n.eachOfSeries=Ro,n.eachSeries=Zo,n.ensureAsync=mt,n.every=tu,n.everyLimit=nu,n.everySeries=ru,n.filter=ou,n.filterLimit=eu,n.filterSeries=uu,n.forever=bt,n.iterator=jt,n.log=iu,n.map=Lr,n.mapLimit=Ar,n.mapSeries=Ir,n.memoize=_t,n.nextTick=qo,n.parallel=cu,n.parallelLimit=St,n.priorityQueue=Et,n.queue=kt,n.race=xt,n.reduce=nt,n.reduceRight=It,n.reflect=Tt,n.reflectAll=$t,n.reject=su,n.rejectLimit=lu,n.rejectSeries=pu,n.retry=Ft,n.retryable=Pt,n.seq=tt,n.series=zt,n.setImmediate=qo,n.some=vu,n.someLimit=yu,n.someSeries=hu,n.sortBy=Dt,n.timeout=Bt,n.times=gu,n.timesLimit=Ct,n.timesSeries=bu,n.transform=qt,n.unmemoize=Rt,n.until=Wt,n.waterfall=Nt,n.whilst=st,n.all=tu,n.allLimit=nu,n.allSeries=ru,n.any=vu,n.anyLimit=yu,n.anySeries=hu,n.find=Ho,n.findLimit=Jo,n.findSeries=Ko,n.forEach=Yo,n.forEachSeries=Zo,n.forEachLimit=ht,n.forEachOf=No,n.forEachOfSeries=Ro,n.forEachOfLimit=Zn,n.inject=nt,n.foldl=nt,n.foldr=It,n.select=ou,n.selectLimit=eu,n.selectSeries=uu,n.wrapSync=z}); +//# sourceMappingURL=async.min.map
\ No newline at end of file diff --git a/dist/async.min.map b/dist/async.min.map index c2e73cd..99f6924 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","toInteger","INFINITY","sign","MAX_INTEGER","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","baseProperty","key","object","isLength","MAX_SAFE_INTEGER","isArrayLike","getLength","getIterator","coll","iteratorSymbol","getPrototype","nativeGetPrototype","Object","baseHas","hasOwnProperty","baseKeys","nativeKeys","baseTimes","n","iteratee","result","isArrayLikeObject","isArguments","hasOwnProperty$1","propertyIsEnumerable","objectToString$2","argsTag","isString","isArray","objectToString$3","stringTag","indexKeys","String","isIndex","reIsUint","MAX_SAFE_INTEGER$1","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","v","doLimit","iterable","asyncify","e","then","message","arrayEach","createBaseFor","fromRight","keysFunc","props","baseForOwn","baseFor","stackClear","__data__","map","eq","assocIndexOf","assocDelete","lastIndex","splice","stackDelete","data","assocGet","stackGet","get","assocHas","stackHas","has","isHostObject","toString","isNative","reIsNative","funcToString","reIsHostCtor","getNative","Hash","checkGlobal","mapClear","hash","Map","string","hashHas","nativeCreate","hasOwnProperty$3","hashDelete","isKeyable","mapDelete","hashGet","HASH_UNDEFINED","hasOwnProperty$4","mapGet","mapHas","assocSet","hashSet","HASH_UNDEFINED$1","mapSet","set","MapCache","values","clear","entry","stackSet","LARGE_ARRAY_SIZE","Stack","arraySome","predicate","equalArrays","equalFunc","customizer","bitmask","stack","isPartial","PARTIAL_COMPARE_FLAG$2","isUnordered","UNORDERED_COMPARE_FLAG$1","arrLength","othLength","stacked","arrValue","othValue","compared","mapToArray","size","forEach","setToArray","equalByTag","dataViewTag","byteLength","byteOffset","buffer","arrayBufferTag","Uint8Array","boolTag","dateTag","errorTag","name","numberTag","regexpTag","stringTag$1","mapTag","convert","setTag","PARTIAL_COMPARE_FLAG$3","UNORDERED_COMPARE_FLAG$2","symbolTag$1","symbolValueOf","equalObjects","PARTIAL_COMPARE_FLAG$4","objProps","objLength","othProps","skipCtor","objValue","objCtor","othCtor","getTag","objectToString$4","isTypedArray","typedArrayTags","objectToString$5","baseIsEqualDeep","objIsArr","othIsArr","objTag","arrayTag","othTag","getTag$1","argsTag$1","objectTag","objIsObj","othIsObj","isSameTag","PARTIAL_COMPARE_FLAG$1","objIsWrapped","hasOwnProperty$5","othIsWrapped","objUnwrapped","othUnwrapped","baseIsEqual","baseIsMatch","source","matchData","noCustomizer","srcValue","UNORDERED_COMPARE_FLAG","PARTIAL_COMPARE_FLAG","isStrictComparable","arrayMap","baseToPairs","toPairs","getMatchData","baseMatches","memoize","resolver","FUNC_ERROR_TEXT$1","memoized","cache","Cache","symbolToString","INFINITY$1","baseCastPath","stringToPath","isKey","reIsPlainProp","reIsDeepProp","baseGet","path","defaultValue","baseHasIn","hasPath","hasFunc","hasIn","baseMatchesProperty","UNORDERED_COMPARE_FLAG$3","PARTIAL_COMPARE_FLAG$5","identity","basePropertyDeep","property","baseIteratee","forOwn","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","keys$$","numTasks","checkForDeadlocks","dep","dependencies","join","remainingDependencies","dependencyName","copyArray","parseParams","match","argsRegex","split","autoInject","newTasks","newTask","taskCb","newArgs","params","unshift","queue","worker","payload","_insert","q","pos","started","idle","setImmediate$1","drain","process","_next","workers","removed","workersList","unsaturated","saturated","empty","paused","kill","pause","resume","resumeCount","Math","min","w","cargo","eachOfLimit","reduce","memo","eachOfSeries","x","seq","newargs","nextargs","compose","reverse","concat$1","y","doParallel","eachOf","doSeries","_createTester","check","getResult","wrappedIteratee","_","_findGetResult","consoleFunc","console","error","during","truth","doDuring","calls","whilst","doWhilst","doUntil","_withoutIndex","eachLimit","ensureAsync","sync","innerArgs","notId","_filter","sort","a","b","forever","iterator$1","makeCallback","memoize$1","hasher","create","queues","l","unmemoized","_parallel","parallelLimit","queue$1","items","priorityQueue","_compareTasks","priority","_binarySearch","sequence","compare","beg","end","mid","createBaseEach","eachFunc","collection","baseEach","race","reduceRight","reversed","reflect","reflectCallback","cbArgs","reject$1","reflectAll","series","retry","times","parseTimes","acc","t","DEFAULT_TIMES","interval","DEFAULT_INTERVAL","retryAttempt","isFinalAttempt","seriesCallback","retryInterval","setTimeout","opts","attempts","retryable","sortBy","comparator","left","right","criteria","timeout","asyncFn","miliseconds","info","injectedCallback","timedOut","originalCallback","clearTimeout","timer","timeoutCallback","code","origCallback","baseRange","step","nativeMax$1","nativeCeil","timeLimit","count","mapLimit","transform","k","unmemoize","until","waterfall","nextTask","taskIndex","objectProto","objectProto$1","parseInt","max","Symbol","getPrototypeOf","objectProto$2","objectProto$3","objectProto$4","Infinity","applyEach","mapSeries","applyEachSeries","apply$1","callArgs","arrayProto","reRegExpChar","objectProto$7","Function","hasOwnProperty$2","RegExp","objectProto$6","objectTypes","function","freeExports","nodeType","freeModule","freeGlobal","freeSelf","self","freeWindow","window","thisGlobal","root","objectProto$8","objectProto$9","Symbol$1","symbolProto","DataView","Promise","Set","WeakMap","mapTag$1","objectTag$1","promiseTag","setTag$1","weakMapTag","dataViewTag$1","objectProto$11","funcToString$1","dataViewCtorString","mapCtorString","promiseCtorString","setCtorString","weakMapCtorString","ArrayBuffer","resolve","ctorString","argsTag$2","arrayTag$1","boolTag$1","dateTag$1","errorTag$1","funcTag$1","mapTag$2","numberTag$1","objectTag$2","regexpTag$1","setTag$2","stringTag$2","weakMapTag$1","arrayBufferTag$1","dataViewTag$2","float32Tag","float64Tag","int8Tag","int16Tag","int32Tag","uint8Tag","uint8ClampedTag","uint16Tag","uint32Tag","objectProto$12","objectProto$10","_defer","symbolProto$1","rePropName","reEscapeChar","number","quote","_setImmediate","setImmediate","nextTick","concatSeries","constant","ignoredArgs","detect","detectLimit","detectSeries","dir","each","eachSeries","everyLimit","every","everySeries","filterLimit","filter","filterSeries","log","parallel","rejectLimit","reject","rejectSeries","someLimit","Boolean","some","someSeries","ceil","timesSeries","timesLimit","all","any","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,SAAUL,GAAW,YAYzB,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,GA2B7B,QAASG,GAASC,GAChB,GAAIC,SAAcD,EAClB,SAASA,IAAkB,UAARC,GAA4B,YAARA,GAgCzC,QAASC,GAAWF,GAIlB,GAAIG,GAAMJ,EAASC,GAASI,GAAeN,KAAKE,GAAS,EACzD,OAAOG,IAAOE,IAAWF,GAAOG,GA2BlC,QAASC,GAAaP,GACpB,QAASA,GAAyB,gBAATA,GAiC3B,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,KAAVA,EAAeA,GAASA,CAEj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UAAYrB,GACpBrnB,EAAQ2oB,KAAO1C,GACfjmB,EAAQ4oB,UAAY1C,GACpBlmB,EAAQ6oB,WAAa1C,GACrBnmB,EAAQ6N,QAAUwY,GAClBrmB,EAAQ2nB,cAAgBrB,GACxBtmB,EAAQ4nB,aAAetN,GACvBta,EAAQ6nB,UAAY1O,GACpBnZ,EAAQ8nB,gBAAkBrP,GAC1BzY,EAAQ+nB,eAAiBzP,GACzBtY,EAAQgoB,OAASzP,GACjBvY,EAAQioB,MAAQ1P,GAChBvY,EAAQkoB,MAAQxL,GAChB1c,EAAQmoB,OAASxB,GACjB3mB,EAAQooB,YAAc1B,GACtB1mB,EAAQqoB,aAAezB,GACvB5mB,EAAQsoB,SAAW3f"}
\ 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","toInteger","INFINITY","sign","MAX_INTEGER","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","result","isArrayLikeObject","isArguments","hasOwnProperty$1","propertyIsEnumerable","objectToString$2","argsTag","isString","isArray","objectToString$3","stringTag","indexKeys","String","isIndex","reIsUint","MAX_SAFE_INTEGER$1","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","v","doLimit","iterable","asyncify","e","then","message","arrayEach","createBaseFor","fromRight","keysFunc","props","baseForOwn","baseFor","stackClear","__data__","map","eq","assocIndexOf","assocDelete","lastIndex","splice","stackDelete","data","assocGet","stackGet","get","assocHas","stackHas","has","isHostObject","toString","isNative","reIsNative","funcToString","reIsHostCtor","getNative","Hash","checkGlobal","mapClear","hash","Map","string","hashHas","nativeCreate","hasOwnProperty$3","hashDelete","isKeyable","mapDelete","hashGet","HASH_UNDEFINED","hasOwnProperty$4","mapGet","mapHas","assocSet","hashSet","HASH_UNDEFINED$1","mapSet","set","MapCache","values","clear","entry","stackSet","LARGE_ARRAY_SIZE","Stack","arraySome","predicate","equalArrays","equalFunc","customizer","bitmask","stack","isPartial","PARTIAL_COMPARE_FLAG$2","isUnordered","UNORDERED_COMPARE_FLAG$1","arrLength","othLength","stacked","arrValue","othValue","compared","mapToArray","size","forEach","setToArray","equalByTag","dataViewTag","byteLength","byteOffset","buffer","arrayBufferTag","Uint8Array","boolTag","dateTag","errorTag","name","numberTag","regexpTag","stringTag$1","mapTag","convert","setTag","PARTIAL_COMPARE_FLAG$3","UNORDERED_COMPARE_FLAG$2","symbolTag$1","symbolValueOf","equalObjects","PARTIAL_COMPARE_FLAG$4","objProps","objLength","othProps","skipCtor","objValue","objCtor","othCtor","getTag","objectToString$4","isTypedArray","typedArrayTags","objectToString$5","baseIsEqualDeep","objIsArr","othIsArr","objTag","arrayTag","othTag","getTag$1","argsTag$1","objectTag","objIsObj","othIsObj","isSameTag","PARTIAL_COMPARE_FLAG$1","objIsWrapped","hasOwnProperty$5","othIsWrapped","objUnwrapped","othUnwrapped","baseIsEqual","baseIsMatch","source","matchData","noCustomizer","srcValue","UNORDERED_COMPARE_FLAG","PARTIAL_COMPARE_FLAG","isStrictComparable","arrayMap","baseToPairs","toPairs","getMatchData","baseMatches","memoize","resolver","FUNC_ERROR_TEXT$1","memoized","cache","Cache","symbolToString","INFINITY$1","baseCastPath","stringToPath","isKey","reIsPlainProp","reIsDeepProp","baseGet","path","defaultValue","baseHasIn","hasPath","hasFunc","hasIn","baseMatchesProperty","UNORDERED_COMPARE_FLAG$3","PARTIAL_COMPARE_FLAG$5","identity","basePropertyDeep","property","baseIteratee","forOwn","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","counter","readyToCheck","getDependents","dependent","uncheckedDependencies","numTasks","keys$$","dependencies","remainingDependencies","dependencyName","join","copyArray","parseParams","match","argsRegex","split","autoInject","newTasks","newTask","taskCb","newArgs","params","queue","worker","payload","_insert","q","pos","started","idle","setImmediate$1","drain","unshift","process","_next","workers","removed","workersList","unsaturated","saturated","empty","paused","kill","pause","resume","resumeCount","Math","min","w","cargo","eachOfLimit","reduce","memo","eachOfSeries","x","seq","newargs","nextargs","compose","reverse","concat$1","y","doParallel","eachOf","doSeries","_createTester","check","getResult","wrappedIteratee","_","_findGetResult","consoleFunc","console","error","during","truth","doDuring","calls","whilst","doWhilst","doUntil","_withoutIndex","eachLimit","ensureAsync","sync","innerArgs","notId","_filter","sort","a","b","forever","iterator$1","makeCallback","memoize$1","hasher","create","queues","l","unmemoized","_parallel","parallelLimit","queue$1","items","priorityQueue","_compareTasks","priority","_binarySearch","sequence","compare","beg","end","mid","createBaseEach","eachFunc","collection","baseEach","race","reduceRight","reversed","reflect","reflectCallback","cbArgs","reject$1","reflectAll","series","retry","times","parseTimes","acc","t","DEFAULT_TIMES","interval","DEFAULT_INTERVAL","retryAttempt","isFinalAttempt","seriesCallback","retryInterval","setTimeout","opts","attempts","retryable","sortBy","comparator","left","right","criteria","timeout","asyncFn","miliseconds","info","injectedCallback","timedOut","originalCallback","clearTimeout","timer","timeoutCallback","code","origCallback","baseRange","step","nativeMax$1","nativeCeil","timeLimit","count","mapLimit","transform","k","unmemoize","until","waterfall","nextTask","taskIndex","objectProto","objectProto$1","parseInt","max","Symbol","getPrototypeOf","objectProto$2","objectProto$3","objectProto$4","Infinity","applyEach","mapSeries","applyEachSeries","apply$1","callArgs","arrayProto","reRegExpChar","objectProto$7","Function","hasOwnProperty$2","RegExp","objectProto$6","objectTypes","function","freeExports","nodeType","freeModule","freeGlobal","freeSelf","self","freeWindow","window","thisGlobal","root","objectProto$8","objectProto$9","Symbol$1","symbolProto","DataView","Promise","Set","WeakMap","mapTag$1","objectTag$1","promiseTag","setTag$1","weakMapTag","dataViewTag$1","objectProto$11","funcToString$1","dataViewCtorString","mapCtorString","promiseCtorString","setCtorString","weakMapCtorString","ArrayBuffer","resolve","ctorString","argsTag$2","arrayTag$1","boolTag$1","dateTag$1","errorTag$1","funcTag$1","mapTag$2","numberTag$1","objectTag$2","regexpTag$1","setTag$2","stringTag$2","weakMapTag$1","arrayBufferTag$1","dataViewTag$2","float32Tag","float64Tag","int8Tag","int16Tag","int32Tag","uint8Tag","uint8ClampedTag","uint16Tag","uint32Tag","objectProto$12","objectProto$10","_defer","symbolProto$1","rePropName","reEscapeChar","number","quote","_setImmediate","setImmediate","nextTick","concatSeries","constant","ignoredArgs","detect","detectLimit","detectSeries","dir","each","eachSeries","everyLimit","every","everySeries","filterLimit","filter","filterSeries","log","parallel","rejectLimit","reject","rejectSeries","someLimit","Boolean","some","someSeries","ceil","timesSeries","timesLimit","all","any","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,SAAUL,GAAW,YAYzB,SAASM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ooB,gBAAkBrP,GAC1B/Y,EAAQqoB,eAAiBzP,GACzB5Y,EAAQsoB,OAASzP,GACjB7Y,EAAQuoB,MAAQ1P,GAChB7Y,EAAQwoB,MAAQxL,GAChBhd,EAAQyoB,OAASxB,GACjBjnB,EAAQ0oB,YAAc1B,GACtBhnB,EAAQ2oB,aAAezB,GACvBlnB,EAAQ4oB,SAAWhgB"}
\ No newline at end of file diff --git a/lib/applyEachSeries.js b/lib/applyEachSeries.js index c56989b..675a029 100644 --- a/lib/applyEachSeries.js +++ b/lib/applyEachSeries.js @@ -9,7 +9,7 @@ import mapSeries from './mapSeries'; * @name applyEachSeries * @static * @memberOf async - * @see `async.applyEach` + * @see async.applyEach * @category Control Flow * @param {Array|Object} fns - A collection of asynchronous functions to all * call with the same arguments diff --git a/lib/auto.js b/lib/auto.js index 148cd5f..750a564 100644 --- a/lib/auto.js +++ b/lib/auto.js @@ -112,36 +112,34 @@ export default function (tasks, concurrency, callback) { 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 = {}; forOwn(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; - - checkForDeadlocks(); - - function checkForDeadlocks() { - var len = dependencies.length; - var dep; - while (len--) { - if (!(dep = tasks[dependencies[len]])) { - throw new Error('async.auto task `' + key + - '` has non-existent dependency in ' + - dependencies.join(', ')); - } - if (isArray(dep) && indexOf(dep, key, 0) >= 0) { - throw new Error('async.auto task `' + key + - '`Has cyclic dependencies'); - } - } + 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) { @@ -151,9 +149,9 @@ export default function (tasks, concurrency, callback) { }); }); + checkForDeadlocks(); processQueue(); - function enqueueTask(key, task) { readyTasks.push(function () { runTask(key, task); @@ -222,5 +220,36 @@ export default function (tasks, concurrency, callback) { } } + 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); + } + }); + } + + if (counter !== numTasks) { + throw new Error( + 'async.auto cannot execute tasks due to a recursive dependency' + ); + } + } + function getDependents(taskName) { + var result = []; + forOwn(tasks, function (task, key) { + if (isArray(task) && indexOf(task, taskName, 0) >= 0) { + result.push(key); + } + }); + return result; + } } diff --git a/lib/autoInject.js b/lib/autoInject.js index 5cd83a2..40a250d 100644 --- a/lib/autoInject.js +++ b/lib/autoInject.js @@ -12,7 +12,7 @@ function parseParams(func) { } /** - * A dependency-injected version of the [`auto`](#auto) function. Dependent + * A dependency-injected version of the {@link async.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 @@ -22,12 +22,12 @@ function parseParams(func) { * specified as named parameters after the initial error parameter. * * The autoInject function is purely syntactic sugar and its semantics are - * otherwise equivalent to [`auto`](#auto). + * otherwise equivalent to {@link async.auto}. * * @name autoInject * @static * @memberOf async - * @see `async.auto` + * @see async.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 @@ -107,7 +107,7 @@ export default function autoInject(tasks, callback) { params = clone(taskFn); taskFn = params.pop(); - newTasks[key] = params.concat(newTask); + newTasks[key] = params.concat(params.length > 0 ? newTask : taskFn); } else if (taskFn.length === 0) { throw new Error("autoInject task functions require explicit parameters."); } else if (taskFn.length === 1) { diff --git a/lib/cargo.js b/lib/cargo.js index faa4ab4..a2fe98e 100644 --- a/lib/cargo.js +++ b/lib/cargo.js @@ -4,7 +4,7 @@ import queue from './internal/queue'; /** * A cargo of tasks for the worker function to complete. Cargo inherits all of - * the same methods and event callbacks as [`queue`](#queue). + * the same methods and event callbacks as {@link async.queue}. * @typedef {Object} cargo * @property {Function} length - A function returning the number of items * waiting to be processed. Invoke with (). @@ -46,7 +46,7 @@ import queue from './internal/queue'; * @name cargo * @static * @memberOf async - * @see `async.queue` + * @see async.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, diff --git a/lib/concatSeries.js b/lib/concatSeries.js index 3fb89d2..73312dc 100644 --- a/lib/concatSeries.js +++ b/lib/concatSeries.js @@ -9,7 +9,7 @@ import doSeries from './internal/doSeries'; * @name concatSeries * @static * @memberOf async - * @see `async.concat` + * @see async.concat * @category Collection * @param {Array|Object} coll - A collection to iterate over. * @param {Function} iteratee - A function to apply to each item in `coll`. diff --git a/lib/detectLimit.js b/lib/detectLimit.js index ee9080b..20c8040 100644 --- a/lib/detectLimit.js +++ b/lib/detectLimit.js @@ -13,7 +13,7 @@ import findGetResult from './internal/findGetResult'; * @name detectLimit * @static * @memberOf async - * @see `async.detect` + * @see async.detect * @alias findLimit * @category Collection * @param {Array|Object} coll - A collection to iterate over. diff --git a/lib/detectSeries.js b/lib/detectSeries.js index 9c88bda..659d820 100644 --- a/lib/detectSeries.js +++ b/lib/detectSeries.js @@ -12,7 +12,7 @@ import findGetResult from './internal/findGetResult'; * @name detectSeries * @static * @memberOf async - * @see `async.detect` + * @see async.detect * @alias findSeries * @category Collection * @param {Array|Object} coll - A collection to iterate over. diff --git a/lib/doDuring.js b/lib/doDuring.js index 6833a78..76050ab 100644 --- a/lib/doDuring.js +++ b/lib/doDuring.js @@ -3,14 +3,14 @@ import during from './during'; /** - * The post-check version of [`during`](#during). To reflect the difference in + * The post-check version of {@link async.during}. To reflect the difference in * the order of operations, the arguments `test` and `fn` are switched. * - * Also a version of [`doWhilst`](#doWhilst) with asynchronous `test` function. + * Also a version of {@link async.doWhilst} with asynchronous `test` function. * @name doDuring * @static * @memberOf async - * @see `async.during` + * @see async.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 diff --git a/lib/doUntil.js b/lib/doUntil.js index e5c48c9..4e6bbc3 100644 --- a/lib/doUntil.js +++ b/lib/doUntil.js @@ -3,19 +3,19 @@ import doWhilst from './doWhilst'; /** - * Like [`doWhilst`](#doWhilst), except the `test` is inverted. Note the + * Like {@link async.doWhilst}, except the `test` is inverted. Note the * argument ordering differs from `until`. * * @name doUntil * @static * @memberOf async - * @see `async.doWhilst` + * @see async.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 before each - * execution of `fn`. Invoked with (). + * @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 diff --git a/lib/doWhilst.js b/lib/doWhilst.js index 54c8303..b38036b 100644 --- a/lib/doWhilst.js +++ b/lib/doWhilst.js @@ -3,7 +3,7 @@ import whilst from './whilst'; /** - * The post-check version of [`whilst`](#whilst). To reflect the difference in + * The post-check version of {@link async.whilst}. To reflect the difference in * the order of operations, the arguments `test` and `fn` are switched. * * `doWhilst` is to `whilst` as `do while` is to `while` in plain JavaScript. @@ -11,13 +11,14 @@ import whilst from './whilst'; * @name doWhilst * @static * @memberOf async - * @see `async.whilst` + * @see async.whilst * @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 - synchronous truth test to perform before each - * execution of `fn`. Invoked with (). + * @param {Function} test - synchronous truth test to perform after each + * execution of `fn`. Invoked with Invoked with the non-error callback results + * 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 and any arguments passed to the final `fn`'s diff --git a/lib/during.js b/lib/during.js index 7c3d10c..de3b1a1 100644 --- a/lib/during.js +++ b/lib/during.js @@ -4,7 +4,7 @@ import noop from 'lodash/noop'; import rest from 'lodash/rest'; /** - * Like [`whilst`](#whilst), except the `test` is an asynchronous function that + * Like {@link async.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. @@ -12,7 +12,7 @@ import rest from 'lodash/rest'; * @name during * @static * @memberOf async - * @see `async.whilst` + * @see async.whilst * @category Control Flow * @param {Function} test - asynchronous truth test to perform before each * execution of `fn`. Invoked with (callback). diff --git a/lib/eachLimit.js b/lib/eachLimit.js index 825c47e..415e6e8 100644 --- a/lib/eachLimit.js +++ b/lib/eachLimit.js @@ -9,7 +9,7 @@ import withoutIndex from './internal/withoutIndex'; * @name eachLimit * @static * @memberOf async - * @see `async.each` + * @see async.each * @alias forEachLimit * @category Collection * @param {Array|Object} coll - A colleciton to iterate over. diff --git a/lib/eachOfLimit.js b/lib/eachOfLimit.js index fe0f088..753dbc0 100644 --- a/lib/eachOfLimit.js +++ b/lib/eachOfLimit.js @@ -9,7 +9,7 @@ import _eachOfLimit from './internal/eachOfLimit'; * @name eachOfLimit * @static * @memberOf async - * @see `async.eachOf` + * @see async.eachOf * @alias forEachOfLimit * @category Collection * @param {Array|Object} coll - A collection to iterate over. diff --git a/lib/eachOfSeries.js b/lib/eachOfSeries.js index f4cd1a3..0718805 100644 --- a/lib/eachOfSeries.js +++ b/lib/eachOfSeries.js @@ -9,7 +9,7 @@ import doLimit from './internal/doLimit'; * @name eachOfSeries * @static * @memberOf async - * @see `async.eachOf` + * @see async.eachOf * @alias forEachOfSeries * @category Collection * @param {Array|Object} coll - A collection to iterate over. diff --git a/lib/eachSeries.js b/lib/eachSeries.js index 7488955..470c34c 100644 --- a/lib/eachSeries.js +++ b/lib/eachSeries.js @@ -9,7 +9,7 @@ import doLimit from './internal/doLimit'; * @name eachSeries * @static * @memberOf async - * @see `async.each` + * @see async.each * @alias forEachSeries * @category Collection * @param {Array|Object} coll - A collection to iterate over. diff --git a/lib/everyLimit.js b/lib/everyLimit.js index e9a690d..6470261 100644 --- a/lib/everyLimit.js +++ b/lib/everyLimit.js @@ -10,7 +10,7 @@ import notId from './internal/notId'; * @name everyLimit * @static * @memberOf async - * @see `async.every` + * @see async.every * @alias allLimit * @category Collection * @param {Array|Object} coll - A collection to iterate over. diff --git a/lib/everySeries.js b/lib/everySeries.js index 636a088..aca6cec 100644 --- a/lib/everySeries.js +++ b/lib/everySeries.js @@ -9,7 +9,7 @@ import doLimit from './internal/doLimit'; * @name everySeries * @static * @memberOf async - * @see `async.every` + * @see async.every * @alias allSeries * @category Collection * @param {Array|Object} coll - A collection to iterate over. diff --git a/lib/filterLimit.js b/lib/filterLimit.js index 34be228..414ea4d 100644 --- a/lib/filterLimit.js +++ b/lib/filterLimit.js @@ -10,7 +10,7 @@ import doParallelLimit from './internal/doParallelLimit'; * @name filterLimit * @static * @memberOf async - * @see `async.filter` + * @see async.filter * @alias selectLimit * @category Collection * @param {Array|Object} coll - A collection to iterate over. diff --git a/lib/filterSeries.js b/lib/filterSeries.js index 44c7542..97c3907 100644 --- a/lib/filterSeries.js +++ b/lib/filterSeries.js @@ -9,7 +9,7 @@ import doLimit from './internal/doLimit'; * @name filterSeries * @static * @memberOf async - * @see `async.filter` + * @see async.filter * @alias selectSeries * @category Collection * @param {Array|Object} coll - A collection to iterate over. diff --git a/lib/internal/once.js b/lib/internal/once.js index 11678dc..f601185 100644 --- a/lib/internal/once.js +++ b/lib/internal/once.js @@ -1,7 +1,8 @@ export default function once(fn) { return function () { if (fn === null) return; - fn.apply(this, arguments); + var callFn = fn; fn = null; + callFn.apply(this, arguments); }; } diff --git a/lib/internal/onlyOnce.js b/lib/internal/onlyOnce.js index f4241c8..355ff41 100644 --- a/lib/internal/onlyOnce.js +++ b/lib/internal/onlyOnce.js @@ -3,7 +3,8 @@ export default function onlyOnce(fn) { return function() { if (fn === null) throw new Error("Callback was already called."); - fn.apply(this, arguments); + var callFn = fn; fn = null; + callFn.apply(this, arguments); }; } diff --git a/lib/mapLimit.js b/lib/mapLimit.js index 8512885..916b206 100644 --- a/lib/mapLimit.js +++ b/lib/mapLimit.js @@ -9,7 +9,7 @@ import map from './internal/map'; * @name mapLimit * @static * @memberOf async - * @see `async.map` + * @see async.map * @category Collection * @param {Array|Object} coll - A collection to iterate over. * @param {number} limit - The maximum number of async operations at a time. diff --git a/lib/mapSeries.js b/lib/mapSeries.js index d5a9af2..efa2818 100644 --- a/lib/mapSeries.js +++ b/lib/mapSeries.js @@ -9,7 +9,7 @@ import doLimit from './internal/doLimit'; * @name mapSeries * @static * @memberOf async - * @see `async.map` + * @see async.map * @category Collection * @param {Array|Object} coll - A collection to iterate over. * @param {Function} iteratee - A function to apply to each item in `coll`. diff --git a/lib/parallel.js b/lib/parallel.js index 8856fb1..eb910ce 100644 --- a/lib/parallel.js +++ b/lib/parallel.js @@ -19,7 +19,7 @@ import doLimit from './internal/doLimit'; * 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 [`parallel`](#parallel). + * results from {@link async.parallel}. * * @name parallel * @static diff --git a/lib/parallelLimit.js b/lib/parallelLimit.js index 188624c..5b62150 100644 --- a/lib/parallelLimit.js +++ b/lib/parallelLimit.js @@ -10,7 +10,7 @@ import parallel from './internal/parallel'; * @name parallel * @static * @memberOf async - * @see `async.parallel` + * @see async.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 diff --git a/lib/priorityQueue.js b/lib/priorityQueue.js index a33f2f5..0d8fd93 100644 --- a/lib/priorityQueue.js +++ b/lib/priorityQueue.js @@ -9,13 +9,13 @@ import setImmediate from './setImmediate'; import queue from './queue'; /** - * The same as [`queue`](#queue) only tasks are assigned a priority and + * The same as {@link async.queue} only tasks are assigned a priority and * completed in ascending priority order. * * @name priorityQueue * @static * @memberOf async - * @see `async.queue` + * @see async.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 @@ -73,12 +73,6 @@ export default function(worker, concurrency) { q.tasks.splice(_binarySearch(q.tasks, item, _compareTasks) + 1, 0, item); - if (q.tasks.length === q.concurrency) { - q.saturated(); - } - if (q.tasks.length <= (q.concurrency - q.buffer) ) { - q.unsaturated(); - } setImmediate(q.process); }); } diff --git a/lib/reduceRight.js b/lib/reduceRight.js index c0135a8..033b9da 100644 --- a/lib/reduceRight.js +++ b/lib/reduceRight.js @@ -10,7 +10,7 @@ var slice = Array.prototype.slice; * @name reduceRight * @static * @memberOf async - * @see `async.reduce` + * @see async.reduce * @alias foldr * @category Collection * @param {Array|Object} coll - A collection to iterate over. diff --git a/lib/reflectAll.js b/lib/reflectAll.js index 2a0f197..b6884cc 100644 --- a/lib/reflectAll.js +++ b/lib/reflectAll.js @@ -8,7 +8,7 @@ import reflect from './reflect'; * @name reflectAll * @static * @memberOf async - * @see `async.reflect` + * @see async.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 diff --git a/lib/reject.js b/lib/reject.js index b96321a..f7f6f10 100644 --- a/lib/reject.js +++ b/lib/reject.js @@ -9,7 +9,7 @@ import doLimit from './internal/doLimit'; * @name reject * @static * @memberOf async - * @see `async.filter` + * @see async.filter * @category Collection * @param {Array|Object} coll - A collection to iterate over. * @param {Function} iteratee - A truth test to apply to each item in `coll`. diff --git a/lib/rejectLimit.js b/lib/rejectLimit.js index 67f34cb..9b3fbd3 100644 --- a/lib/rejectLimit.js +++ b/lib/rejectLimit.js @@ -10,7 +10,7 @@ import doParallelLimit from './internal/doParallelLimit'; * @name rejectLimit * @static * @memberOf async - * @see `async.reject` + * @see async.reject * @category Collection * @param {Array|Object} coll - A collection to iterate over. * @param {number} limit - The maximum number of async operations at a time. diff --git a/lib/rejectSeries.js b/lib/rejectSeries.js index 858f39a..1732eca 100644 --- a/lib/rejectSeries.js +++ b/lib/rejectSeries.js @@ -9,7 +9,7 @@ import doLimit from './internal/doLimit'; * @name rejectSeries * @static * @memberOf async - * @see `async.reject` + * @see async.reject * @category Collection * @param {Array|Object} coll - A collection to iterate over. * @param {Function} iteratee - A truth test to apply to each item in `coll`. diff --git a/lib/retryable.js b/lib/retryable.js index 58f56f4..b9c0fbb 100644 --- a/lib/retryable.js +++ b/lib/retryable.js @@ -8,7 +8,7 @@ import initialParams from './internal/initialParams'; * @name retryable * @static * @memberOf async - * @see `async.retry` + * @see async.retry * @category Control Flow * @param {Object|number} [opts = {times: 5, interval: 0}| 5] - optional * options, exactly the same as from `retry` @@ -7,14 +7,14 @@ import reduce from './reduce'; /** * 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`](#compose) with the arguments reversed. + * {@link async.compose} with the arguments reversed. * * Each function is executed with the `this` binding of the composed function. * * @name seq * @static * @memberOf async - * @see `async.compose` + * @see async.compose * @category Control Flow * @param {...Function} functions - the asynchronous functions to compose * @example diff --git a/lib/series.js b/lib/series.js index b0cc6bf..17392cd 100644 --- a/lib/series.js +++ b/lib/series.js @@ -13,7 +13,7 @@ import eachOfSeries from './eachOfSeries'; * 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 [`series`](#series). + * 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) diff --git a/lib/someLimit.js b/lib/someLimit.js index a70e194..521c116 100644 --- a/lib/someLimit.js +++ b/lib/someLimit.js @@ -10,7 +10,7 @@ import identity from 'lodash/identity'; * @name someLimit * @static * @memberOf async - * @see `async.some` + * @see async.some * @alias anyLimit * @category Collection * @param {Array|Object} coll - A collection to iterate over. diff --git a/lib/someSeries.js b/lib/someSeries.js index 5637556..41ca733 100644 --- a/lib/someSeries.js +++ b/lib/someSeries.js @@ -9,7 +9,7 @@ import doLimit from './internal/doLimit'; * @name someSeries * @static * @memberOf async - * @see `async.some` + * @see async.some * @alias anySeries * @category Collection * @param {Array|Object} coll - A collection to iterate over. diff --git a/lib/times.js b/lib/times.js index ef92779..8b4bb2b 100644 --- a/lib/times.js +++ b/lib/times.js @@ -5,17 +5,17 @@ import doLimit from './internal/doLimit'; /** * Calls the `iteratee` function `n` times, and accumulates results in the same - * manner you would use with [`map`](#map). + * manner you would use with {@link async.map}. * * @name times * @static * @memberOf async - * @see `async.map` + * @see async.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 [`map`](#map). + * @param {Function} callback - see {@link async.map}. * @example * * // Pretend this is some complicated async factory diff --git a/lib/timesLimit.js b/lib/timesLimit.js index abec4f8..a6ac311 100644 --- a/lib/timesLimit.js +++ b/lib/timesLimit.js @@ -4,19 +4,19 @@ import mapLimit from './mapLimit'; import range from 'lodash/_baseRange'; /** -* The same as `times` but runs a maximum of `limit` async operations at a +* The same as {@link times} but runs a maximum of `limit` async operations at a * time. * * @name timesLimit * @static * @memberOf async - * @see `async.times` + * @see async.times * @category Control Flow * @param {number} n - 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 [`map`](#map). + * @param {Function} callback - see {@link async.map}. */ export default function timeLimit(count, limit, iteratee, cb) { return mapLimit(range(0, count, 1), limit, iteratee, cb); diff --git a/lib/timesSeries.js b/lib/timesSeries.js index e68d1ed..a610b11 100644 --- a/lib/timesSeries.js +++ b/lib/timesSeries.js @@ -4,16 +4,16 @@ import timesLimit from './timesLimit'; import doLimit from './internal/doLimit'; /** - * The same as `times` but runs only a single async operation at a time. + * The same as {@link async.times} but runs only a single async operation at a time. * * @name timesSeries * @static * @memberOf async - * @see `async.times` + * @see async.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 [`map`](#map). + * @param {Function} callback - see {@link async.map}. */ export default doLimit(timesLimit, 1); diff --git a/lib/transform.js b/lib/transform.js index 819cd5d..cdad526 100644 --- a/lib/transform.js +++ b/lib/transform.js @@ -4,16 +4,60 @@ import isArray from 'lodash/isArray'; import eachOf from './eachOf'; -export default function transform (arr, memo, iteratee, callback) { +/** + * 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 async + * @category Collection + * @param {Array|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} + * }) + */ +export default function transform (arr, acc, iteratee, callback) { if (arguments.length === 3) { callback = iteratee; - iteratee = memo; - memo = isArray(arr) ? [] : {}; + iteratee = acc; + acc = isArray(arr) ? [] : {}; } eachOf(arr, function(v, k, cb) { - iteratee(memo, v, k, cb); + iteratee(acc, v, k, cb); }, function(err) { - callback(err, memo); + callback(err, acc); }); } diff --git a/lib/unmemoize.js b/lib/unmemoize.js index e7f0941..6b7a6f7 100644 --- a/lib/unmemoize.js +++ b/lib/unmemoize.js @@ -1,13 +1,13 @@ 'use strict'; /** - * Undoes a [`memoize`](#memoize)d function, reverting it to the original, + * Undoes a {@link async.memoize}d function, reverting it to the original, * unmemoized form. Handy for testing. * * @name unmemoize * @static * @memberOf async - * @see `async.memoize` + * @see async.memoize * @category Util * @param {Function} fn - the memoized function */ diff --git a/lib/until.js b/lib/until.js index 0c5a1aa..f5e6efa 100644 --- a/lib/until.js +++ b/lib/until.js @@ -7,12 +7,12 @@ import whilst from './whilst'; * 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`](#whilst). + * The inverse of {@link async.whilst}. * * @name until * @static * @memberOf async - * @see `async.whilst` + * @see async.whilst * @category Control Flow * @param {Function} test - synchronous truth test to perform before each * execution of `fn`. Invoked with (). diff --git a/mocha_test/apply.js b/mocha_test/apply.js new file mode 100644 index 0000000..18e5d12 --- /dev/null +++ b/mocha_test/apply.js @@ -0,0 +1,21 @@ +var async = require('../lib'); +var expect = require('chai').expect; + +describe('concat', function() { + it('apply', function(done) { + var fn = function(){ + expect(Array.prototype.slice.call(arguments)).to.eql([1,2,3,4]); + }; + async.apply(fn, 1, 2, 3, 4)(); + async.apply(fn, 1, 2, 3)(4); + async.apply(fn, 1, 2)(3, 4); + async.apply(fn, 1)(2, 3, 4); + async.apply(fn)(1, 2, 3, 4); + expect( + async.apply(function(name){return 'hello ' + name;}, 'world')() + ).to.equal( + 'hello world' + ); + done(); + }); +}); diff --git a/mocha_test/asyncify.js b/mocha_test/asyncify.js new file mode 100644 index 0000000..507cd1a --- /dev/null +++ b/mocha_test/asyncify.js @@ -0,0 +1,117 @@ +var async = require('../lib'); +var assert = require('assert'); +var expect = require('chai').expect; +var isBrowser = require('./support/is_browser'); + +describe('asyncify', function(done){ + + it('asyncify', function(done) { + var parse = async.asyncify(JSON.parse); + parse("{\"a\":1}", function (err, result) { + assert(!err); + expect(result.a).to.equal(1); + done(); + }); + }); + + it('asyncify null', function(done) { + var parse = async.asyncify(function() { + return null; + }); + parse("{\"a\":1}", function (err, result) { + assert(!err); + expect(result).to.equal(null); + done(); + }); + }); + + it('variable numbers of arguments', function(done) { + async.asyncify(function (x, y, z) { + return arguments; + })(1, 2, 3, function (err, result) { + expect(result.length).to.equal(3); + expect(result[0]).to.equal(1); + expect(result[1]).to.equal(2); + expect(result[2]).to.equal(3); + done(); + }); + }); + + it('catch errors', function(done) { + async.asyncify(function () { + throw new Error("foo"); + })(function (err) { + assert(err); + expect(err.message).to.equal("foo"); + done(); + }); + }); + + it('dont catch errors in the callback', function(done) { + try { + async.asyncify(function () {})(function (err) { + if (err) { + return done(new Error("should not get an error here")); + } + throw new Error("callback error"); + }); + } catch (err) { + expect(err.message).to.equal("callback error"); + done(); + } + }); + + describe('promisified', function() { + if (isBrowser()) { + // node only tests + return; + } + + var names = [ + 'native-promise-only', + 'bluebird', + 'es6-promise', + 'rsvp' + ]; + + names.forEach(function(name) { + describe(name, function() { + + var Promise = require(name); + if (typeof Promise.Promise === 'function') { + Promise = Promise.Promise; + } + + it('resolve', function(done) { + var promisified = function(argument) { + return new Promise(function (resolve) { + setTimeout(function () { + resolve(argument + " resolved"); + }, 15); + }); + }; + async.asyncify(promisified)("argument", function (err, value) { + if (err) { + return done(new Error("should not get an error here")); + } + expect(value).to.equal("argument resolved"); + done(); + }); + }); + + it('reject', function(done) { + var promisified = function(argument) { + return new Promise(function (resolve, reject) { + reject(argument + " rejected"); + }); + }; + async.asyncify(promisified)("argument", function (err) { + assert(err); + expect(err.message).to.equal("argument rejected"); + done(); + }); + }); + }); + }); + }); +}); diff --git a/mocha_test/auto.js b/mocha_test/auto.js index fb779ee..6d30815 100644 --- a/mocha_test/auto.js +++ b/mocha_test/auto.js @@ -305,6 +305,23 @@ describe('auto', function () { done(); }); + // Issue 1092 on github: https://github.com/caolan/async/issues/1092 + it('extended cycle detection', function(done) { + var task = function (name) { + return function (results, callback) { + callback(null, 'task ' + name); + }; + }; + expect(function () { + async.auto({ + a: ['c', task('a')], + b: ['a', task('b')], + c: ['b', task('c')] + }); + }).to.throw(); + done(); + }); + // Issue 988 on github: https://github.com/caolan/async/issues/988 it('auto stops running tasks on error', function(done) { async.auto({ @@ -349,6 +366,18 @@ describe('auto', function () { }).to.throw(); }); + it('should handle array tasks with just a function', function (done) { + async.auto({ + a: [function (cb) { + cb(null, 1); + }], + b: ["a", function (results, cb) { + expect(results.a).to.equal(1); + cb(); + }] + }, done); + }); + it("should avoid unncecessary deferrals", function (done) { var isSync = true; diff --git a/mocha_test/autoInject.js b/mocha_test/autoInject.js index b90125b..39c99a4 100644 --- a/mocha_test/autoInject.js +++ b/mocha_test/autoInject.js @@ -74,6 +74,18 @@ describe('autoInject', function () { }); }); + it('should handle array tasks with just a function', function (done) { + async.autoInject({ + a: [function (cb) { + cb(null, 1); + }], + b: ["a", function (a, cb) { + expect(a).to.equal(1); + cb(); + }] + }, done); + }); + var arrowSupport = true; try { /* jshint -W054 */ @@ -103,5 +115,4 @@ describe('autoInject', function () { )(); /* jshint +W061 */ } - }); diff --git a/mocha_test/concat.js b/mocha_test/concat.js new file mode 100644 index 0000000..389b2de --- /dev/null +++ b/mocha_test/concat.js @@ -0,0 +1,57 @@ +var async = require('../lib'); +var expect = require('chai').expect; +var assert = require('assert'); + +describe('concat', function() { + it('concat', function(done) { + var call_order = []; + var iteratee = function (x, cb) { + setTimeout(function(){ + call_order.push(x); + var r = []; + while (x > 0) { + r.push(x); + x--; + } + cb(null, r); + }, x*25); + }; + async.concat([1,3,2], iteratee, function(err, results){ + expect(results).to.eql([1,2,1,3,2,1]); + expect(call_order).to.eql([1,2,3]); + assert(err === null, err + " passed instead of 'null'"); + done(); + }); + }); + + it('concat error', function(done) { + var iteratee = function (x, cb) { + cb(new Error('test error')); + }; + async.concat([1,2,3], iteratee, function(err){ + assert(err); + done(); + }); + }); + + it('concatSeries', function(done) { + var call_order = []; + var iteratee = function (x, cb) { + setTimeout(function(){ + call_order.push(x); + var r = []; + while (x > 0) { + r.push(x); + x--; + } + cb(null, r); + }, x*25); + }; + async.concatSeries([1,3,2], iteratee, function(err, results){ + expect(results).to.eql([1,3,2,1,2,1]); + expect(call_order).to.eql([1,3,2]); + assert(err === null, err + " passed instead of 'null'"); + done(); + }); + }); +}); diff --git a/mocha_test/consoleFunctions.js b/mocha_test/consoleFunctions.js new file mode 100644 index 0000000..616ac1d --- /dev/null +++ b/mocha_test/consoleFunctions.js @@ -0,0 +1,71 @@ +var async = require('../lib'); +var expect = require('chai').expect; +var assert = require('assert'); + +describe('console functions', function() { + + var names = [ + 'log', + 'dir', + /* 'info' + 'warn' + 'error' */ + ]; + + // generates tests for console functions such as async.log + names.forEach(function(name) { + if (typeof console !== 'undefined') { + it(name, function(done) { + var fn = function(arg1, callback){ + expect(arg1).to.equal('one'); + setTimeout(function(){callback(null, 'test');}, 0); + }; + var fn_err = function(arg1, callback){ + expect(arg1).to.equal('one'); + setTimeout(function(){callback('error');}, 0); + }; + var _console_fn = console[name]; + var _error = console.error; + console[name] = function(val){ + expect(val).to.equal('test'); + expect(arguments.length).to.equal(1); + console.error = function(val){ + expect(val).to.equal('error'); + console[name] = _console_fn; + console.error = _error; + done(); + }; + async[name](fn_err, 'one'); + }; + async[name](fn, 'one'); + }); + + it(name + ' with multiple result params', function(done) { + var fn = function(callback){callback(null,'one','two','three');}; + var _console_fn = console[name]; + var called_with = []; + console[name] = function(x){ + called_with.push(x); + }; + async[name](fn); + expect(called_with).to.eql(['one','two','three']); + console[name] = _console_fn; + done(); + }); + } + + // browser-only test + if (typeof window !== 'undefined') { + it(name + ' without console.' + name, function(done) { + var _console = window.console; + window.console = undefined; + var fn = function(callback){callback(null, 'val');}; + var fn_err = function(callback){callback('error');}; + async[name](fn); + async[name](fn_err); + window.console = _console; + done(); + }); + } + }); +}); diff --git a/mocha_test/during.js b/mocha_test/during.js new file mode 100644 index 0000000..851acf1 --- /dev/null +++ b/mocha_test/during.js @@ -0,0 +1,97 @@ +var async = require('../lib'); +var expect = require('chai').expect; +var assert = require('assert'); + +describe('during', function() { + + it('during', function(done) { + var call_order = []; + + var count = 0; + async.during( + function (cb) { + call_order.push(['test', count]); + cb(null, count < 5); + }, + function (cb) { + call_order.push(['iteratee', count]); + count++; + cb(); + }, + function (err) { + assert(err === null, err + " passed instead of 'null'"); + expect(call_order).to.eql([ + ['test', 0], + ['iteratee', 0], ['test', 1], + ['iteratee', 1], ['test', 2], + ['iteratee', 2], ['test', 3], + ['iteratee', 3], ['test', 4], + ['iteratee', 4], ['test', 5], + ]); + expect(count).to.equal(5); + done(); + } + ); + }); + + it('doDuring', function(done) { + var call_order = []; + + var count = 0; + async.doDuring( + function (cb) { + call_order.push(['iteratee', count]); + count++; + cb(); + }, + function (cb) { + call_order.push(['test', count]); + cb(null, count < 5); + }, + function (err) { + assert(err === null, err + " passed instead of 'null'"); + expect(call_order).to.eql([ + ['iteratee', 0], ['test', 1], + ['iteratee', 1], ['test', 2], + ['iteratee', 2], ['test', 3], + ['iteratee', 3], ['test', 4], + ['iteratee', 4], ['test', 5], + ]); + expect(count).to.equal(5); + done(); + } + ); + }); + + it('doDuring - error test', function(done) { + var error = new Error('asdas'); + + async.doDuring( + function (cb) { + cb(error); + }, + function () {}, + function (err) { + expect(err).to.equal(error); + done(); + } + ); + }); + + it('doDuring - error iteratee', function(done) { + var error = new Error('asdas'); + + async.doDuring( + function (cb) { + cb(null); + }, + function (cb) { + cb(error); + }, + function (err) { + expect(err).to.equal(error); + done(); + } + ); + }); +}); diff --git a/mocha_test/each.js b/mocha_test/each.js new file mode 100644 index 0000000..014e9df --- /dev/null +++ b/mocha_test/each.js @@ -0,0 +1,283 @@ +var async = require('../lib'); +var expect = require('chai').expect; +var assert = require('assert'); + +describe("each", function() { + + function eachIteratee(args, x, callback) { + setTimeout(function(){ + args.push(x); + callback(); + }, x*25); + } + + function eachNoCallbackIteratee(done, x, callback) { + expect(x).to.equal(1); + callback(); + done(); + } + + it('each', function(done) { + var args = []; + async.each([1,3,2], eachIteratee.bind(this, args), function(err){ + assert(err === null, err + " passed instead of 'null'"); + expect(args).to.eql([1,2,3]); + done(); + }); + }); + + it('each extra callback', function(done) { + var count = 0; + async.each([1,3,2], function(val, callback) { + count++; + var done_ = count == 3; + callback(); + assert.throws(callback); + if (done_) { + done(); + } + }); + }); + + it('each empty array', function(done) { + async.each([], function(x, callback){ + assert(false, 'iteratee should not be called'); + callback(); + }, function(err){ + if (err) throw err; + assert(true, 'should call callback'); + }); + setTimeout(done, 25); + }); + + + it('each empty array, with other property on the array', function(done) { + var myArray = []; + myArray.myProp = "anything"; + async.each(myArray, function(x, callback){ + assert(false, 'iteratee should not be called'); + callback(); + }, function(err){ + if (err) throw err; + assert(true, 'should call callback'); + }); + setTimeout(done, 25); + }); + + + it('each error', function(done) { + async.each([1,2,3], function(x, callback){ + callback('error'); + }, function(err){ + expect(err).to.equal('error'); + }); + setTimeout(done, 50); + }); + + it('each no callback', function(done) { + async.each([1], eachNoCallbackIteratee.bind(this, done)); + }); + + it('eachSeries', function(done) { + var args = []; + async.eachSeries([1,3,2], eachIteratee.bind(this, args), function(err){ + assert(err === null, err + " passed instead of 'null'"); + expect(args).to.eql([1,3,2]); + done(); + }); + }); + + it('eachSeries empty array', function(done) { + async.eachSeries([], function(x, callback){ + assert(false, 'iteratee should not be called'); + callback(); + }, function(err){ + if (err) throw err; + assert(true, 'should call callback'); + }); + setTimeout(done, 25); + }); + + it('eachSeries array modification', function(done) { + var arr = [1, 2, 3, 4]; + async.eachSeries(arr, function (x, callback) { + async.setImmediate(callback); + }, function () { + assert(true, 'should call callback'); + }); + + arr.pop(); + arr.splice(0, 1); + + setTimeout(done, 50); + }); + + // bug #782. Remove in next major release + it('eachSeries single item', function(done) { + var sync = true; + async.eachSeries([1], function (i, cb) { + cb(null); + }, function () { + assert(sync, "callback not called on same tick"); + }); + sync = false; + done(); + }); + + // bug #782. Remove in next major release + it('eachSeries single item', function(done) { + var sync = true; + async.eachSeries([1], function (i, cb) { + cb(null); + }, function () { + assert(sync, "callback not called on same tick"); + }); + sync = false; + done(); + }); + + it('eachSeries error', function(done) { + var call_order = []; + async.eachSeries([1,2,3], function(x, callback){ + call_order.push(x); + callback('error'); + }, function(err){ + expect(call_order).to.eql([1]); + expect(err).to.equal('error'); + }); + setTimeout(done, 50); + }); + + it('eachSeries no callback', function(done) { + async.eachSeries([1], eachNoCallbackIteratee.bind(this, done)); + }); + + + it('eachLimit', function(done) { + var args = []; + var arr = [0,1,2,3,4,5,6,7,8,9]; + async.eachLimit(arr, 2, function(x,callback){ + setTimeout(function(){ + args.push(x); + callback(); + }, x*5); + }, function(err){ + assert(err === null, err + " passed instead of 'null'"); + expect(args).to.eql(arr); + done(); + }); + }); + + it('eachLimit empty array', function(done) { + async.eachLimit([], 2, function(x, callback){ + assert(false, 'iteratee should not be called'); + callback(); + }, function(err){ + if (err) throw err; + assert(true, 'should call callback'); + }); + setTimeout(done, 25); + }); + + it('eachLimit limit exceeds size', function(done) { + var args = []; + var arr = [0,1,2,3,4,5,6,7,8,9]; + async.eachLimit(arr, 20, eachIteratee.bind(this, args), function(err){ + if (err) throw err; + expect(args).to.eql(arr); + done(); + }); + }); + + it('eachLimit limit equal size', function(done) { + var args = []; + var arr = [0,1,2,3,4,5,6,7,8,9]; + async.eachLimit(arr, 10, eachIteratee.bind(this, args), function(err){ + if (err) throw err; + expect(args).to.eql(arr); + done(); + }); + }); + + it('eachLimit zero limit', function(done) { + async.eachLimit([0,1,2,3,4,5], 0, function(x, callback){ + assert(false, 'iteratee should not be called'); + callback(); + }, function(err){ + if (err) throw err; + assert(true, 'should call callback'); + }); + setTimeout(done, 25); + }); + + it('eachLimit error', function(done) { + var arr = [0,1,2,3,4,5,6,7,8,9]; + var call_order = []; + + async.eachLimit(arr, 3, function(x, callback){ + call_order.push(x); + if (x === 2) { + callback('error'); + } + }, function(err){ + expect(call_order).to.eql([0,1,2]); + expect(err).to.equal('error'); + }); + setTimeout(done, 25); + }); + + it('eachLimit no callback', function(done) { + async.eachLimit([1], 1, eachNoCallbackIteratee.bind(this, done)); + }); + + it('eachLimit synchronous', function(done) { + var args = []; + var arr = [0,1,2]; + async.eachLimit(arr, 5, function(x,callback){ + args.push(x); + callback(); + }, function(err){ + if (err) throw err; + expect(args).to.eql(arr); + done(); + }); + }); + + it('eachLimit does not continue replenishing after error', function(done) { + var started = 0; + var arr = [0,1,2,3,4,5,6,7,8,9]; + var delay = 10; + var limit = 3; + var maxTime = 10 * arr.length; + + async.eachLimit(arr, limit, function(x, callback) { + started ++; + if (started === 3) { + return callback(new Error ("Test Error")); + } + setTimeout(function(){ + callback(); + }, delay); + }, function(){}); + + setTimeout(function(){ + expect(started).to.equal(3); + done(); + }, maxTime); + }); + + it('forEach alias', function(done) { + assert.strictEqual(async.each, async.forEach); + done(); + }); + + it('forEachSeries alias', function(done) { + assert.strictEqual(async.eachSeries, async.forEachSeries); + done(); + }); + + it('forEachLimit alias', function(done) { + assert.strictEqual(async.eachLimit, async.forEachLimit); + done(); + }); +}); diff --git a/mocha_test/eachOf.js b/mocha_test/eachOf.js new file mode 100644 index 0000000..c705bad --- /dev/null +++ b/mocha_test/eachOf.js @@ -0,0 +1,333 @@ +var async = require('../lib'); +var expect = require('chai').expect; +var assert = require('assert'); + +describe("eachOf", function() { + + function forEachOfNoCallbackIteratee(done, x, key, callback) { + expect(x).to.equal(1); + expect(key).to.equal("a"); + callback(); + done(); + } + + function forEachOfIteratee(args, value, key, callback) { + setTimeout(function(){ + args.push(key, value); + callback(); + }, value*25); + } + + it('eachOf alias', function(done) { + expect(async.eachOf).to.equal(async.forEachOf); + done(); + }); + + it('eachOfLimit alias', function(done) { + expect(async.eachOfLimit).to.equal(async.forEachOfLimit); + done(); + }); + + it('eachOfSeries alias', function(done) { + expect(async.eachOfSeries).to.equal(async.forEachOfSeries); + done(); + }); + + it('forEachOf', function(done) { + var args = []; + async.forEachOf({ a: 1, b: 2 }, forEachOfIteratee.bind(this, args), function(err){ + assert(err === null, err + " passed instead of 'null'"); + expect(args).to.eql(["a", 1, "b", 2]); + done(); + }); + }); + + it('forEachOf - instant resolver', function(done) { + var args = []; + async.forEachOf({ a: 1, b: 2 }, function(x, k, cb) { + args.push(k, x); + cb(); + }, function(){ + // ensures done callback isn't called before all items iterated + expect(args).to.eql(["a", 1, "b", 2]); + done(); + }); + }); + + it('forEachOf empty object', function(done) { + async.forEachOf({}, function(value, key, callback){ + assert(false, 'iteratee should not be called'); + callback(); + }, function(err) { + if (err) throw err; + assert(true, 'should call callback'); + }); + setTimeout(done, 25); + }); + + it('forEachOf empty array', function(done) { + async.forEachOf([], function(value, key, callback){ + assert(false, 'iteratee should not be called'); + callback(); + }, function(err) { + if (err) throw err; + assert(true, 'should call callback'); + }); + setTimeout(done, 25); + }); + + it('forEachOf error', function(done) { + async.forEachOf({ a: 1, b: 2 }, function(value, key, callback) { + callback('error'); + }, function(err){ + expect(err).to.equal('error'); + }); + setTimeout(done, 50); + }); + + it('forEachOf no callback', function(done) { + async.forEachOf({ a: 1 }, forEachOfNoCallbackIteratee.bind(this, done)); + }); + + + it('forEachOf with array', function(done) { + var args = []; + async.forEachOf([ "a", "b" ], forEachOfIteratee.bind(this, args), function(err){ + if (err) throw err; + expect(args).to.eql([0, "a", 1, "b"]); + done(); + }); + }); + + it('forEachOf with Set (iterators)', function(done) { + if (typeof Set !== 'function') + return done(); + + var args = []; + var set = new Set(); + set.add("a"); + set.add("b"); + async.forEachOf(set, forEachOfIteratee.bind(this, args), function(err){ + if (err) throw err; + expect(args).to.eql([0, "a", 1, "b"]); + done(); + }); + }); + + it('forEachOf with Map (iterators)', function(done) { + if (typeof Map !== 'function') + return done(); + + var args = []; + var map = new Map(); + map.set(1, "a"); + map.set(2, "b"); + async.forEachOf(map, forEachOfIteratee.bind(this, args), function(err){ + if (err) throw err; + expect(args).to.eql([0, [1, "a"], 1, [2, "b"]]); + done(); + }); + }); + + it('forEachOfSeries', function(done) { + var args = []; + async.forEachOfSeries({ a: 1, b: 2 }, forEachOfIteratee.bind(this, args), function(err){ + assert(err === null, err + " passed instead of 'null'"); + expect(args).to.eql([ "a", 1, "b", 2 ]); + done(); + }); + }); + + it('forEachOfSeries empty object', function(done) { + async.forEachOfSeries({}, function(x, callback){ + assert(false, 'iteratee should not be called'); + callback(); + }, function(err){ + if (err) throw err; + assert(true, 'should call callback'); + }); + setTimeout(done, 25); + }); + + it('forEachOfSeries error', function(done) { + var call_order = []; + async.forEachOfSeries({ a: 1, b: 2 }, function(value, key, callback){ + call_order.push(value, key); + callback('error'); + }, function(err){ + expect(call_order).to.eql([ 1, "a" ]); + expect(err).to.equal('error'); + }); + setTimeout(done, 50); + }); + + it('forEachOfSeries no callback', function(done) { + async.forEachOfSeries({ a: 1 }, forEachOfNoCallbackIteratee.bind(this, done)); + }); + + it('forEachOfSeries with array', function(done) { + var args = []; + async.forEachOfSeries([ "a", "b" ], forEachOfIteratee.bind(this, args), function(err){ + if (err) throw err; + expect(args).to.eql([ 0, "a", 1, "b" ]); + done(); + }); + }); + + it('forEachOfSeries with Set (iterators)', function(done) { + if (typeof Set !== 'function') + return done(); + + var args = []; + var set = new Set(); + set.add("a"); + set.add("b"); + async.forEachOfSeries(set, forEachOfIteratee.bind(this, args), function(err){ + if (err) throw err; + expect(args).to.eql([0, "a", 1, "b"]); + done(); + }); + }); + + it('forEachOfSeries with Map (iterators)', function(done) { + if (typeof Map !== 'function') + return done(); + + var args = []; + var map = new Map(); + map.set(1, "a"); + map.set(2, "b"); + async.forEachOfSeries(map, forEachOfIteratee.bind(this, args), function(err){ + if (err) throw err; + expect(args).to.eql([0, [1, "a"], 1, [2, "b"]]); + done(); + }); + }); + + it('forEachOfLimit', function(done) { + var args = []; + var obj = { a: 1, b: 2, c: 3, d: 4 }; + async.forEachOfLimit(obj, 2, function(value, key, callback){ + setTimeout(function(){ + args.push(value, key); + callback(); + }, value * 5); + }, function(err){ + assert(err === null, err + " passed instead of 'null'"); + expect(args).to.eql([ 1, "a", 2, "b", 3, "c", 4, "d" ]); + done(); + }); + }); + + it('forEachOfLimit empty object', function(done) { + async.forEachOfLimit({}, 2, function(value, key, callback){ + assert(false, 'iteratee should not be called'); + callback(); + }, function(err){ + if (err) throw err; + assert(true, 'should call callback'); + }); + setTimeout(done, 25); + }); + + it('forEachOfLimit limit exceeds size', function(done) { + var args = []; + var obj = { a: 1, b: 2, c: 3, d: 4, e: 5 }; + async.forEachOfLimit(obj, 10, forEachOfIteratee.bind(this, args), function(err){ + if (err) throw err; + expect(args).to.eql([ "a", 1, "b", 2, "c", 3, "d", 4, "e", 5 ]); + done(); + }); + }); + + it('forEachOfLimit limit equal size', function(done) { + var args = []; + var obj = { a: 1, b: 2, c: 3, d: 4, e: 5 }; + async.forEachOfLimit(obj, 5, forEachOfIteratee.bind(this, args), function(err){ + if (err) throw err; + expect(args).to.eql([ "a", 1, "b", 2, "c", 3, "d", 4, "e", 5 ]); + done(); + }); + }); + + it('forEachOfLimit zero limit', function(done) { + async.forEachOfLimit({ a: 1, b: 2 }, 0, function(x, callback){ + assert(false, 'iteratee should not be called'); + callback(); + }, function(err){ + if (err) throw err; + assert(true, 'should call callback'); + }); + setTimeout(done, 25); + }); + + it('forEachOfLimit error', function(done) { + var obj = { a: 1, b: 2, c: 3, d: 4, e: 5 }; + var call_order = []; + + async.forEachOfLimit(obj, 3, function(value, key, callback){ + call_order.push(value, key); + if (value === 2) { + callback('error'); + } + }, function(err){ + expect(call_order).to.eql([ 1, "a", 2, "b" ]); + expect(err).to.equal('error'); + }); + setTimeout(done, 25); + }); + + it('forEachOfLimit no callback', function(done) { + async.forEachOfLimit({ a: 1 }, 1, forEachOfNoCallbackIteratee.bind(this, done)); + }); + + it('forEachOfLimit synchronous', function(done) { + var args = []; + var obj = { a: 1, b: 2 }; + async.forEachOfLimit(obj, 5, forEachOfIteratee.bind(this, args), function(err){ + if (err) throw err; + expect(args).to.eql([ "a", 1, "b", 2 ]); + done(); + }); + }); + + it('forEachOfLimit with array', function(done) { + var args = []; + var arr = [ "a", "b" ]; + async.forEachOfLimit(arr, 1, forEachOfIteratee.bind(this, args), function (err) { + if (err) throw err; + expect(args).to.eql([ 0, "a", 1, "b" ]); + done(); + }); + }); + + it('forEachOfLimit with Set (iterators)', function(done) { + if (typeof Set !== 'function') + return done(); + + var args = []; + var set = new Set(); + set.add("a"); + set.add("b"); + async.forEachOfLimit(set, 1, forEachOfIteratee.bind(this, args), function(err){ + if (err) throw err; + expect(args).to.eql([0, "a", 1, "b"]); + done(); + }); + }); + + it('forEachOfLimit with Map (iterators)', function(done) { + if (typeof Map !== 'function') + return done(); + + var args = []; + var map = new Map(); + map.set(1, "a"); + map.set(2, "b"); + async.forEachOfLimit(map, 1, forEachOfIteratee.bind(this, args), function(err){ + if (err) throw err; + expect(args).to.eql([0, [1, "a"], 1, [2, "b"]]); + done(); + }); + }); +}); diff --git a/mocha_test/ensureAsync.js b/mocha_test/ensureAsync.js index c33e344..fd8cc3f 100644 --- a/mocha_test/ensureAsync.js +++ b/mocha_test/ensureAsync.js @@ -1,11 +1,64 @@ var async = require('../lib');
var expect = require('chai').expect;
+var assert = require('assert');
describe('ensureAsync', function() {
var passContext = function(cb) {
cb(this);
};
+ it('defer sync functions', function(done) {
+ var sync = true;
+ async.ensureAsync(function (arg1, arg2, cb) {
+ expect(arg1).to.equal(1);
+ expect(arg2).to.equal(2);
+ cb(null, 4, 5);
+ })(1, 2, function (err, arg4, arg5) {
+ expect(err).to.equal(null);
+ expect(arg4).to.equal(4);
+ expect(arg5).to.equal(5);
+ assert(!sync, 'callback called on same tick');
+ done();
+ });
+ sync = false;
+ });
+
+ it('do not defer async functions', function(done) {
+ var sync = false;
+ async.ensureAsync(function (arg1, arg2, cb) {
+ expect(arg1).to.equal(1);
+ expect(arg2).to.equal(2);
+ async.setImmediate(function () {
+ sync = true;
+ cb(null, 4, 5);
+ sync = false;
+ });
+ })(1, 2, function (err, arg4, arg5) {
+ expect(err).to.equal(null);
+ expect(arg4).to.equal(4);
+ expect(arg5).to.equal(5);
+ assert(sync, 'callback called on next tick');
+ done();
+ });
+ });
+
+ it('double wrapping', function(done) {
+ var sync = true;
+ async.ensureAsync(async.ensureAsync(function (arg1, arg2, cb) {
+ expect(arg1).to.equal(1);
+ expect(arg2).to.equal(2);
+ cb(null, 4, 5);
+ }))(1, 2, function (err, arg4, arg5) {
+ expect(err).to.equal(null);
+ expect(arg4).to.equal(4);
+ expect(arg5).to.equal(5);
+ assert(!sync, 'callback called on same tick');
+ done();
+ });
+ sync = false;
+ });
+
+
it('should propely bind context to the wrapped function', function(done) {
// call bind after wrapping with ensureAsync
diff --git a/mocha_test/iterator.js b/mocha_test/iterator.js new file mode 100644 index 0000000..71c477c --- /dev/null +++ b/mocha_test/iterator.js @@ -0,0 +1,61 @@ +var async = require('../lib'); +var expect = require('chai').expect; + +describe('iterator', function() { + + it('iterator', function(done) { + var call_order = []; + var iterator = async.iterator([ + function(){call_order.push(1);}, + function(arg1){ + expect(arg1).to.equal('arg1'); + call_order.push(2); + }, + function(arg1, arg2){ + expect(arg1).to.equal('arg1'); + expect(arg2).to.equal('arg2'); + call_order.push(3); + } + ]); + iterator(); + expect(call_order).to.eql([1]); + var iterator2 = iterator(); + expect(call_order).to.eql([1,1]); + var iterator3 = iterator2('arg1'); + expect(call_order).to.eql([1,1,2]); + var iterator4 = iterator3('arg1', 'arg2'); + expect(call_order).to.eql([1,1,2,3]); + expect(iterator4).to.equal(null); + done(); + }); + + it('iterator empty array', function(done) { + var iterator = async.iterator([]); + expect(iterator()).to.equal(null); + expect(iterator.next()).to.equal(null); + done(); + }); + + it('iterator.next', function(done) { + var call_order = []; + var iterator = async.iterator([ + function(){call_order.push(1);}, + function(arg1){ + expect(arg1).to.equal('arg1'); + call_order.push(2); + }, + function(arg1, arg2){ + expect(arg1).to.equal('arg1'); + expect(arg2).to.equal('arg2'); + call_order.push(3); + } + ]); + var fn = iterator.next(); + var iterator2 = fn('arg1'); + expect(call_order).to.eql([2]); + iterator2('arg1','arg2'); + expect(call_order).to.eql([2,3]); + expect(iterator2.next()).to.equal(null); + done(); + }); +}); diff --git a/mocha_test/map.js b/mocha_test/map.js new file mode 100644 index 0000000..a537427 --- /dev/null +++ b/mocha_test/map.js @@ -0,0 +1,311 @@ +var async = require('../lib'); +var expect = require('chai').expect; +var assert = require('assert'); + +describe("map", function() { + + function mapIteratee(call_order, x, callback) { + setTimeout(function() { + call_order.push(x); + callback(null, x * 2); + }, x * 25); + } + + it('basic', function(done) { + var call_order = []; + async.map([1, 3, 2], mapIteratee.bind(this, call_order), function(err, results) { + assert(err === null, err + " passed instead of 'null'"); + expect(call_order).to.eql([1, 2, 3]); + expect(results).to.eql([2, 6, 4]); + done(); + }); + }); + + it('with reflect', function(done) { + var call_order = []; + async.map([1, 3, 2], async.reflect(function(item, cb) { + setTimeout(function() { + call_order.push(item); + cb(null, item * 2); + }, item * 25); + }), function(err, results) { + assert(err === null, err + " passed instead of 'null'"); + expect(call_order).to.eql([1, 2, 3]); + expect(results).to.eql([{ + value: 2 + }, { + value: 6 + }, { + value: 4 + }]); + done(); + }); + }); + + it('error with reflect', function(done) { + var call_order = []; + async.map([-1, 1, 3, 2], async.reflect(function(item, cb) { + setTimeout(function() { + call_order.push(item); + if (item < 0) { + cb('number less then zero'); + } else { + cb(null, item * 2); + } + }, item * 25); + }), function(err, results) { + assert(err === null, err + " passed instead of 'null'"); + expect(call_order).to.eql([-1, 1, 2, 3]); + expect(results).to.eql([{ + error: 'number less then zero' + }, { + value: 2 + }, { + value: 6 + }, { + value: 4 + }]); + done(); + }); + }); + + it('map original untouched', function(done) { + var a = [1, 2, 3]; + async.map(a, function(x, callback) { + callback(null, x * 2); + }, function(err, results) { + expect(results).to.eql([2, 4, 6]); + expect(a).to.eql([1, 2, 3]); + done(); + }); + }); + + it('map without main callback', function(done) { + var a = [1, 2, 3]; + var r = []; + async.map(a, function(x, callback) { + r.push(x); + var done_ = r.length == a.length; + callback(null); + if (done_) { + expect(r).to.eql(a); + done(); + } + }); + }); + + it('map error', function(done) { + async.map([1, 2, 3], function(x, callback) { + callback('error'); + }, function(err) { + expect(err).to.equal('error'); + }); + setTimeout(done, 50); + }); + + it('map undefined array', function(done) { + async.map(undefined, function(x, callback) { + callback(); + }, function(err, result) { + expect(err).to.equal(null); + expect(result).to.eql([]); + }); + setTimeout(done, 50); + }); + + it('map object', function(done) { + async.map({ + a: 1, + b: 2, + c: 3 + }, function(val, callback) { + callback(null, val * 2); + }, function(err, result) { + if (err) throw err; + expect(Object.prototype.toString.call(result)).to.equal('[object Object]'); + expect(result).to.eql({ + a: 2, + b: 4, + c: 6 + }); + done(); + }); + }); + + it('mapSeries', function(done) { + var call_order = []; + async.mapSeries([1, 3, 2], mapIteratee.bind(this, call_order), function(err, results) { + assert(err === null, err + " passed instead of 'null'"); + expect(call_order).to.eql([1, 3, 2]); + expect(results).to.eql([2, 6, 4]); + done(); + }); + }); + + it('mapSeries error', function(done) { + async.mapSeries([1, 2, 3], function(x, callback) { + callback('error'); + }, function(err) { + expect(err).to.equal('error'); + }); + setTimeout(done, 50); + }); + + it('mapSeries undefined array', function(done) { + async.mapSeries(undefined, function(x, callback) { + callback(); + }, function(err, result) { + expect(err).to.equal(null); + expect(result).to.eql([]); + }); + setTimeout(done, 50); + }); + + it('mapSeries object', function(done) { + async.mapSeries({ + a: 1, + b: 2, + c: 3 + }, function(val, callback) { + callback(null, val * 2); + }, function(err, result) { + if (err) throw err; + expect(result).to.eql({ + a: 2, + b: 4, + c: 6 + }); + done(); + }); + }); + + it('mapLimit', function(done) { + var call_order = []; + async.mapLimit([2, 4, 3], 2, mapIteratee.bind(this, call_order), function(err, results) { + assert(err === null, err + " passed instead of 'null'"); + expect(call_order).to.eql([2, 4, 3]); + expect(results).to.eql([4, 8, 6]); + done(); + }); + }); + + it('mapLimit empty array', function(done) { + async.mapLimit([], 2, function(x, callback) { + assert(false, 'iteratee should not be called'); + callback(); + }, function(err) { + if (err) throw err; + assert(true, 'should call callback'); + }); + setTimeout(done, 25); + }); + + it('mapLimit undefined array', function(done) { + async.mapLimit(undefined, 2, function(x, callback) { + callback(); + }, function(err, result) { + expect(err).to.equal(null); + expect(result).to.eql([]); + }); + setTimeout(done, 50); + }); + + it('mapLimit limit exceeds size', function(done) { + var call_order = []; + async.mapLimit([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 20, mapIteratee.bind(this, call_order), function(err, results) { + expect(call_order).to.eql([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); + expect(results).to.eql([0, 2, 4, 6, 8, 10, 12, 14, 16, 18]); + done(); + }); + }); + + it('mapLimit limit equal size', function(done) { + var call_order = []; + async.mapLimit([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 10, mapIteratee.bind(this, call_order), function(err, results) { + expect(call_order).to.eql([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); + expect(results).to.eql([0, 2, 4, 6, 8, 10, 12, 14, 16, 18]); + done(); + }); + }); + + it('mapLimit zero limit', function(done) { + async.mapLimit([0, 1, 2, 3, 4, 5], 0, function(x, callback) { + assert(false, 'iteratee should not be called'); + callback(); + }, function(err, results) { + expect(results).to.eql([]); + assert(true, 'should call callback'); + }); + setTimeout(done, 25); + }); + + it('mapLimit error', function(done) { + var arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; + var call_order = []; + + async.mapLimit(arr, 3, function(x, callback) { + call_order.push(x); + if (x === 2) { + callback('error'); + } + }, function(err) { + expect(call_order).to.eql([0, 1, 2]); + expect(err).to.equal('error'); + }); + setTimeout(done, 25); + }); + + it('mapLimit does not continue replenishing after error', function(done) { + var started = 0; + var arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; + var delay = 10; + var limit = 3; + var maxTime = 10 * arr.length; + + async.mapLimit(arr, limit, function(x, callback) { + started++; + if (started === 3) { + return callback(new Error("Test Error")); + } + setTimeout(function() { + callback(); + }, delay); + }, function() {}); + + setTimeout(function() { + expect(started).to.equal(3); + done(); + }, maxTime); + }); + + it('map with Map', function(done) { + if (typeof Map !== 'function') + return done(); + + var map = new Map(); + map.set(1, "a"); + map.set(2, "b"); + async.map(map, function(val, cb) { + cb(null, val); + }, function(err, result) { + assert(Array.isArray(result), "map should return an array for an iterable"); + done(); + }); + }); + + // Issue 1106 on github: https://github.com/caolan/async/issues/1106 + it('map main callback is called only once', function(done) { + async.map([1, 2], function(item, callback) { + try { + callback(item); + } catch (exception) { + expect(function() { + callback(exception); + }).to.throw(/already called/); + done(); + } + }, function(err) { + no_such_function(); + }); + }); +}); diff --git a/mocha_test/memoize.js b/mocha_test/memoize.js new file mode 100644 index 0000000..1a6e886 --- /dev/null +++ b/mocha_test/memoize.js @@ -0,0 +1,208 @@ +var async = require('../lib'); +var expect = require('chai').expect; +var assert = require('assert'); + +describe("memoize", function() { + + it('memoize', function(done) { + var call_order = []; + + var fn = function (arg1, arg2, callback) { + async.setImmediate(function () { + call_order.push(['fn', arg1, arg2]); + callback(null, arg1 + arg2); + }); + }; + + var fn2 = async.memoize(fn); + fn2(1, 2, function (err, result) { + assert(err === null, err + " passed instead of 'null'"); + expect(result).to.equal(3); + fn2(1, 2, function (err, result) { + expect(result).to.equal(3); + fn2(2, 2, function (err, result) { + expect(result).to.equal(4); + expect(call_order).to.eql([['fn',1,2], ['fn',2,2]]); + done(); + }); + }); + }); + }); + + it('maintains asynchrony', function(done) { + var call_order = []; + + var fn = function (arg1, arg2, callback) { + call_order.push(['fn', arg1, arg2]); + async.setImmediate(function () { + call_order.push(['cb', arg1, arg2]); + callback(null, arg1 + arg2); + }); + }; + + var fn2 = async.memoize(fn); + fn2(1, 2, function (err, result) { + expect(result).to.equal(3); + fn2(1, 2, function (err, result) { + expect(result).to.equal(3); + async.nextTick(memoize_done); + call_order.push('tick3'); + }); + call_order.push('tick2'); + }); + call_order.push('tick1'); + + function memoize_done() { + var async_call_order = [ + ['fn',1,2], // initial async call + 'tick1', // async caller + ['cb',1,2], // async callback + // ['fn',1,2], // memoized // memoized async body + 'tick2', // handler for first async call + // ['cb',1,2], // memoized // memoized async response body + 'tick3' // handler for memoized async call + ]; + expect(call_order).to.eql(async_call_order); + done(); + } + }); + + it('unmemoize', function(done) { + var call_order = []; + + var fn = function (arg1, arg2, callback) { + call_order.push(['fn', arg1, arg2]); + async.setImmediate(function () { + callback(null, arg1 + arg2); + }); + }; + + var fn2 = async.memoize(fn); + var fn3 = async.unmemoize(fn2); + fn3(1, 2, function (err, result) { + expect(result).to.equal(3); + fn3(1, 2, function (err, result) { + expect(result).to.equal(3); + fn3(2, 2, function (err, result) { + expect(result).to.equal(4); + expect(call_order).to.eql([['fn',1,2], ['fn',1,2], ['fn',2,2]]); + done(); + }); + }); + }); + }); + + it('unmemoize a not memoized function', function(done) { + var fn = function (arg1, arg2, callback) { + callback(null, arg1 + arg2); + }; + + var fn2 = async.unmemoize(fn); + fn2(1, 2, function(err, result) { + expect(result).to.equal(3); + }); + + done(); + }); + + it('error', function(done) { + var testerr = new Error('test'); + var fn = function (arg1, arg2, callback) { + callback(testerr, arg1 + arg2); + }; + async.memoize(fn)(1, 2, function (err) { + expect(err).to.equal(testerr); + }); + done(); + }); + + it('multiple calls', function(done) { + var fn = function (arg1, arg2, callback) { + assert(true); + setTimeout(function(){ + callback(null, arg1, arg2); + }, 10); + }; + var fn2 = async.memoize(fn); + fn2(1, 2, function(err, result) { + expect(result).to.equal(1, 2); + }); + fn2(1, 2, function(err, result) { + expect(result).to.equal(1, 2); + done(); + }); + }); + + it('custom hash function', function(done) { + var testerr = new Error('test'); + + var fn = function (arg1, arg2, callback) { + callback(testerr, arg1 + arg2); + }; + var fn2 = async.memoize(fn, function () { + return 'custom hash'; + }); + fn2(1, 2, function (err, result) { + expect(result).to.equal(3); + fn2(2, 2, function (err, result) { + expect(result).to.equal(3); + done(); + }); + }); + }); + + it('manually added memo value', function(done) { + var fn = async.memoize(function() { + test(false, "Function should never be called"); + }); + fn.memo.foo = ["bar"]; + fn("foo", function(val) { + expect(val).to.equal("bar"); + done(); + }); + }); + + it('avoid constructor key return undefined', function(done) { + var fn = async.memoize(function(name, callback) { + setTimeout(function(){ + callback(null, name); + }, 100); + }); + fn('constructor', function(error, results) { + expect(results).to.equal('constructor'); + done(); + }); + }); + + it('avoid __proto__ key return undefined', function(done) { + // Skip test if there is a Object.create bug (node 0.10 and some Chrome 30x versions) + var x = Object.create(null); + /* jshint proto: true */ + x.__proto__ = 'foo'; + if (x.__proto__ !== 'foo') { + return done(); + } + + var fn = async.memoize(function(name, callback) { + setTimeout(function(){ + callback(null, name); + }, 100); + }); + fn('__proto__', function(error, results) { + expect(results).to.equal('__proto__'); + done(); + }); + }); + + it('allow hasOwnProperty as key', function(done) { + var fn = async.memoize(function(name, callback) { + setTimeout(function(){ + callback(null, name); + }, 100); + }); + fn('hasOwnProperty', function(error, results) { + expect(results).to.equal('hasOwnProperty'); + done(); + }); + }); +}); diff --git a/mocha_test/parallel.js b/mocha_test/parallel.js new file mode 100644 index 0000000..5362491 --- /dev/null +++ b/mocha_test/parallel.js @@ -0,0 +1,277 @@ +var async = require('../lib'); +var expect = require('chai').expect; +var assert = require('assert'); +var isBrowser = require('./support/is_browser'); +var getFunctionsObject = require('./support/get_function_object'); + +describe('parallel', function() { + + it('parallel', function(done) { + var call_order = []; + async.parallel([ + function(callback){ + setTimeout(function(){ + call_order.push(1); + callback(null, 1); + }, 50); + }, + function(callback){ + setTimeout(function(){ + call_order.push(2); + callback(null, 2); + }, 100); + }, + function(callback){ + setTimeout(function(){ + call_order.push(3); + callback(null, 3,3); + }, 25); + } + ], + function(err, results){ + assert(err === null, err + " passed instead of 'null'"); + expect(call_order).to.eql([3,1,2]); + expect(results).to.eql([1,2,[3,3]]); + done(); + }); + }); + + it('parallel empty array', function(done) { + async.parallel([], function(err, results){ + assert(err === null, err + " passed instead of 'null'"); + expect(results).to.eql([]); + done(); + }); + }); + + it('parallel error', function(done) { + async.parallel([ + function(callback){ + callback('error', 1); + }, + function(callback){ + callback('error2', 2); + } + ], + function(err){ + expect(err).to.equal('error'); + }); + setTimeout(done, 100); + }); + + it('parallel no callback', function(done) { + async.parallel([ + function(callback){callback();}, + function(callback){callback(); done();}, + ]); + }); + + it('parallel object', function(done) { + var call_order = []; + async.parallel(getFunctionsObject(call_order), function(err, results){ + expect(err).to.equal(null); + expect(call_order).to.eql([3,1,2]); + expect(results).to.eql({ + one: 1, + two: 2, + three: [3,3] + }); + done(); + }); + }); + + // Issue 10 on github: https://github.com/caolan/async/issues#issue/10 + it('paralel falsy return values', function(done) { + function taskFalse(callback) { + async.nextTick(function() { + callback(null, false); + }); + } + function taskUndefined(callback) { + async.nextTick(function() { + callback(null, undefined); + }); + } + function taskEmpty(callback) { + async.nextTick(function() { + callback(null); + }); + } + function taskNull(callback) { + async.nextTick(function() { + callback(null, null); + }); + } + async.parallel( + [taskFalse, taskUndefined, taskEmpty, taskNull], + function(err, results) { + expect(results.length).to.equal(4); + assert.strictEqual(results[0], false); + assert.strictEqual(results[1], undefined); + assert.strictEqual(results[2], undefined); + assert.strictEqual(results[3], null); + done(); + } + ); + }); + + + it('parallel limit', function(done) { + var call_order = []; + async.parallelLimit([ + function(callback){ + setTimeout(function(){ + call_order.push(1); + callback(null, 1); + }, 50); + }, + function(callback){ + setTimeout(function(){ + call_order.push(2); + callback(null, 2); + }, 100); + }, + function(callback){ + setTimeout(function(){ + call_order.push(3); + callback(null, 3,3); + }, 25); + } + ], + 2, + function(err, results){ + assert(err === null, err + " passed instead of 'null'"); + expect(call_order).to.eql([1,3,2]); + expect(results).to.eql([1,2,[3,3]]); + done(); + }); + }); + + it('parallel limit empty array', function(done) { + async.parallelLimit([], 2, function(err, results){ + assert(err === null, err + " passed instead of 'null'"); + expect(results).to.eql([]); + done(); + }); + }); + + it('parallel limit error', function(done) { + async.parallelLimit([ + function(callback){ + callback('error', 1); + }, + function(callback){ + callback('error2', 2); + } + ], + 1, + function(err){ + expect(err).to.equal('error'); + }); + setTimeout(done, 100); + }); + + it('parallel limit no callback', function(done) { + async.parallelLimit([ + function(callback){callback();}, + function(callback){callback(); done();}, + ], 1); + }); + + it('parallel limit object', function(done) { + var call_order = []; + async.parallelLimit(getFunctionsObject(call_order), 2, function(err, results){ + expect(err).to.equal(null); + expect(call_order).to.eql([1,3,2]); + expect(results).to.eql({ + one: 1, + two: 2, + three: [3,3] + }); + done(); + }); + }); + + it('parallel call in another context', function(done) { + if (isBrowser()) { + // node only test + done(); + return; + } + var vm = require('vm'); + var sandbox = { + async: async, + done: done + }; + + var fn = "(" + (function () { + async.parallel([function (callback) { + callback(); + }], function (err) { + if (err) { + return done(err); + } + done(); + }); + }).toString() + "())"; + + vm.runInNewContext(fn, sandbox); + }); + + it('parallel error with reflect', function(done) { + async.parallel([ + async.reflect(function(callback){ + callback('error', 1); + }), + async.reflect(function(callback){ + callback('error2', 2); + }), + async.reflect(function(callback){ + callback(null, 2); + }) + ], + function(err, results){ + assert(err === null, err + " passed instead of 'null'"); + expect(results).to.eql([ + { error: 'error' }, + { error: 'error2' }, + { value: 2 } + ]); + done(); + }); + }); + + it('parallel does not continue replenishing after error', function(done) { + var started = 0; + var arr = [ + funcToCall, + funcToCall, + funcToCall, + funcToCall, + funcToCall, + funcToCall, + funcToCall, + funcToCall, + funcToCall, + ]; + var delay = 10; + var limit = 3; + var maxTime = 10 * arr.length; + function funcToCall(callback) { + started ++; + if (started === 3) { + return callback(new Error ("Test Error")); + } + setTimeout(function(){ + callback(); + }, delay); + } + + async.parallelLimit(arr, limit, function(){}); + + setTimeout(function(){ + expect(started).to.equal(3); + done(); + }, maxTime); + }); +}); diff --git a/mocha_test/priorityQueue.js b/mocha_test/priorityQueue.js index fa5cfce..b777815 100644 --- a/mocha_test/priorityQueue.js +++ b/mocha_test/priorityQueue.js @@ -108,7 +108,43 @@ describe('priorityQueue', function() { }; }); - + context('q.saturated(): ', function() { + it('should call the saturated callback if tasks length is concurrency', function(done) { + var calls = []; + var q = async.priorityQueue(function(task, cb) { + calls.push('process ' + task); + async.setImmediate(cb); + }, 4); + q.saturated = function() { + calls.push('saturated'); + }; + q.empty = function() { + expect(calls.indexOf('saturated')).to.be.above(-1); + setTimeout(function() { + expect(calls).eql([ + 'process foo4', + 'process foo3', + 'process foo2', + "saturated", + 'process foo1', + 'foo4 cb', + "saturated", + 'process foo0', + 'foo3 cb', + 'foo2 cb', + 'foo1 cb', + 'foo0 cb' + ]); + done(); + }, 50); + }; + q.push('foo0', 5, function () {calls.push('foo0 cb');}); + q.push('foo1', 4, function () {calls.push('foo1 cb');}); + q.push('foo2', 3, function () {calls.push('foo2 cb');}); + q.push('foo3', 2, function () {calls.push('foo3 cb');}); + q.push('foo4', 1, function () {calls.push('foo4 cb');}); + }); + }); context('q.unsaturated(): ',function() { it('should have a default buffer property that equals 25% of the concurrenct rate', function(done) { @@ -148,9 +184,6 @@ describe('priorityQueue', function() { expect(calls.indexOf('unsaturated')).to.be.above(-1); setTimeout(function() { expect(calls).eql([ - 'unsaturated', - 'unsaturated', - 'unsaturated', 'process foo4', 'process foo3', 'process foo2', diff --git a/mocha_test/queue.js b/mocha_test/queue.js index 2baf124..a51efb3 100644 --- a/mocha_test/queue.js +++ b/mocha_test/queue.js @@ -599,7 +599,43 @@ describe('queue', function(){ done(); }); - + context('q.saturated(): ', function() { + it('should call the saturated callback if tasks length is concurrency', function(done) { + var calls = []; + var q = async.queue(function(task, cb) { + calls.push('process ' + task); + async.setImmediate(cb); + }, 4); + q.saturated = function() { + calls.push('saturated'); + }; + q.empty = function() { + expect(calls.indexOf('saturated')).to.be.above(-1); + setTimeout(function() { + expect(calls).eql([ + 'process foo0', + 'process foo1', + 'process foo2', + "saturated", + 'process foo3', + 'foo0 cb', + "saturated", + 'process foo4', + 'foo1 cb', + 'foo2 cb', + 'foo3 cb', + 'foo4 cb' + ]); + done(); + }, 50); + }; + q.push('foo0', function () {calls.push('foo0 cb');}); + q.push('foo1', function () {calls.push('foo1 cb');}); + q.push('foo2', function () {calls.push('foo2 cb');}); + q.push('foo3', function () {calls.push('foo3 cb');}); + q.push('foo4', function () {calls.push('foo4 cb');}); + }); + }); context('q.unsaturated(): ',function() { it('should have a default buffer property that equals 25% of the concurrenct rate', function(done){ diff --git a/mocha_test/reduce.js b/mocha_test/reduce.js new file mode 100644 index 0000000..f5dce59 --- /dev/null +++ b/mocha_test/reduce.js @@ -0,0 +1,66 @@ +var async = require('../lib'); +var expect = require('chai').expect; +var assert = require('assert'); + +describe('reduce', function() { + + it('reduce', function(done) { + var call_order = []; + async.reduce([1,2,3], 0, function(a, x, callback){ + call_order.push(x); + callback(null, a + x); + }, function(err, result){ + assert(err === null, err + " passed instead of 'null'"); + expect(result).to.equal(6); + expect(call_order).to.eql([1,2,3]); + done(); + }); + }); + + it('reduce async with non-reference memo', function(done) { + async.reduce([1,3,2], 0, function(a, x, callback){ + setTimeout(function(){callback(null, a + x);}, Math.random()*100); + }, function(err, result){ + expect(result).to.equal(6); + done(); + }); + }); + + it('reduce error', function(done) { + async.reduce([1,2,3], 0, function(a, x, callback){ + callback('error'); + }, function(err){ + expect(err).to.equal('error'); + }); + setTimeout(done, 50); + }); + + it('inject alias', function(done) { + expect(async.inject).to.equal(async.reduce); + done(); + }); + + it('foldl alias', function(done) { + expect(async.foldl).to.equal(async.reduce); + done(); + }); + + it('reduceRight', function(done) { + var call_order = []; + var a = [1,2,3]; + async.reduceRight(a, 0, function(a, x, callback){ + call_order.push(x); + callback(null, a + x); + }, function(err, result){ + expect(result).to.equal(6); + expect(call_order).to.eql([3,2,1]); + expect(a).to.eql([1,2,3]); + done(); + }); + }); + + it('foldr alias', function(done) { + expect(async.foldr).to.equal(async.reduceRight); + done(); + }); +}); diff --git a/mocha_test/seq.js b/mocha_test/seq.js new file mode 100644 index 0000000..1f7cbfc --- /dev/null +++ b/mocha_test/seq.js @@ -0,0 +1,109 @@ +var async = require('../lib'); +var expect = require('chai').expect; +var assert = require('assert'); + +describe('seq', function() { + + it('seq', function(done) { + var add2 = function (n, cb) { + expect(n).to.equal(3); + setTimeout(function () { + cb(null, n + 2); + }, 50); + }; + var mul3 = function (n, cb) { + expect(n).to.equal(5); + setTimeout(function () { + cb(null, n * 3); + }, 15); + }; + var add1 = function (n, cb) { + expect(n).to.equal(15); + setTimeout(function () { + cb(null, n + 1); + }, 100); + }; + var add2mul3add1 = async.seq(add2, mul3, add1); + add2mul3add1(3, function (err, result) { + if (err) { + return done(err); + } + assert(err === null, err + " passed instead of 'null'"); + expect(result).to.equal(16); + done(); + }); + }); + + it('seq error', function(done) { + var testerr = new Error('test'); + + var add2 = function (n, cb) { + expect(n).to.equal(3); + setTimeout(function () { + cb(null, n + 2); + }, 50); + }; + var mul3 = function (n, cb) { + expect(n).to.equal(5); + setTimeout(function () { + cb(testerr); + }, 15); + }; + var add1 = function (n, cb) { + assert(false, 'add1 should not get called'); + setTimeout(function () { + cb(null, n + 1); + }, 100); + }; + var add2mul3add1 = async.seq(add2, mul3, add1); + add2mul3add1(3, function (err) { + expect(err).to.equal(testerr); + done(); + }); + }); + + it('seq binding', function(done) { + var testcontext = {name: 'foo'}; + + var add2 = function (n, cb) { + expect(this).to.equal(testcontext); + setTimeout(function () { + cb(null, n + 2); + }, 50); + }; + var mul3 = function (n, cb) { + expect(this).to.equal(testcontext); + setTimeout(function () { + cb(null, n * 3); + }, 15); + }; + var add2mul3 = async.seq(add2, mul3); + add2mul3.call(testcontext, 3, function (err, result) { + if (err) { + return done(err); + } + expect(this).to.equal(testcontext); + expect(result).to.equal(15); + done(); + }); + }); + + it('seq without callback', function(done) { + var testcontext = {name: 'foo'}; + + var add2 = function (n, cb) { + expect(this).to.equal(testcontext); + setTimeout(function () { + cb(null, n + 2); + }, 50); + }; + var mul3 = function () { + expect(this).to.equal(testcontext); + setTimeout(function () { + done(); + }, 15); + }; + var add2mul3 = async.seq(add2, mul3); + add2mul3.call(testcontext, 3); + }); +}); diff --git a/mocha_test/series.js b/mocha_test/series.js new file mode 100644 index 0000000..0237582 --- /dev/null +++ b/mocha_test/series.js @@ -0,0 +1,200 @@ +var async = require('../lib'); +var expect = require('chai').expect; +var assert = require('assert'); +var isBrowser = require('./support/is_browser'); +var getFunctionsObject = require('./support/get_function_object'); + +describe('series', function() { + it('series', function(done) { + var call_order = []; + async.series([ + function(callback){ + setTimeout(function(){ + call_order.push(1); + callback(null, 1); + }, 25); + }, + function(callback){ + setTimeout(function(){ + call_order.push(2); + callback(null, 2); + }, 50); + }, + function(callback){ + setTimeout(function(){ + call_order.push(3); + callback(null, 3,3); + }, 15); + } + ], + function(err, results){ + assert(err === null, err + " passed instead of 'null'"); + expect(results).to.eql([1,2,[3,3]]); + expect(call_order).to.eql([1,2,3]); + done(); + }); + }); + + it('with reflect', function(done) { + var call_order = []; + async.series([ + async.reflect(function(callback){ + setTimeout(function(){ + call_order.push(1); + callback(null, 1); + }, 25); + }), + async.reflect(function(callback){ + setTimeout(function(){ + call_order.push(2); + callback(null, 2); + }, 50); + }), + async.reflect(function(callback){ + setTimeout(function(){ + call_order.push(3); + callback(null, 3,3); + }, 15); + }) + ], + function(err, results){ + assert(err === null, err + " passed instead of 'null'"); + expect(results).to.eql([ + { value: 1 }, + { value: 2 }, + { value: [3,3] } + ]); + expect(call_order).to.eql([1,2,3]); + done(); + }); + }); + + it('empty array', function(done) { + async.series([], function(err, results){ + expect(err).to.equal(null); + expect(results).to.eql([]); + done(); + }); + }); + + it('error', function(done) { + async.series([ + function(callback){ + callback('error', 1); + }, + function(callback){ + assert(false, 'should not be called'); + callback('error2', 2); + } + ], + function(err){ + expect(err).to.equal('error'); + }); + setTimeout(done, 100); + }); + + it('error with reflect', function(done) { + async.series([ + async.reflect(function(callback){ + callback('error', 1); + }), + async.reflect(function(callback){ + callback('error2', 2); + }), + async.reflect(function(callback){ + callback(null, 1); + }) + ], + function(err, results){ + assert(err === null, err + " passed instead of 'null'"); + expect(results).to.eql([ + { error: 'error' }, + { error: 'error2' }, + { value: 1 } + ]); + done(); + }); + }); + + it('no callback', function(done) { + async.series([ + function(callback){callback();}, + function(callback){callback(); done();}, + ]); + }); + + it('object', function(done) { + var call_order = []; + async.series(getFunctionsObject(call_order), function(err, results){ + expect(err).to.equal(null); + expect(results).to.eql({ + one: 1, + two: 2, + three: [3,3] + }); + expect(call_order).to.eql([1,2,3]); + done(); + }); + }); + + it('call in another context', function(done) { + if (isBrowser()) { + // node only test + done(); + return; + } + var vm = require('vm'); + var sandbox = { + async: async, + done: done + }; + + var fn = "(" + (function () { + async.series([function (callback) { + callback(); + }], function (err) { + if (err) { + return done(err); + } + done(); + }); + }).toString() + "())"; + + vm.runInNewContext(fn, sandbox); + }); + + // Issue 10 on github: https://github.com/caolan/async/issues#issue/10 + it('falsy return values', function(done) { + function taskFalse(callback) { + async.nextTick(function() { + callback(null, false); + }); + } + function taskUndefined(callback) { + async.nextTick(function() { + callback(null, undefined); + }); + } + function taskEmpty(callback) { + async.nextTick(function() { + callback(null); + }); + } + function taskNull(callback) { + async.nextTick(function() { + callback(null, null); + }); + } + async.series( + [taskFalse, taskUndefined, taskEmpty, taskNull], + function(err, results) { + expect(results.length).to.equal(4); + assert.strictEqual(results[0], false); + assert.strictEqual(results[1], undefined); + assert.strictEqual(results[2], undefined); + assert.strictEqual(results[3], null); + done(); + } + ); + }); +}); diff --git a/mocha_test/sortBy.js b/mocha_test/sortBy.js new file mode 100644 index 0000000..1636276 --- /dev/null +++ b/mocha_test/sortBy.js @@ -0,0 +1,36 @@ +var async = require('../lib'); +var expect = require('chai').expect; +var assert = require('assert'); + +describe('sortBy', function(){ + it('sortBy', function(done) { + async.sortBy([{a:1},{a:15},{a:6}], function(x, callback){ + setTimeout(function(){callback(null, x.a);}, 0); + }, function(err, result){ + assert(err === null, err + " passed instead of 'null'"); + expect(result).to.eql([{a:1},{a:6},{a:15}]); + done(); + }); + }); + + it('sortBy inverted', function(done) { + async.sortBy([{a:1},{a:15},{a:6}], function(x, callback){ + setTimeout(function(){callback(null, x.a*-1);}, 0); + }, function(err, result){ + expect(result).to.eql([{a:15},{a:6},{a:1}]); + done(); + }); + }); + + it('sortBy error', function(done) { + var error = new Error('asdas'); + async.sortBy([{a:1},{a:15},{a:6}], function(x, callback){ + async.setImmediate(function(){ + callback(error); + }); + }, function(err){ + expect(err).to.equal(error); + done(); + }); + }); +}); diff --git a/mocha_test/support/get_function_object.js b/mocha_test/support/get_function_object.js new file mode 100644 index 0000000..008fd8f --- /dev/null +++ b/mocha_test/support/get_function_object.js @@ -0,0 +1,22 @@ +module.exports = function (call_order) { + return { + one: function(callback) { + setTimeout(function() { + call_order.push(1); + callback(null, 1); + }, 125); + }, + two: function(callback) { + setTimeout(function() { + call_order.push(2); + callback(null, 2); + }, 200); + }, + three: function(callback) { + setTimeout(function() { + call_order.push(3); + callback(null, 3, 3); + }, 50); + } + }; +}; diff --git a/mocha_test/timeout.js b/mocha_test/timeout.js index 7608124..be41283 100644 --- a/mocha_test/timeout.js +++ b/mocha_test/timeout.js @@ -19,6 +19,30 @@ describe('timeout', function () { function(err, results) { expect(err.message).to.equal('Callback function "asyncFn" timed out.'); expect(err.code).to.equal('ETIMEDOUT'); + expect(err.info).to.equal(undefined); + expect(results[0]).to.equal('I didn\'t time out'); + done(); + }); + }); + + it('timeout with series and info', function (done) { + var info = { custom: 'info about callback' }; + async.series([ + async.timeout(function asyncFn(callback) { + setTimeout(function() { + callback(null, 'I didn\'t time out'); + }, 25); + }, 50), + async.timeout(function asyncFn(callback) { + setTimeout(function() { + callback(null, 'I will time out'); + }, 75); + }, 50, info) + ], + function(err, results) { + expect(err.message).to.equal('Callback function "asyncFn" timed out.'); + expect(err.code).to.equal('ETIMEDOUT'); + expect(err.info).to.equal(info); expect(results[0]).to.equal('I didn\'t time out'); done(); }); @@ -40,9 +64,9 @@ describe('timeout', function () { function(err, results) { expect(err.message).to.equal('Callback function "asyncFn" timed out.'); expect(err.code).to.equal('ETIMEDOUT'); + expect(err.info).to.equal(undefined); expect(results[0]).to.equal('I didn\'t time out'); done(); }); }); - }); diff --git a/mocha_test/times.js b/mocha_test/times.js new file mode 100644 index 0000000..ad1dfcd --- /dev/null +++ b/mocha_test/times.js @@ -0,0 +1,90 @@ +var async = require('../lib'); +var expect = require('chai').expect; +var assert = require('assert'); + +describe('times', function() { + + it('times', function(done) { + async.times(5, function(n, next) { + next(null, n); + }, function(err, results) { + assert(err === null, err + " passed instead of 'null'"); + expect(results).to.eql([0,1,2,3,4]); + done(); + }); + }); + + it('times 3', function(done) { + var args = []; + async.times(3, function(n, callback){ + setTimeout(function(){ + args.push(n); + callback(); + }, n * 25); + }, function(err){ + if (err) throw err; + expect(args).to.eql([0,1,2]); + done(); + }); + }); + + it('times 0', function(done) { + async.times(0, function(n, callback){ + assert(false, 'iteratee should not be called'); + callback(); + }, function(err){ + if (err) throw err; + assert(true, 'should call callback'); + }); + setTimeout(done, 25); + }); + + it('times error', function(done) { + async.times(3, function(n, callback){ + callback('error'); + }, function(err){ + expect(err).to.equal('error'); + }); + setTimeout(done, 50); + }); + + it('timesSeries', function(done) { + var call_order = []; + async.timesSeries(5, function(n, callback){ + setTimeout(function(){ + call_order.push(n); + callback(null, n); + }, 100 - n * 10); + }, function(err, results){ + expect(call_order).to.eql([0,1,2,3,4]); + expect(results).to.eql([0,1,2,3,4]); + done(); + }); + }); + + it('timesSeries error', function(done) { + async.timesSeries(5, function(n, callback){ + callback('error'); + }, function(err){ + expect(err).to.equal('error'); + }); + setTimeout(done, 50); + }); + + it('timesLimit', function(done) { + var limit = 2; + var running = 0; + async.timesLimit(5, limit, function (i, next) { + running++; + assert(running <= limit && running > 0, running); + setTimeout(function () { + running--; + next(null, i * 2); + }, (3 - i) * 10); + }, function(err, results){ + assert(err === null, err + " passed instead of 'null'"); + expect(results).to.eql([0, 2, 4, 6, 8]); + done(); + }); + }); +}); diff --git a/mocha_test/transform.js b/mocha_test/transform.js new file mode 100644 index 0000000..5c04f56 --- /dev/null +++ b/mocha_test/transform.js @@ -0,0 +1,54 @@ +var async = require('../lib'); +var expect = require('chai').expect; + +describe('transform', function() { + + it('transform implictly determines memo if not provided', function(done) { + async.transform([1,2,3], function(memo, x, v, callback){ + memo.push(x + 1); + callback(); + }, function(err, result){ + expect(result).to.eql([2, 3, 4]); + done(); + }); + }); + + it('transform async with object memo', function(done) { + async.transform([1,3,2], {}, function(memo, v, k, callback){ + setTimeout(function() { + memo[k] = v; + callback(); + }); + }, function(err, result) { + expect(err).to.equal(null); + expect(result).to.eql({ + 0: 1, + 1: 3, + 2: 2 + }); + done(); + }); + }); + + it('transform iterating object', function(done) { + async.transform({a: 1, b: 3, c: 2}, function(memo, v, k, callback){ + setTimeout(function() { + memo[k] = v + 1; + callback(); + }); + }, function(err, result) { + expect(err).to.equal(null); + expect(result).to.eql({a: 2, b: 4, c: 3}); + done(); + }); + }); + + it('transform error', function(done) { + async.transform([1,2,3], function(a, v, k, callback){ + callback('error'); + }, function(err){ + expect(err).to.equal('error'); + done(); + }); + }); +}); diff --git a/mocha_test/until.js b/mocha_test/until.js new file mode 100644 index 0000000..a738218 --- /dev/null +++ b/mocha_test/until.js @@ -0,0 +1,93 @@ +var async = require('../lib'); +var expect = require('chai').expect; +var assert = require('assert'); + +describe('until', function(){ + it('until', function(done) { + var call_order = []; + var count = 0; + async.until( + function () { + call_order.push(['test', count]); + return (count == 5); + }, + function (cb) { + call_order.push(['iteratee', count]); + count++; + cb(null, count); + }, + function (err, result) { + assert(err === null, err + " passed instead of 'null'"); + expect(result).to.equal(5, 'last result passed through'); + expect(call_order).to.eql([ + ['test', 0], + ['iteratee', 0], ['test', 1], + ['iteratee', 1], ['test', 2], + ['iteratee', 2], ['test', 3], + ['iteratee', 3], ['test', 4], + ['iteratee', 4], ['test', 5], + ]); + expect(count).to.equal(5); + done(); + } + ); + }); + + it('doUntil', function(done) { + var call_order = []; + var count = 0; + async.doUntil( + function (cb) { + call_order.push(['iteratee', count]); + count++; + cb(null, count); + }, + function () { + call_order.push(['test', count]); + return (count == 5); + }, + function (err, result) { + assert(err === null, err + " passed instead of 'null'"); + expect(result).to.equal(5, 'last result passed through'); + expect(call_order).to.eql([ + ['iteratee', 0], ['test', 1], + ['iteratee', 1], ['test', 2], + ['iteratee', 2], ['test', 3], + ['iteratee', 3], ['test', 4], + ['iteratee', 4], ['test', 5] + ]); + expect(count).to.equal(5); + done(); + } + ); + }); + + it('doUntil callback params', function(done) { + var call_order = []; + var count = 0; + async.doUntil( + function (cb) { + call_order.push(['iteratee', count]); + count++; + cb(null, count); + }, + function (c) { + call_order.push(['test', c]); + return (c == 5); + }, + function (err, result) { + if (err) throw err; + expect(result).to.equal(5, 'last result passed through'); + expect(call_order).to.eql([ + ['iteratee', 0], ['test', 1], + ['iteratee', 1], ['test', 2], + ['iteratee', 2], ['test', 3], + ['iteratee', 3], ['test', 4], + ['iteratee', 4], ['test', 5] + ]); + expect(count).to.equal(5); + done(); + } + ); + }); +}); diff --git a/mocha_test/waterfall.js b/mocha_test/waterfall.js index b1d1561..7053b2c 100644 --- a/mocha_test/waterfall.js +++ b/mocha_test/waterfall.js @@ -1,5 +1,6 @@ var async = require('../lib'); var expect = require('chai').expect; +var assert = require('assert'); describe("waterfall", function () { @@ -80,7 +81,7 @@ describe("waterfall", function () { callback('error'); }, function(callback){ - test.ok(false, 'next function should not be called'); + assert(false, 'next function should not be called'); callback(); } ], function(err){ diff --git a/mocha_test/whilst.js b/mocha_test/whilst.js new file mode 100644 index 0000000..a384916 --- /dev/null +++ b/mocha_test/whilst.js @@ -0,0 +1,123 @@ +var async = require('../lib'); +var expect = require('chai').expect; +var assert = require('assert'); + +describe('whilst', function(){ + it('whilst', function(done) { + var call_order = []; + + var count = 0; + async.whilst( + function () { + call_order.push(['test', count]); + return (count < 5); + }, + function (cb) { + call_order.push(['iteratee', count]); + count++; + cb(null, count); + }, + function (err, result) { + assert(err === null, err + " passed instead of 'null'"); + expect(result).to.equal(5, 'last result passed through'); + expect(call_order).to.eql([ + ['test', 0], + ['iteratee', 0], ['test', 1], + ['iteratee', 1], ['test', 2], + ['iteratee', 2], ['test', 3], + ['iteratee', 3], ['test', 4], + ['iteratee', 4], ['test', 5], + ]); + expect(count).to.equal(5); + done(); + } + ); + }); + + it('whilst optional callback', function(done) { + var counter = 0; + async.whilst( + function () { return counter < 2; }, + function (cb) { + counter++; + cb(); + } + ); + expect(counter).to.equal(2); + done(); + }); + + it('doWhilst', function(done) { + var call_order = []; + + var count = 0; + async.doWhilst( + function (cb) { + call_order.push(['iteratee', count]); + count++; + cb(null, count); + }, + function () { + call_order.push(['test', count]); + return (count < 5); + }, + function (err, result) { + assert(err === null, err + " passed instead of 'null'"); + expect(result).to.equal(5, 'last result passed through'); + expect(call_order).to.eql([ + ['iteratee', 0], ['test', 1], + ['iteratee', 1], ['test', 2], + ['iteratee', 2], ['test', 3], + ['iteratee', 3], ['test', 4], + ['iteratee', 4], ['test', 5] + ]); + expect(count).to.equal(5); + done(); + } + ); + }); + + it('doWhilst callback params', function(done) { + var call_order = []; + var count = 0; + async.doWhilst( + function (cb) { + call_order.push(['iteratee', count]); + count++; + cb(null, count); + }, + function (c) { + call_order.push(['test', c]); + return (c < 5); + }, + function (err, result) { + if (err) throw err; + expect(result).to.equal(5, 'last result passed through'); + expect(call_order).to.eql([ + ['iteratee', 0], ['test', 1], + ['iteratee', 1], ['test', 2], + ['iteratee', 2], ['test', 3], + ['iteratee', 3], ['test', 4], + ['iteratee', 4], ['test', 5] + ]); + expect(count).to.equal(5); + done(); + } + ); + }); + + it('doWhilst - error', function(done) { + var error = new Error('asdas'); + + async.doWhilst( + function (cb) { + cb(error); + }, + function () {}, + function (err) { + expect(err).to.equal(error); + done(); + } + ); + }); +}); diff --git a/package.json b/package.json index 6c8eb02..ae8cbcd 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "async", "description": "Higher-order functions and common patterns for asynchronous code", - "version": "2.0.0-rc.3", + "version": "2.0.0-rc.4", "main": "dist/async.js", "author": "Caolan McMahon", "repository": { @@ -44,7 +44,6 @@ "karma-mocha-reporter": "^1.0.2", "mocha": "^2.2.5", "native-promise-only": "^0.8.0-a", - "nodeunit": ">0.0.0", "nyc": "^2.1.0", "recursive-readdir": "^1.3.0", "rimraf": "^2.5.0", @@ -59,12 +58,11 @@ "scripts": { "coverage": "nyc npm test && nyc report", "coveralls": "nyc npm test && nyc report --reporter=text-lcov | coveralls", - "lint": "jshint lib/ test/ mocha_test/ perf/memory.js perf/suites.js perf/benchmark.js support/ karma.conf.js && jscs lib/ test/ mocha_test/ perf/memory.js perf/suites.js perf/benchmark.js support/ karma.conf.js", + "lint": "jshint lib/ mocha_test/ perf/memory.js perf/suites.js perf/benchmark.js support/ karma.conf.js && jscs lib/ mocha_test/ perf/memory.js perf/suites.js perf/benchmark.js support/ karma.conf.js", "mocha-browser-test": "karma start", "mocha-node-test": "mocha mocha_test/ --compilers js:babel-core/register", "mocha-test": "npm run mocha-node-test && npm run mocha-browser-test", - "nodeunit-test": "nodeunit test/test-async.js", - "test": "npm run-script lint && npm run nodeunit-test && npm run mocha-node-test" + "test": "npm run-script lint && npm run mocha-node-test" }, "license": "MIT", "jam": { diff --git a/support/xyz.sh b/support/xyz.sh index e178eee..cb92577 100755 --- a/support/xyz.sh +++ b/support/xyz.sh @@ -167,5 +167,4 @@ run "git commit --message '$message'" run "git tag --annotate '$tag' --message '$message'" run "git push '$repo' 'refs/heads/$branch' 'refs/tags/$tag'" -#cd build/ -#run "npm pack" +# npm publish is managed by the Makefile diff --git a/test/test-async.js b/test/test-async.js deleted file mode 100755 index b310f70..0000000 --- a/test/test-async.js +++ /dev/null @@ -1,2751 +0,0 @@ -/** - * NOTE: We are in the process of migrating these tests to Mocha. If you are - * adding a new test, please create a new spec file in mocha_tests/ - */ - -require('babel-core/register'); -var async = require('../lib'); - -if (!Function.prototype.bind) { - Function.prototype.bind = function (thisArg) { - var args = Array.prototype.slice.call(arguments, 1); - var self = this; - return function () { - self.apply(thisArg, args.concat(Array.prototype.slice.call(arguments))); - }; - }; -} - -function eachIteratee(args, x, callback) { - setTimeout(function(){ - args.push(x); - callback(); - }, x*25); -} - -function forEachOfIteratee(args, value, key, callback) { - setTimeout(function(){ - args.push(key, value); - callback(); - }, value*25); -} - -function mapIteratee(call_order, x, callback) { - setTimeout(function(){ - call_order.push(x); - callback(null, x*2); - }, x*25); -} - -function eachNoCallbackIteratee(test, x, callback) { - test.equal(x, 1); - callback(); - test.done(); -} - -function forEachOfNoCallbackIteratee(test, x, key, callback) { - test.equal(x, 1); - test.equal(key, "a"); - callback(); - test.done(); -} - -function getFunctionsObject(call_order) { - return { - one: function(callback){ - setTimeout(function(){ - call_order.push(1); - callback(null, 1); - }, 125); - }, - two: function(callback){ - setTimeout(function(){ - call_order.push(2); - callback(null, 2); - }, 200); - }, - three: function(callback){ - setTimeout(function(){ - call_order.push(3); - callback(null, 3,3); - }, 50); - } - }; -} - -function isBrowser() { - return (typeof process === "undefined") || - (process + "" !== "[object process]"); // browserify -} - - -exports['seq'] = function (test) { - test.expect(5); - var add2 = function (n, cb) { - test.equal(n, 3); - setTimeout(function () { - cb(null, n + 2); - }, 50); - }; - var mul3 = function (n, cb) { - test.equal(n, 5); - setTimeout(function () { - cb(null, n * 3); - }, 15); - }; - var add1 = function (n, cb) { - test.equal(n, 15); - setTimeout(function () { - cb(null, n + 1); - }, 100); - }; - var add2mul3add1 = async.seq(add2, mul3, add1); - add2mul3add1(3, function (err, result) { - if (err) { - return test.done(err); - } - test.ok(err === null, err + " passed instead of 'null'"); - test.equal(result, 16); - test.done(); - }); -}; - -exports['seq error'] = function (test) { - test.expect(3); - var testerr = new Error('test'); - - var add2 = function (n, cb) { - test.equal(n, 3); - setTimeout(function () { - cb(null, n + 2); - }, 50); - }; - var mul3 = function (n, cb) { - test.equal(n, 5); - setTimeout(function () { - cb(testerr); - }, 15); - }; - var add1 = function (n, cb) { - test.ok(false, 'add1 should not get called'); - setTimeout(function () { - cb(null, n + 1); - }, 100); - }; - var add2mul3add1 = async.seq(add2, mul3, add1); - add2mul3add1(3, function (err) { - test.equal(err, testerr); - test.done(); - }); -}; - -exports['seq binding'] = function (test) { - test.expect(4); - var testcontext = {name: 'foo'}; - - var add2 = function (n, cb) { - test.equal(this, testcontext); - setTimeout(function () { - cb(null, n + 2); - }, 50); - }; - var mul3 = function (n, cb) { - test.equal(this, testcontext); - setTimeout(function () { - cb(null, n * 3); - }, 15); - }; - var add2mul3 = async.seq(add2, mul3); - add2mul3.call(testcontext, 3, function (err, result) { - if (err) { - return test.done(err); - } - test.equal(this, testcontext); - test.equal(result, 15); - test.done(); - }); -}; - -exports['seq without callback'] = function (test) { - test.expect(2); - var testcontext = {name: 'foo'}; - - var add2 = function (n, cb) { - test.equal(this, testcontext); - setTimeout(function () { - cb(null, n + 2); - }, 50); - }; - var mul3 = function () { - test.equal(this, testcontext); - setTimeout(function () { - test.done(); - }, 15); - }; - var add2mul3 = async.seq(add2, mul3); - add2mul3.call(testcontext, 3); -}; - - -exports['parallel'] = function(test){ - var call_order = []; - async.parallel([ - function(callback){ - setTimeout(function(){ - call_order.push(1); - callback(null, 1); - }, 50); - }, - function(callback){ - setTimeout(function(){ - call_order.push(2); - callback(null, 2); - }, 100); - }, - function(callback){ - setTimeout(function(){ - call_order.push(3); - callback(null, 3,3); - }, 25); - } - ], - function(err, results){ - test.ok(err === null, err + " passed instead of 'null'"); - test.same(call_order, [3,1,2]); - test.same(results, [1,2,[3,3]]); - test.done(); - }); -}; - -exports['parallel empty array'] = function(test){ - async.parallel([], function(err, results){ - test.ok(err === null, err + " passed instead of 'null'"); - test.same(results, []); - test.done(); - }); -}; - -exports['parallel error'] = function(test){ - async.parallel([ - function(callback){ - callback('error', 1); - }, - function(callback){ - callback('error2', 2); - } - ], - function(err){ - test.equals(err, 'error'); - }); - setTimeout(test.done, 100); -}; - -exports['parallel no callback'] = function(test){ - async.parallel([ - function(callback){callback();}, - function(callback){callback(); test.done();}, - ]); -}; - -exports['parallel object'] = function(test){ - var call_order = []; - async.parallel(getFunctionsObject(call_order), function(err, results){ - test.equals(err, null); - test.same(call_order, [3,1,2]); - test.same(results, { - one: 1, - two: 2, - three: [3,3] - }); - test.done(); - }); -}; - -// Issue 10 on github: https://github.com/caolan/async/issues#issue/10 -exports['paralel falsy return values'] = function (test) { - function taskFalse(callback) { - async.nextTick(function() { - callback(null, false); - }); - } - function taskUndefined(callback) { - async.nextTick(function() { - callback(null, undefined); - }); - } - function taskEmpty(callback) { - async.nextTick(function() { - callback(null); - }); - } - function taskNull(callback) { - async.nextTick(function() { - callback(null, null); - }); - } - async.parallel( - [taskFalse, taskUndefined, taskEmpty, taskNull], - function(err, results) { - test.equal(results.length, 4); - test.strictEqual(results[0], false); - test.strictEqual(results[1], undefined); - test.strictEqual(results[2], undefined); - test.strictEqual(results[3], null); - test.done(); - } - ); -}; - - -exports['parallel limit'] = function(test){ - var call_order = []; - async.parallelLimit([ - function(callback){ - setTimeout(function(){ - call_order.push(1); - callback(null, 1); - }, 50); - }, - function(callback){ - setTimeout(function(){ - call_order.push(2); - callback(null, 2); - }, 100); - }, - function(callback){ - setTimeout(function(){ - call_order.push(3); - callback(null, 3,3); - }, 25); - } - ], - 2, - function(err, results){ - test.ok(err === null, err + " passed instead of 'null'"); - test.same(call_order, [1,3,2]); - test.same(results, [1,2,[3,3]]); - test.done(); - }); -}; - -exports['parallel limit empty array'] = function(test){ - async.parallelLimit([], 2, function(err, results){ - test.ok(err === null, err + " passed instead of 'null'"); - test.same(results, []); - test.done(); - }); -}; - -exports['parallel limit error'] = function(test){ - async.parallelLimit([ - function(callback){ - callback('error', 1); - }, - function(callback){ - callback('error2', 2); - } - ], - 1, - function(err){ - test.equals(err, 'error'); - }); - setTimeout(test.done, 100); -}; - -exports['parallel limit no callback'] = function(test){ - async.parallelLimit([ - function(callback){callback();}, - function(callback){callback(); test.done();}, - ], 1); -}; - -exports['parallel limit object'] = function(test){ - var call_order = []; - async.parallelLimit(getFunctionsObject(call_order), 2, function(err, results){ - test.equals(err, null); - test.same(call_order, [1,3,2]); - test.same(results, { - one: 1, - two: 2, - three: [3,3] - }); - test.done(); - }); -}; - -exports['parallel call in another context'] = function(test) { - if (isBrowser()) { - // node only test - test.done(); - return; - } - var vm = require('vm'); - var sandbox = { - async: async, - test: test - }; - - var fn = "(" + (function () { - async.parallel([function (callback) { - callback(); - }], function (err) { - if (err) { - return test.done(err); - } - test.done(); - }); - }).toString() + "())"; - - vm.runInNewContext(fn, sandbox); -}; - -exports['parallel error with reflect'] = function(test){ - async.parallel([ - async.reflect(function(callback){ - callback('error', 1); - }), - async.reflect(function(callback){ - callback('error2', 2); - }), - async.reflect(function(callback){ - callback(null, 2); - }) - ], - function(err, results){ - test.ok(err === null, err + " passed instead of 'null'"); - test.same(results, [ - { error: 'error' }, - { error: 'error2' }, - { value: 2 } - ]); - test.done(); - }); -}; - -exports['parallel does not continue replenishing after error'] = function (test) { - var started = 0; - var arr = [ - funcToCall, - funcToCall, - funcToCall, - funcToCall, - funcToCall, - funcToCall, - funcToCall, - funcToCall, - funcToCall, - ]; - var delay = 10; - var limit = 3; - var maxTime = 10 * arr.length; - function funcToCall(callback) { - started ++; - if (started === 3) { - return callback(new Error ("Test Error")); - } - setTimeout(function(){ - callback(); - }, delay); - } - - async.parallelLimit(arr, limit, function(){}); - - setTimeout(function(){ - test.equal(started, 3); - test.done(); - }, maxTime); -}; - - -exports['series'] = { - - 'series': function(test){ - var call_order = []; - async.series([ - function(callback){ - setTimeout(function(){ - call_order.push(1); - callback(null, 1); - }, 25); - }, - function(callback){ - setTimeout(function(){ - call_order.push(2); - callback(null, 2); - }, 50); - }, - function(callback){ - setTimeout(function(){ - call_order.push(3); - callback(null, 3,3); - }, 15); - } - ], - function(err, results){ - test.ok(err === null, err + " passed instead of 'null'"); - test.same(results, [1,2,[3,3]]); - test.same(call_order, [1,2,3]); - test.done(); - }); -}, - - 'with reflect': function(test){ - var call_order = []; - async.series([ - async.reflect(function(callback){ - setTimeout(function(){ - call_order.push(1); - callback(null, 1); - }, 25); - }), - async.reflect(function(callback){ - setTimeout(function(){ - call_order.push(2); - callback(null, 2); - }, 50); - }), - async.reflect(function(callback){ - setTimeout(function(){ - call_order.push(3); - callback(null, 3,3); - }, 15); - }) - ], - function(err, results){ - test.ok(err === null, err + " passed instead of 'null'"); - test.deepEqual(results, [ - { value: 1 }, - { value: 2 }, - { value: [3,3] } - ]); - test.same(call_order, [1,2,3]); - test.done(); - }); -}, - - 'empty array': function(test){ - async.series([], function(err, results){ - test.equals(err, null); - test.same(results, []); - test.done(); - }); -}, - - 'error': function(test){ - test.expect(1); - async.series([ - function(callback){ - callback('error', 1); - }, - function(callback){ - test.ok(false, 'should not be called'); - callback('error2', 2); - } - ], - function(err){ - test.equals(err, 'error'); - }); - setTimeout(test.done, 100); -}, - - 'error with reflect': function(test){ - test.expect(2); - async.series([ - async.reflect(function(callback){ - callback('error', 1); - }), - async.reflect(function(callback){ - callback('error2', 2); - }), - async.reflect(function(callback){ - callback(null, 1); - }) - ], - function(err, results){ - test.ok(err === null, err + " passed instead of 'null'"); - test.deepEqual(results, [ - { error: 'error' }, - { error: 'error2' }, - { value: 1 } - ]); - test.done(); - }); -}, - - 'no callback': function(test){ - async.series([ - function(callback){callback();}, - function(callback){callback(); test.done();}, - ]); -}, - - 'object': function(test){ - var call_order = []; - async.series(getFunctionsObject(call_order), function(err, results){ - test.equals(err, null); - test.same(results, { - one: 1, - two: 2, - three: [3,3] - }); - test.same(call_order, [1,2,3]); - test.done(); - }); -}, - - 'call in another context': function(test) { - if (isBrowser()) { - // node only test - test.done(); - return; - } - var vm = require('vm'); - var sandbox = { - async: async, - test: test - }; - - var fn = "(" + (function () { - async.series([function (callback) { - callback(); - }], function (err) { - if (err) { - return test.done(err); - } - test.done(); - }); - }).toString() + "())"; - - vm.runInNewContext(fn, sandbox); -}, - - // Issue 10 on github: https://github.com/caolan/async/issues#issue/10 - 'falsy return values': function (test) { - function taskFalse(callback) { - async.nextTick(function() { - callback(null, false); - }); - } - function taskUndefined(callback) { - async.nextTick(function() { - callback(null, undefined); - }); - } - function taskEmpty(callback) { - async.nextTick(function() { - callback(null); - }); - } - function taskNull(callback) { - async.nextTick(function() { - callback(null, null); - }); - } - async.series( - [taskFalse, taskUndefined, taskEmpty, taskNull], - function(err, results) { - test.equal(results.length, 4); - test.strictEqual(results[0], false); - test.strictEqual(results[1], undefined); - test.strictEqual(results[2], undefined); - test.strictEqual(results[3], null); - test.done(); - } - ); -} - -}; - - -exports['iterator'] = function(test){ - var call_order = []; - var iterator = async.iterator([ - function(){call_order.push(1);}, - function(arg1){ - test.equals(arg1, 'arg1'); - call_order.push(2); - }, - function(arg1, arg2){ - test.equals(arg1, 'arg1'); - test.equals(arg2, 'arg2'); - call_order.push(3); - } - ]); - iterator(); - test.same(call_order, [1]); - var iterator2 = iterator(); - test.same(call_order, [1,1]); - var iterator3 = iterator2('arg1'); - test.same(call_order, [1,1,2]); - var iterator4 = iterator3('arg1', 'arg2'); - test.same(call_order, [1,1,2,3]); - test.equals(iterator4, undefined); - test.done(); -}; - -exports['iterator empty array'] = function(test){ - var iterator = async.iterator([]); - test.equals(iterator(), undefined); - test.equals(iterator.next(), undefined); - test.done(); -}; - -exports['iterator.next'] = function(test){ - var call_order = []; - var iterator = async.iterator([ - function(){call_order.push(1);}, - function(arg1){ - test.equals(arg1, 'arg1'); - call_order.push(2); - }, - function(arg1, arg2){ - test.equals(arg1, 'arg1'); - test.equals(arg2, 'arg2'); - call_order.push(3); - } - ]); - var fn = iterator.next(); - var iterator2 = fn('arg1'); - test.same(call_order, [2]); - iterator2('arg1','arg2'); - test.same(call_order, [2,3]); - test.equals(iterator2.next(), undefined); - test.done(); -}; - -exports['each'] = function(test){ - var args = []; - async.each([1,3,2], eachIteratee.bind(this, args), function(err){ - test.ok(err === null, err + " passed instead of 'null'"); - test.same(args, [1,2,3]); - test.done(); - }); -}; - -exports['each extra callback'] = function(test){ - var count = 0; - async.each([1,3,2], function(val, callback) { - count++; - var done = count == 3; - callback(); - test.throws(callback); - if (done) { - test.done(); - } - }); -}; - -exports['each empty array'] = function(test){ - test.expect(1); - async.each([], function(x, callback){ - test.ok(false, 'iteratee should not be called'); - callback(); - }, function(err){ - if (err) throw err; - test.ok(true, 'should call callback'); - }); - setTimeout(test.done, 25); -}; - - -exports['each empty array, with other property on the array'] = function(test){ - test.expect(1); - var myArray = []; - myArray.myProp = "anything"; - async.each(myArray, function(x, callback){ - test.ok(false, 'iteratee should not be called'); - callback(); - }, function(err){ - if (err) throw err; - test.ok(true, 'should call callback'); - }); - setTimeout(test.done, 25); -}; - - -exports['each error'] = function(test){ - test.expect(1); - async.each([1,2,3], function(x, callback){ - callback('error'); - }, function(err){ - test.equals(err, 'error'); - }); - setTimeout(test.done, 50); -}; - -exports['each no callback'] = function(test){ - async.each([1], eachNoCallbackIteratee.bind(this, test)); -}; - -exports['forEach alias'] = function (test) { - test.strictEqual(async.each, async.forEach); - test.done(); -}; - -exports['forEachOf'] = function(test){ - var args = []; - async.forEachOf({ a: 1, b: 2 }, forEachOfIteratee.bind(this, args), function(err){ - test.ok(err === null, err + " passed instead of 'null'"); - test.same(args, ["a", 1, "b", 2]); - test.done(); - }); -}; - -exports['forEachOf - instant resolver'] = function(test){ - test.expect(1); - var args = []; - async.forEachOf({ a: 1, b: 2 }, function(x, k, cb) { - args.push(k, x); - cb(); - }, function(){ - // ensures done callback isn't called before all items iterated - test.same(args, ["a", 1, "b", 2]); - test.done(); - }); -}; - -exports['forEachOf empty object'] = function(test){ - test.expect(1); - async.forEachOf({}, function(value, key, callback){ - test.ok(false, 'iteratee should not be called'); - callback(); - }, function(err) { - if (err) throw err; - test.ok(true, 'should call callback'); - }); - setTimeout(test.done, 25); -}; - -exports['forEachOf empty array'] = function(test){ - test.expect(1); - async.forEachOf([], function(value, key, callback){ - test.ok(false, 'iteratee should not be called'); - callback(); - }, function(err) { - if (err) throw err; - test.ok(true, 'should call callback'); - }); - setTimeout(test.done, 25); -}; - -exports['forEachOf error'] = function(test){ - test.expect(1); - async.forEachOf({ a: 1, b: 2 }, function(value, key, callback) { - callback('error'); - }, function(err){ - test.equals(err, 'error'); - }); - setTimeout(test.done, 50); -}; - -exports['forEachOf no callback'] = function(test){ - async.forEachOf({ a: 1 }, forEachOfNoCallbackIteratee.bind(this, test)); -}; - -exports['eachOf alias'] = function(test){ - test.equals(async.eachOf, async.forEachOf); - test.done(); -}; - -exports['forEachOf with array'] = function(test){ - var args = []; - async.forEachOf([ "a", "b" ], forEachOfIteratee.bind(this, args), function(err){ - if (err) throw err; - test.same(args, [0, "a", 1, "b"]); - test.done(); - }); -}; - -exports['forEachOf with Set (iterators)'] = function(test){ - if (typeof Set !== 'function') - return test.done(); - - var args = []; - var set = new Set(); - set.add("a"); - set.add("b"); - async.forEachOf(set, forEachOfIteratee.bind(this, args), function(err){ - if (err) throw err; - test.same(args, [0, "a", 1, "b"]); - test.done(); - }); -}; - -exports['forEachOf with Map (iterators)'] = function(test){ - if (typeof Map !== 'function') - return test.done(); - - var args = []; - var map = new Map(); - map.set(1, "a"); - map.set(2, "b"); - async.forEachOf(map, forEachOfIteratee.bind(this, args), function(err){ - if (err) throw err; - test.same(args, [0, [1, "a"], 1, [2, "b"]]); - test.done(); - }); -}; - -exports['eachSeries'] = function(test){ - var args = []; - async.eachSeries([1,3,2], eachIteratee.bind(this, args), function(err){ - test.ok(err === null, err + " passed instead of 'null'"); - test.same(args, [1,3,2]); - test.done(); - }); -}; - -exports['eachSeries empty array'] = function(test){ - test.expect(1); - async.eachSeries([], function(x, callback){ - test.ok(false, 'iteratee should not be called'); - callback(); - }, function(err){ - if (err) throw err; - test.ok(true, 'should call callback'); - }); - setTimeout(test.done, 25); -}; - -exports['eachSeries array modification'] = function(test) { - test.expect(1); - var arr = [1, 2, 3, 4]; - async.eachSeries(arr, function (x, callback) { - async.setImmediate(callback); - }, function () { - test.ok(true, 'should call callback'); - }); - - arr.pop(); - arr.splice(0, 1); - - setTimeout(test.done, 50); -}; - -// bug #782. Remove in next major release -exports['eachSeries single item'] = function (test) { - test.expect(1); - var sync = true; - async.eachSeries([1], function (i, cb) { - cb(null); - }, function () { - test.ok(sync, "callback not called on same tick"); - }); - sync = false; - test.done(); -}; - -// bug #782. Remove in next major release -exports['eachSeries single item'] = function (test) { - test.expect(1); - var sync = true; - async.eachSeries([1], function (i, cb) { - cb(null); - }, function () { - test.ok(sync, "callback not called on same tick"); - }); - sync = false; - test.done(); -}; - -exports['eachSeries error'] = function(test){ - test.expect(2); - var call_order = []; - async.eachSeries([1,2,3], function(x, callback){ - call_order.push(x); - callback('error'); - }, function(err){ - test.same(call_order, [1]); - test.equals(err, 'error'); - }); - setTimeout(test.done, 50); -}; - -exports['eachSeries no callback'] = function(test){ - async.eachSeries([1], eachNoCallbackIteratee.bind(this, test)); -}; - - -exports['eachLimit'] = function(test){ - var args = []; - var arr = [0,1,2,3,4,5,6,7,8,9]; - async.eachLimit(arr, 2, function(x,callback){ - setTimeout(function(){ - args.push(x); - callback(); - }, x*5); - }, function(err){ - test.ok(err === null, err + " passed instead of 'null'"); - test.same(args, arr); - test.done(); - }); -}; - -exports['eachLimit empty array'] = function(test){ - test.expect(1); - async.eachLimit([], 2, function(x, callback){ - test.ok(false, 'iteratee should not be called'); - callback(); - }, function(err){ - if (err) throw err; - test.ok(true, 'should call callback'); - }); - setTimeout(test.done, 25); -}; - -exports['eachLimit limit exceeds size'] = function(test){ - var args = []; - var arr = [0,1,2,3,4,5,6,7,8,9]; - async.eachLimit(arr, 20, eachIteratee.bind(this, args), function(err){ - if (err) throw err; - test.same(args, arr); - test.done(); - }); -}; - -exports['eachLimit limit equal size'] = function(test){ - var args = []; - var arr = [0,1,2,3,4,5,6,7,8,9]; - async.eachLimit(arr, 10, eachIteratee.bind(this, args), function(err){ - if (err) throw err; - test.same(args, arr); - test.done(); - }); -}; - -exports['eachLimit zero limit'] = function(test){ - test.expect(1); - async.eachLimit([0,1,2,3,4,5], 0, function(x, callback){ - test.ok(false, 'iteratee should not be called'); - callback(); - }, function(err){ - if (err) throw err; - test.ok(true, 'should call callback'); - }); - setTimeout(test.done, 25); -}; - -exports['eachLimit error'] = function(test){ - test.expect(2); - var arr = [0,1,2,3,4,5,6,7,8,9]; - var call_order = []; - - async.eachLimit(arr, 3, function(x, callback){ - call_order.push(x); - if (x === 2) { - callback('error'); - } - }, function(err){ - test.same(call_order, [0,1,2]); - test.equals(err, 'error'); - }); - setTimeout(test.done, 25); -}; - -exports['eachLimit no callback'] = function(test){ - async.eachLimit([1], 1, eachNoCallbackIteratee.bind(this, test)); -}; - -exports['eachLimit synchronous'] = function(test){ - var args = []; - var arr = [0,1,2]; - async.eachLimit(arr, 5, function(x,callback){ - args.push(x); - callback(); - }, function(err){ - if (err) throw err; - test.same(args, arr); - test.done(); - }); -}; - - -exports['eachLimit does not continue replenishing after error'] = function (test) { - var started = 0; - var arr = [0,1,2,3,4,5,6,7,8,9]; - var delay = 10; - var limit = 3; - var maxTime = 10 * arr.length; - - async.eachLimit(arr, limit, function(x, callback) { - started ++; - if (started === 3) { - return callback(new Error ("Test Error")); - } - setTimeout(function(){ - callback(); - }, delay); - }, function(){}); - - setTimeout(function(){ - test.equal(started, 3); - test.done(); - }, maxTime); -}; - -exports['forEachSeries alias'] = function (test) { - test.strictEqual(async.eachSeries, async.forEachSeries); - test.done(); -}; - -exports['forEachOfSeries'] = function(test){ - var args = []; - async.forEachOfSeries({ a: 1, b: 2 }, forEachOfIteratee.bind(this, args), function(err){ - test.ok(err === null, err + " passed instead of 'null'"); - test.same(args, [ "a", 1, "b", 2 ]); - test.done(); - }); -}; - -exports['forEachOfSeries empty object'] = function(test){ - test.expect(1); - async.forEachOfSeries({}, function(x, callback){ - test.ok(false, 'iteratee should not be called'); - callback(); - }, function(err){ - if (err) throw err; - test.ok(true, 'should call callback'); - }); - setTimeout(test.done, 25); -}; - -exports['forEachOfSeries error'] = function(test){ - test.expect(2); - var call_order = []; - async.forEachOfSeries({ a: 1, b: 2 }, function(value, key, callback){ - call_order.push(value, key); - callback('error'); - }, function(err){ - test.same(call_order, [ 1, "a" ]); - test.equals(err, 'error'); - }); - setTimeout(test.done, 50); -}; - -exports['forEachOfSeries no callback'] = function(test){ - async.forEachOfSeries({ a: 1 }, forEachOfNoCallbackIteratee.bind(this, test)); -}; - -exports['forEachOfSeries with array'] = function(test){ - var args = []; - async.forEachOfSeries([ "a", "b" ], forEachOfIteratee.bind(this, args), function(err){ - if (err) throw err; - test.same(args, [ 0, "a", 1, "b" ]); - test.done(); - }); -}; - -exports['forEachOfSeries with Set (iterators)'] = function(test){ - if (typeof Set !== 'function') - return test.done(); - - var args = []; - var set = new Set(); - set.add("a"); - set.add("b"); - async.forEachOfSeries(set, forEachOfIteratee.bind(this, args), function(err){ - if (err) throw err; - test.same(args, [0, "a", 1, "b"]); - test.done(); - }); -}; - -exports['forEachOfSeries with Map (iterators)'] = function(test){ - if (typeof Map !== 'function') - return test.done(); - - var args = []; - var map = new Map(); - map.set(1, "a"); - map.set(2, "b"); - async.forEachOfSeries(map, forEachOfIteratee.bind(this, args), function(err){ - if (err) throw err; - test.same(args, [0, [1, "a"], 1, [2, "b"]]); - test.done(); - }); -}; - -exports['eachOfLimit alias'] = function(test){ - test.equals(async.eachOfLimit, async.forEachOfLimit); - test.done(); -}; - - -exports['eachOfSeries alias'] = function(test){ - test.equals(async.eachOfSeries, async.forEachOfSeries); - test.done(); -}; - -exports['forEachLimit alias'] = function (test) { - test.strictEqual(async.eachLimit, async.forEachLimit); - test.done(); -}; - -exports['forEachOfLimit'] = function(test){ - var args = []; - var obj = { a: 1, b: 2, c: 3, d: 4 }; - async.forEachOfLimit(obj, 2, function(value, key, callback){ - setTimeout(function(){ - args.push(value, key); - callback(); - }, value * 5); - }, function(err){ - test.ok(err === null, err + " passed instead of 'null'"); - test.same(args, [ 1, "a", 2, "b", 3, "c", 4, "d" ]); - test.done(); - }); -}; - -exports['forEachOfLimit empty object'] = function(test){ - test.expect(1); - async.forEachOfLimit({}, 2, function(value, key, callback){ - test.ok(false, 'iteratee should not be called'); - callback(); - }, function(err){ - if (err) throw err; - test.ok(true, 'should call callback'); - }); - setTimeout(test.done, 25); -}; - -exports['forEachOfLimit limit exceeds size'] = function(test){ - var args = []; - var obj = { a: 1, b: 2, c: 3, d: 4, e: 5 }; - async.forEachOfLimit(obj, 10, forEachOfIteratee.bind(this, args), function(err){ - if (err) throw err; - test.same(args, [ "a", 1, "b", 2, "c", 3, "d", 4, "e", 5 ]); - test.done(); - }); -}; - -exports['forEachOfLimit limit equal size'] = function(test){ - var args = []; - var obj = { a: 1, b: 2, c: 3, d: 4, e: 5 }; - async.forEachOfLimit(obj, 5, forEachOfIteratee.bind(this, args), function(err){ - if (err) throw err; - test.same(args, [ "a", 1, "b", 2, "c", 3, "d", 4, "e", 5 ]); - test.done(); - }); -}; - -exports['forEachOfLimit zero limit'] = function(test){ - test.expect(1); - async.forEachOfLimit({ a: 1, b: 2 }, 0, function(x, callback){ - test.ok(false, 'iteratee should not be called'); - callback(); - }, function(err){ - if (err) throw err; - test.ok(true, 'should call callback'); - }); - setTimeout(test.done, 25); -}; - -exports['forEachOfLimit error'] = function(test){ - test.expect(2); - var obj = { a: 1, b: 2, c: 3, d: 4, e: 5 }; - var call_order = []; - - async.forEachOfLimit(obj, 3, function(value, key, callback){ - call_order.push(value, key); - if (value === 2) { - callback('error'); - } - }, function(err){ - test.same(call_order, [ 1, "a", 2, "b" ]); - test.equals(err, 'error'); - }); - setTimeout(test.done, 25); -}; - -exports['forEachOfLimit no callback'] = function(test){ - async.forEachOfLimit({ a: 1 }, 1, forEachOfNoCallbackIteratee.bind(this, test)); -}; - -exports['forEachOfLimit synchronous'] = function(test){ - var args = []; - var obj = { a: 1, b: 2 }; - async.forEachOfLimit(obj, 5, forEachOfIteratee.bind(this, args), function(err){ - if (err) throw err; - test.same(args, [ "a", 1, "b", 2 ]); - test.done(); - }); -}; - -exports['forEachOfLimit with array'] = function(test){ - var args = []; - var arr = [ "a", "b" ]; - async.forEachOfLimit(arr, 1, forEachOfIteratee.bind(this, args), function (err) { - if (err) throw err; - test.same(args, [ 0, "a", 1, "b" ]); - test.done(); - }); -}; - -exports['forEachOfLimit with Set (iterators)'] = function(test){ - if (typeof Set !== 'function') - return test.done(); - - var args = []; - var set = new Set(); - set.add("a"); - set.add("b"); - async.forEachOfLimit(set, 1, forEachOfIteratee.bind(this, args), function(err){ - if (err) throw err; - test.same(args, [0, "a", 1, "b"]); - test.done(); - }); -}; - -exports['forEachOfLimit with Map (iterators)'] = function(test){ - if (typeof Map !== 'function') - return test.done(); - - var args = []; - var map = new Map(); - map.set(1, "a"); - map.set(2, "b"); - async.forEachOfLimit(map, 1, forEachOfIteratee.bind(this, args), function(err){ - if (err) throw err; - test.same(args, [0, [1, "a"], 1, [2, "b"]]); - test.done(); - }); -}; - -exports['map'] = { - - 'basic': function(test){ - var call_order = []; - async.map([1,3,2], mapIteratee.bind(this, call_order), function(err, results){ - test.ok(err === null, err + " passed instead of 'null'"); - test.same(call_order, [1,2,3]); - test.same(results, [2,6,4]); - test.done(); - }); -}, - - 'with reflect': function(test){ - var call_order = []; - async.map([1,3,2], async.reflect(function(item, cb) { - setTimeout(function(){ - call_order.push(item); - cb(null, item*2); - }, item*25); - }), function(err, results){ - test.ok(err === null, err + " passed instead of 'null'"); - test.same(call_order, [1,2,3]); - test.same(results, [ - { value: 2 }, - { value: 6 }, - { value: 4 } - ]); - test.done(); - }); -}, - - 'error with reflect': function(test){ - var call_order = []; - async.map([-1,1,3,2], async.reflect(function(item, cb) { - setTimeout(function(){ - call_order.push(item); - if (item < 0) { - cb('number less then zero'); - } else { - cb(null, item*2); - } - - }, item*25); - }), function(err, results){ - test.ok(err === null, err + " passed instead of 'null'"); - test.same(call_order, [-1,1,2,3]); - test.same(results, [ - { error: 'number less then zero' }, - { value: 2 }, - { value: 6 }, - { value: 4 } - ]); - test.done(); - }); -}, - - 'map original untouched': function(test){ - var a = [1,2,3]; - async.map(a, function(x, callback){ - callback(null, x*2); - }, function(err, results){ - test.same(results, [2,4,6]); - test.same(a, [1,2,3]); - test.done(); - }); -}, - - 'map without main callback': function(test){ - var a = [1,2,3]; - var r = []; - async.map(a, function(x, callback){ - r.push(x); - var done = r.length == a.length; - callback(null); - if (done) { - test.same(r, a); - test.done(); - } - }); -}, - - 'map error': function(test){ - test.expect(1); - async.map([1,2,3], function(x, callback){ - callback('error'); - }, function(err){ - test.equals(err, 'error'); - }); - setTimeout(test.done, 50); -}, - - 'map undefined array': function(test){ - test.expect(2); - async.map(undefined, function(x, callback){ - callback(); - }, function(err, result){ - test.equals(err, null); - test.same(result, []); - }); - setTimeout(test.done, 50); -}, - - 'map object': function (test) { - async.map({a: 1, b: 2, c: 3}, function (val, callback) { - callback(null, val * 2); - }, function (err, result) { - if (err) throw err; - test.equals(Object.prototype.toString.call(result), '[object Object]'); - test.same(result, {a: 2, b: 4, c: 6}); - test.done(); - }); -}, - - 'mapSeries': function(test){ - var call_order = []; - async.mapSeries([1,3,2], mapIteratee.bind(this, call_order), function(err, results){ - test.ok(err === null, err + " passed instead of 'null'"); - test.same(call_order, [1,3,2]); - test.same(results, [2,6,4]); - test.done(); - }); -}, - - 'mapSeries error': function(test){ - test.expect(1); - async.mapSeries([1,2,3], function(x, callback){ - callback('error'); - }, function(err){ - test.equals(err, 'error'); - }); - setTimeout(test.done, 50); -}, - - 'mapSeries undefined array': function(test){ - test.expect(2); - async.mapSeries(undefined, function(x, callback){ - callback(); - }, function(err, result){ - test.equals(err, null); - test.same(result, []); - }); - setTimeout(test.done, 50); -}, - - 'mapSeries object': function (test) { - async.mapSeries({a: 1, b: 2, c: 3}, function (val, callback) { - callback(null, val * 2); - }, function (err, result) { - if (err) throw err; - test.same(result, {a: 2, b: 4, c: 6}); - test.done(); - }); -}, - - 'mapLimit': function(test){ - var call_order = []; - async.mapLimit([2,4,3], 2, mapIteratee.bind(this, call_order), function(err, results){ - test.ok(err === null, err + " passed instead of 'null'"); - test.same(call_order, [2,4,3]); - test.same(results, [4,8,6]); - test.done(); - }); -}, - - 'mapLimit empty array': function(test){ - test.expect(1); - async.mapLimit([], 2, function(x, callback){ - test.ok(false, 'iteratee should not be called'); - callback(); - }, function(err){ - if (err) throw err; - test.ok(true, 'should call callback'); - }); - setTimeout(test.done, 25); -}, - - 'mapLimit undefined array': function(test){ - test.expect(2); - async.mapLimit(undefined, 2, function(x, callback){ - callback(); - }, function(err, result){ - test.equals(err, null); - test.same(result, []); - }); - setTimeout(test.done, 50); -}, - - 'mapLimit limit exceeds size': function(test){ - var call_order = []; - async.mapLimit([0,1,2,3,4,5,6,7,8,9], 20, mapIteratee.bind(this, call_order), function(err, results){ - test.same(call_order, [0,1,2,3,4,5,6,7,8,9]); - test.same(results, [0,2,4,6,8,10,12,14,16,18]); - test.done(); - }); -}, - - 'mapLimit limit equal size': function(test){ - var call_order = []; - async.mapLimit([0,1,2,3,4,5,6,7,8,9], 10, mapIteratee.bind(this, call_order), function(err, results){ - test.same(call_order, [0,1,2,3,4,5,6,7,8,9]); - test.same(results, [0,2,4,6,8,10,12,14,16,18]); - test.done(); - }); -}, - - 'mapLimit zero limit': function(test){ - test.expect(2); - async.mapLimit([0,1,2,3,4,5], 0, function(x, callback){ - test.ok(false, 'iteratee should not be called'); - callback(); - }, function(err, results){ - test.same(results, []); - test.ok(true, 'should call callback'); - }); - setTimeout(test.done, 25); -}, - - 'mapLimit error': function(test){ - test.expect(2); - var arr = [0,1,2,3,4,5,6,7,8,9]; - var call_order = []; - - async.mapLimit(arr, 3, function(x, callback){ - call_order.push(x); - if (x === 2) { - callback('error'); - } - }, function(err){ - test.same(call_order, [0,1,2]); - test.equals(err, 'error'); - }); - setTimeout(test.done, 25); -}, - - 'mapLimit does not continue replenishing after error': function (test) { - var started = 0; - var arr = [0,1,2,3,4,5,6,7,8,9]; - var delay = 10; - var limit = 3; - var maxTime = 10 * arr.length; - - async.mapLimit(arr, limit, function(x, callback) { - started ++; - if (started === 3) { - return callback(new Error ("Test Error")); - } - setTimeout(function(){ - callback(); - }, delay); - }, function(){}); - - setTimeout(function(){ - test.equal(started, 3); - test.done(); - }, maxTime); -}, - - 'map with Map': function(test) { - if (typeof Map !== 'function') - return test.done(); - - var map = new Map(); - map.set(1, "a"); - map.set(2, "b"); - async.map(map, function(val, cb) { - cb(null, val); - }, function (err, result) { - test.ok(Array.isArray(result), "map should return an array for an iterable"); - test.done(); - }); -} - -}; - - -exports['reduce'] = function(test){ - var call_order = []; - async.reduce([1,2,3], 0, function(a, x, callback){ - call_order.push(x); - callback(null, a + x); - }, function(err, result){ - test.ok(err === null, err + " passed instead of 'null'"); - test.equals(result, 6); - test.same(call_order, [1,2,3]); - test.done(); - }); -}; - -exports['reduce async with non-reference memo'] = function(test){ - async.reduce([1,3,2], 0, function(a, x, callback){ - setTimeout(function(){callback(null, a + x);}, Math.random()*100); - }, function(err, result){ - test.equals(result, 6); - test.done(); - }); -}; - -exports['reduce error'] = function(test){ - test.expect(1); - async.reduce([1,2,3], 0, function(a, x, callback){ - callback('error'); - }, function(err){ - test.equals(err, 'error'); - }); - setTimeout(test.done, 50); -}; - -exports['inject alias'] = function(test){ - test.equals(async.inject, async.reduce); - test.done(); -}; - -exports['foldl alias'] = function(test){ - test.equals(async.foldl, async.reduce); - test.done(); -}; - -exports['reduceRight'] = function(test){ - var call_order = []; - var a = [1,2,3]; - async.reduceRight(a, 0, function(a, x, callback){ - call_order.push(x); - callback(null, a + x); - }, function(err, result){ - test.equals(result, 6); - test.same(call_order, [3,2,1]); - test.same(a, [1,2,3]); - test.done(); - }); -}; - -exports['foldr alias'] = function(test){ - test.equals(async.foldr, async.reduceRight); - test.done(); -}; - -exports['transform implictly determines memo if not provided'] = function(test){ - async.transform([1,2,3], function(memo, x, v, callback){ - memo.push(x + 1); - callback(); - }, function(err, result){ - test.same(result, [2, 3, 4]); - test.done(); - }); -}; - -exports['transform async with object memo'] = function(test){ - test.expect(2); - - async.transform([1,3,2], {}, function(memo, v, k, callback){ - setTimeout(function() { - memo[k] = v; - callback(); - }); - }, function(err, result) { - test.equals(err, null); - test.same(result, { - 0: 1, - 1: 3, - 2: 2 - }); - test.done(); - }); -}; - -exports['transform iterating object'] = function(test){ - test.expect(2); - - async.transform({a: 1, b: 3, c: 2}, function(memo, v, k, callback){ - setTimeout(function() { - memo[k] = v + 1; - callback(); - }); - }, function(err, result) { - test.equals(err, null); - test.same(result, {a: 2, b: 4, c: 3}); - test.done(); - }); -}; - -exports['transform error'] = function(test){ - async.transform([1,2,3], function(a, v, k, callback){ - callback('error'); - }, function(err){ - test.equals(err, 'error'); - test.done(); - }); -}; - -exports['sortBy'] = function(test){ - test.expect(2); - - async.sortBy([{a:1},{a:15},{a:6}], function(x, callback){ - setTimeout(function(){callback(null, x.a);}, 0); - }, function(err, result){ - test.ok(err === null, err + " passed instead of 'null'"); - test.same(result, [{a:1},{a:6},{a:15}]); - test.done(); - }); -}; - -exports['sortBy inverted'] = function(test){ - test.expect(1); - - async.sortBy([{a:1},{a:15},{a:6}], function(x, callback){ - setTimeout(function(){callback(null, x.a*-1);}, 0); - }, function(err, result){ - test.same(result, [{a:15},{a:6},{a:1}]); - test.done(); - }); -}; - -exports['sortBy error'] = function(test){ - test.expect(1); - var error = new Error('asdas'); - async.sortBy([{a:1},{a:15},{a:6}], function(x, callback){ - async.setImmediate(function(){ - callback(error); - }); - }, function(err){ - test.equal(err, error); - test.done(); - }); -}; - -exports['apply'] = function(test){ - test.expect(6); - var fn = function(){ - test.same(Array.prototype.slice.call(arguments), [1,2,3,4]); - }; - async.apply(fn, 1, 2, 3, 4)(); - async.apply(fn, 1, 2, 3)(4); - async.apply(fn, 1, 2)(3, 4); - async.apply(fn, 1)(2, 3, 4); - async.apply(fn)(1, 2, 3, 4); - test.equals( - async.apply(function(name){return 'hello ' + name;}, 'world')(), - 'hello world' - ); - test.done(); -}; - - -// generates tests for console functions such as async.log -var console_fn_tests = function(name){ - - if (typeof console !== 'undefined') { - exports[name] = function(test){ - test.expect(5); - var fn = function(arg1, callback){ - test.equals(arg1, 'one'); - setTimeout(function(){callback(null, 'test');}, 0); - }; - var fn_err = function(arg1, callback){ - test.equals(arg1, 'one'); - setTimeout(function(){callback('error');}, 0); - }; - var _console_fn = console[name]; - var _error = console.error; - console[name] = function(val){ - test.equals(val, 'test'); - test.equals(arguments.length, 1); - console.error = function(val){ - test.equals(val, 'error'); - console[name] = _console_fn; - console.error = _error; - test.done(); - }; - async[name](fn_err, 'one'); - }; - async[name](fn, 'one'); - }; - - exports[name + ' with multiple result params'] = function(test){ - test.expect(1); - var fn = function(callback){callback(null,'one','two','three');}; - var _console_fn = console[name]; - var called_with = []; - console[name] = function(x){ - called_with.push(x); - }; - async[name](fn); - test.same(called_with, ['one','two','three']); - console[name] = _console_fn; - test.done(); - }; - } - - // browser-only test - exports[name + ' without console.' + name] = function(test){ - if (typeof window !== 'undefined') { - var _console = window.console; - window.console = undefined; - var fn = function(callback){callback(null, 'val');}; - var fn_err = function(callback){callback('error');}; - async[name](fn); - async[name](fn_err); - window.console = _console; - } - test.done(); - }; - -}; - - -exports['times'] = { - - 'times': function(test) { - test.expect(2); - async.times(5, function(n, next) { - next(null, n); - }, function(err, results) { - test.ok(err === null, err + " passed instead of 'null'"); - test.same(results, [0,1,2,3,4]); - test.done(); - }); -}, - - 'times 3': function(test){ - test.expect(1); - var args = []; - async.times(3, function(n, callback){ - setTimeout(function(){ - args.push(n); - callback(); - }, n * 25); - }, function(err){ - if (err) throw err; - test.same(args, [0,1,2]); - test.done(); - }); -}, - - 'times 0': function(test){ - test.expect(1); - async.times(0, function(n, callback){ - test.ok(false, 'iteratee should not be called'); - callback(); - }, function(err){ - if (err) throw err; - test.ok(true, 'should call callback'); - }); - setTimeout(test.done, 25); -}, - - 'times error': function(test){ - test.expect(1); - async.times(3, function(n, callback){ - callback('error'); - }, function(err){ - test.equals(err, 'error'); - }); - setTimeout(test.done, 50); -}, - - 'timesSeries': function(test){ - test.expect(2); - var call_order = []; - async.timesSeries(5, function(n, callback){ - setTimeout(function(){ - call_order.push(n); - callback(null, n); - }, 100 - n * 10); - }, function(err, results){ - test.same(call_order, [0,1,2,3,4]); - test.same(results, [0,1,2,3,4]); - test.done(); - }); -}, - - 'timesSeries error': function(test){ - test.expect(1); - async.timesSeries(5, function(n, callback){ - callback('error'); - }, function(err){ - test.equals(err, 'error'); - }); - setTimeout(test.done, 50); -}, - - 'timesLimit': function(test){ - test.expect(7); - - var limit = 2; - var running = 0; - async.timesLimit(5, limit, function (i, next) { - running++; - test.ok(running <= limit && running > 0, running); - setTimeout(function () { - running--; - next(null, i * 2); - }, (3 - i) * 10); - }, function(err, results){ - test.ok(err === null, err + " passed instead of 'null'"); - test.same(results, [0, 2, 4, 6, 8]); - test.done(); - }); -} - -}; - -console_fn_tests('log'); -console_fn_tests('dir'); -/*console_fn_tests('info'); -console_fn_tests('warn'); -console_fn_tests('error');*/ - - -exports['concat'] = function(test){ - test.expect(3); - var call_order = []; - var iteratee = function (x, cb) { - setTimeout(function(){ - call_order.push(x); - var r = []; - while (x > 0) { - r.push(x); - x--; - } - cb(null, r); - }, x*25); - }; - async.concat([1,3,2], iteratee, function(err, results){ - test.same(results, [1,2,1,3,2,1]); - test.same(call_order, [1,2,3]); - test.ok(err === null, err + " passed instead of 'null'"); - test.done(); - }); -}; - -exports['concat error'] = function(test){ - test.expect(1); - var iteratee = function (x, cb) { - cb(new Error('test error')); - }; - async.concat([1,2,3], iteratee, function(err){ - test.ok(err); - test.done(); - }); -}; - -exports['concatSeries'] = function(test){ - test.expect(3); - var call_order = []; - var iteratee = function (x, cb) { - setTimeout(function(){ - call_order.push(x); - var r = []; - while (x > 0) { - r.push(x); - x--; - } - cb(null, r); - }, x*25); - }; - async.concatSeries([1,3,2], iteratee, function(err, results){ - test.same(results, [1,3,2,1,2,1]); - test.same(call_order, [1,3,2]); - test.ok(err === null, err + " passed instead of 'null'"); - test.done(); - }); -}; - -exports['until'] = function (test) { - test.expect(4); - - var call_order = []; - var count = 0; - async.until( - function () { - call_order.push(['test', count]); - return (count == 5); - }, - function (cb) { - call_order.push(['iteratee', count]); - count++; - cb(null, count); - }, - function (err, result) { - test.ok(err === null, err + " passed instead of 'null'"); - test.equals(result, 5, 'last result passed through'); - test.same(call_order, [ - ['test', 0], - ['iteratee', 0], ['test', 1], - ['iteratee', 1], ['test', 2], - ['iteratee', 2], ['test', 3], - ['iteratee', 3], ['test', 4], - ['iteratee', 4], ['test', 5], - ]); - test.equals(count, 5); - test.done(); - } - ); -}; - -exports['doUntil'] = function (test) { - test.expect(4); - - var call_order = []; - var count = 0; - async.doUntil( - function (cb) { - call_order.push(['iteratee', count]); - count++; - cb(null, count); - }, - function () { - call_order.push(['test', count]); - return (count == 5); - }, - function (err, result) { - test.ok(err === null, err + " passed instead of 'null'"); - test.equals(result, 5, 'last result passed through'); - test.same(call_order, [ - ['iteratee', 0], ['test', 1], - ['iteratee', 1], ['test', 2], - ['iteratee', 2], ['test', 3], - ['iteratee', 3], ['test', 4], - ['iteratee', 4], ['test', 5] - ]); - test.equals(count, 5); - test.done(); - } - ); -}; - -exports['doUntil callback params'] = function (test) { - test.expect(3); - - var call_order = []; - var count = 0; - async.doUntil( - function (cb) { - call_order.push(['iteratee', count]); - count++; - cb(null, count); - }, - function (c) { - call_order.push(['test', c]); - return (c == 5); - }, - function (err, result) { - if (err) throw err; - test.equals(result, 5, 'last result passed through'); - test.same(call_order, [ - ['iteratee', 0], ['test', 1], - ['iteratee', 1], ['test', 2], - ['iteratee', 2], ['test', 3], - ['iteratee', 3], ['test', 4], - ['iteratee', 4], ['test', 5] - ]); - test.equals(count, 5); - test.done(); - } - ); -}; - -exports['whilst'] = function (test) { - test.expect(4); - - var call_order = []; - - var count = 0; - async.whilst( - function () { - call_order.push(['test', count]); - return (count < 5); - }, - function (cb) { - call_order.push(['iteratee', count]); - count++; - cb(null, count); - }, - function (err, result) { - test.ok(err === null, err + " passed instead of 'null'"); - test.equals(result, 5, 'last result passed through'); - test.same(call_order, [ - ['test', 0], - ['iteratee', 0], ['test', 1], - ['iteratee', 1], ['test', 2], - ['iteratee', 2], ['test', 3], - ['iteratee', 3], ['test', 4], - ['iteratee', 4], ['test', 5], - ]); - test.equals(count, 5); - test.done(); - } - ); -}; - -exports['doWhilst'] = function (test) { - test.expect(4); - var call_order = []; - - var count = 0; - async.doWhilst( - function (cb) { - call_order.push(['iteratee', count]); - count++; - cb(null, count); - }, - function () { - call_order.push(['test', count]); - return (count < 5); - }, - function (err, result) { - test.ok(err === null, err + " passed instead of 'null'"); - test.equals(result, 5, 'last result passed through'); - test.same(call_order, [ - ['iteratee', 0], ['test', 1], - ['iteratee', 1], ['test', 2], - ['iteratee', 2], ['test', 3], - ['iteratee', 3], ['test', 4], - ['iteratee', 4], ['test', 5] - ]); - test.equals(count, 5); - test.done(); - } - ); -}; - -exports['doWhilst callback params'] = function (test) { - test.expect(3); - var call_order = []; - var count = 0; - async.doWhilst( - function (cb) { - call_order.push(['iteratee', count]); - count++; - cb(null, count); - }, - function (c) { - call_order.push(['test', c]); - return (c < 5); - }, - function (err, result) { - if (err) throw err; - test.equals(result, 5, 'last result passed through'); - test.same(call_order, [ - ['iteratee', 0], ['test', 1], - ['iteratee', 1], ['test', 2], - ['iteratee', 2], ['test', 3], - ['iteratee', 3], ['test', 4], - ['iteratee', 4], ['test', 5] - ]); - test.equals(count, 5); - test.done(); - } - ); -}; - -exports['doWhilst - error'] = function (test) { - test.expect(1); - var error = new Error('asdas'); - - async.doWhilst( - function (cb) { - cb(error); - }, - function () {}, - function (err) { - test.equal(err, error); - test.done(); - } - ); -}; - -exports['during'] = function (test) { - var call_order = []; - - var count = 0; - async.during( - function (cb) { - call_order.push(['test', count]); - cb(null, count < 5); - }, - function (cb) { - call_order.push(['iteratee', count]); - count++; - cb(); - }, - function (err) { - test.ok(err === null, err + " passed instead of 'null'"); - test.same(call_order, [ - ['test', 0], - ['iteratee', 0], ['test', 1], - ['iteratee', 1], ['test', 2], - ['iteratee', 2], ['test', 3], - ['iteratee', 3], ['test', 4], - ['iteratee', 4], ['test', 5], - ]); - test.equals(count, 5); - test.done(); - } - ); -}; - -exports['doDuring'] = function (test) { - var call_order = []; - - var count = 0; - async.doDuring( - function (cb) { - call_order.push(['iteratee', count]); - count++; - cb(); - }, - function (cb) { - call_order.push(['test', count]); - cb(null, count < 5); - }, - function (err) { - test.ok(err === null, err + " passed instead of 'null'"); - test.same(call_order, [ - ['iteratee', 0], ['test', 1], - ['iteratee', 1], ['test', 2], - ['iteratee', 2], ['test', 3], - ['iteratee', 3], ['test', 4], - ['iteratee', 4], ['test', 5], - ]); - test.equals(count, 5); - test.done(); - } - ); -}; - -exports['doDuring - error test'] = function (test) { - test.expect(1); - var error = new Error('asdas'); - - async.doDuring( - function (cb) { - cb(error); - }, - function () {}, - function (err) { - test.equal(err, error); - test.done(); - } - ); -}; - -exports['doDuring - error iteratee'] = function (test) { - test.expect(1); - var error = new Error('asdas'); - - async.doDuring( - function (cb) { - cb(null); - }, - function (cb) { - cb(error); - }, - function (err) { - test.equal(err, error); - test.done(); - } - ); -}; - -exports['whilst optional callback'] = function (test) { - var counter = 0; - async.whilst( - function () { return counter < 2; }, - function (cb) { - counter++; - cb(); - } - ); - test.equal(counter, 2); - test.done(); -}; - - -exports['memoize'] = { - - 'memoize': function (test) { - test.expect(5); - var call_order = []; - - var fn = function (arg1, arg2, callback) { - async.setImmediate(function () { - call_order.push(['fn', arg1, arg2]); - callback(null, arg1 + arg2); - }); - }; - - var fn2 = async.memoize(fn); - fn2(1, 2, function (err, result) { - test.ok(err === null, err + " passed instead of 'null'"); - test.equal(result, 3); - fn2(1, 2, function (err, result) { - test.equal(result, 3); - fn2(2, 2, function (err, result) { - test.equal(result, 4); - test.same(call_order, [['fn',1,2], ['fn',2,2]]); - test.done(); - }); - }); - }); -}, - - 'maintains asynchrony': function (test) { - test.expect(3); - var call_order = []; - - var fn = function (arg1, arg2, callback) { - call_order.push(['fn', arg1, arg2]); - async.setImmediate(function () { - call_order.push(['cb', arg1, arg2]); - callback(null, arg1 + arg2); - }); - }; - - var fn2 = async.memoize(fn); - fn2(1, 2, function (err, result) { - test.equal(result, 3); - fn2(1, 2, function (err, result) { - test.equal(result, 3); - async.nextTick(memoize_done); - call_order.push('tick3'); - }); - call_order.push('tick2'); - }); - call_order.push('tick1'); - - function memoize_done() { - var async_call_order = [ - ['fn',1,2], // initial async call - 'tick1', // async caller - ['cb',1,2], // async callback - // ['fn',1,2], // memoized // memoized async body - 'tick2', // handler for first async call - // ['cb',1,2], // memoized // memoized async response body - 'tick3' // handler for memoized async call - ]; - test.same(call_order, async_call_order); - test.done(); - } -}, - - 'unmemoize': function(test) { - test.expect(4); - var call_order = []; - - var fn = function (arg1, arg2, callback) { - call_order.push(['fn', arg1, arg2]); - async.setImmediate(function () { - callback(null, arg1 + arg2); - }); - }; - - var fn2 = async.memoize(fn); - var fn3 = async.unmemoize(fn2); - fn3(1, 2, function (err, result) { - test.equal(result, 3); - fn3(1, 2, function (err, result) { - test.equal(result, 3); - fn3(2, 2, function (err, result) { - test.equal(result, 4); - test.same(call_order, [['fn',1,2], ['fn',1,2], ['fn',2,2]]); - test.done(); - }); - }); - }); -}, - - 'unmemoize a not memoized function': function(test) { - test.expect(1); - - var fn = function (arg1, arg2, callback) { - callback(null, arg1 + arg2); - }; - - var fn2 = async.unmemoize(fn); - fn2(1, 2, function(err, result) { - test.equal(result, 3); - }); - - test.done(); -}, - - 'error': function (test) { - test.expect(1); - var testerr = new Error('test'); - var fn = function (arg1, arg2, callback) { - callback(testerr, arg1 + arg2); - }; - async.memoize(fn)(1, 2, function (err) { - test.equal(err, testerr); - }); - test.done(); -}, - - 'multiple calls': function (test) { - test.expect(3); - var fn = function (arg1, arg2, callback) { - test.ok(true); - setTimeout(function(){ - callback(null, arg1, arg2); - }, 10); - }; - var fn2 = async.memoize(fn); - fn2(1, 2, function(err, result) { - test.equal(result, 1, 2); - }); - fn2(1, 2, function(err, result) { - test.equal(result, 1, 2); - test.done(); - }); -}, - - 'custom hash function': function (test) { - test.expect(2); - var testerr = new Error('test'); - - var fn = function (arg1, arg2, callback) { - callback(testerr, arg1 + arg2); - }; - var fn2 = async.memoize(fn, function () { - return 'custom hash'; - }); - fn2(1, 2, function (err, result) { - test.equal(result, 3); - fn2(2, 2, function (err, result) { - test.equal(result, 3); - test.done(); - }); - }); -}, - - 'manually added memo value': function (test) { - test.expect(1); - var fn = async.memoize(function() { - test(false, "Function should never be called"); - }); - fn.memo["foo"] = ["bar"]; - fn("foo", function(val) { - test.equal(val, "bar"); - test.done(); - }); -}, - - 'avoid constructor key return undefined': function (test) { - test.expect(1); - var fn = async.memoize(function(name, callback) { - setTimeout(function(){ - callback(null, name); - }, 100); - }); - fn('constructor', function(error, results) { - test.equal(results, 'constructor'); - test.done(); - }); -}, - - 'avoid __proto__ key return undefined': function (test) { - // Skip test if there is a Object.create bug (node 0.10 and some Chrome 30x versions) - var x = Object.create(null); - /* jshint proto: true */ - x.__proto__ = 'foo'; - if (x.__proto__ !== 'foo') { - return test.done(); - } - - test.expect(1); - var fn = async.memoize(function(name, callback) { - setTimeout(function(){ - callback(null, name); - }, 100); - }); - fn('__proto__', function(error, results) { - test.equal(results, '__proto__'); - test.done(); - }); -}, - - 'allow hasOwnProperty as key': function (test) { - test.expect(1); - var fn = async.memoize(function(name, callback) { - setTimeout(function(){ - callback(null, name); - }, 100); - }); - fn('hasOwnProperty', function(error, results) { - test.equal(results, 'hasOwnProperty'); - test.done(); - }); -} - -}; - - -exports['ensureAsync'] = { - 'defer sync functions': function (test) { - test.expect(6); - var sync = true; - async.ensureAsync(function (arg1, arg2, cb) { - test.equal(arg1, 1); - test.equal(arg2, 2); - cb(null, 4, 5); - })(1, 2, function (err, arg4, arg5) { - test.equal(err, null); - test.equal(arg4, 4); - test.equal(arg5, 5); - test.ok(!sync, 'callback called on same tick'); - test.done(); - }); - sync = false; - }, - - 'do not defer async functions': function (test) { - test.expect(6); - var sync = false; - async.ensureAsync(function (arg1, arg2, cb) { - test.equal(arg1, 1); - test.equal(arg2, 2); - async.setImmediate(function () { - sync = true; - cb(null, 4, 5); - sync = false; - }); - })(1, 2, function (err, arg4, arg5) { - test.equal(err, null); - test.equal(arg4, 4); - test.equal(arg5, 5); - test.ok(sync, 'callback called on next tick'); - test.done(); - }); - }, - - 'double wrapping': function (test) { - test.expect(6); - var sync = true; - async.ensureAsync(async.ensureAsync(function (arg1, arg2, cb) { - test.equal(arg1, 1); - test.equal(arg2, 2); - cb(null, 4, 5); - }))(1, 2, function (err, arg4, arg5) { - test.equal(err, null); - test.equal(arg4, 4); - test.equal(arg5, 5); - test.ok(!sync, 'callback called on same tick'); - test.done(); - }); - sync = false; - } -}; - -exports['constant'] = function (test) { - test.expect(5); - var f = async.constant(42, 1, 2, 3); - f(function (err, value, a, b, c) { - test.ok(!err); - test.ok(value === 42); - test.ok(a === 1); - test.ok(b === 2); - test.ok(c === 3); - test.done(); - }); -}; - -exports['asyncify'] = { - 'asyncify': function (test) { - var parse = async.asyncify(JSON.parse); - parse("{\"a\":1}", function (err, result) { - test.ok(!err); - test.ok(result.a === 1); - test.done(); - }); - }, - - 'asyncify null': function (test) { - var parse = async.asyncify(function() { - return null; - }); - parse("{\"a\":1}", function (err, result) { - test.ok(!err); - test.ok(result === null); - test.done(); - }); - }, - - 'variable numbers of arguments': function (test) { - async.asyncify(function (x, y, z) { - test.ok(arguments.length === 3); - test.ok(x === 1); - test.ok(y === 2); - test.ok(z === 3); - })(1, 2, 3, function () {}); - test.done(); - }, - - 'catch errors': function (test) { - async.asyncify(function () { - throw new Error("foo"); - })(function (err) { - test.ok(err); - test.ok(err.message === "foo"); - test.done(); - }); - }, - - 'dont catch errors in the callback': function (test) { - try { - async.asyncify(function () {})(function (err) { - if (err) { - return test.done(new Error("should not get an error here")); - } - throw new Error("callback error"); - }); - } catch (e) { - test.ok(e.message === "callback error"); - test.done(); - } - }, - - 'promisified': [ - 'native-promise-only', - 'bluebird', - 'es6-promise', - 'rsvp' - ].reduce(function(promises, name) { - if (isBrowser()) { - // node only test - return; - } - var Promise = require(name); - if (typeof Promise.Promise === 'function') { - Promise = Promise.Promise; - } - promises[name] = { - 'resolve': function(test) { - var promisified = function(argument) { - return new Promise(function (resolve) { - setTimeout(function () { - resolve(argument + " resolved"); - }, 15); - }); - }; - async.asyncify(promisified)("argument", function (err, value) { - if (err) { - return test.done(new Error("should not get an error here")); - } - test.ok(value === "argument resolved"); - test.done(); - }); - }, - - 'reject': function(test) { - var promisified = function(argument) { - return new Promise(function (resolve, reject) { - reject(argument + " rejected"); - }); - }; - async.asyncify(promisified)("argument", function (err) { - test.ok(err); - test.ok(err.message === "argument rejected"); - test.done(); - }); - } - }; - return promises; - }, {}) -}; - -exports['timeout'] = function (test) { - test.expect(4); - - async.series([ - async.timeout(function asyncFn(callback) { - setTimeout(function() { - callback(null, 'I didn\'t time out'); - }, 50); - }, 200), - async.timeout(function asyncFn(callback) { - setTimeout(function() { - callback(null, 'I will time out'); - }, 300); - }, 150) - ], - function(err, results) { - test.ok(err.message === 'Callback function "asyncFn" timed out.'); - test.ok(err.code === 'ETIMEDOUT'); - test.ok(err.info === undefined); - test.ok(results[0] === 'I didn\'t time out'); - test.done(); - }); -}; - -exports['timeout with info'] = function (test) { - test.expect(4); - - var info = { custom: 'info about callback' }; - async.series([ - async.timeout(function asyncFn(callback) { - setTimeout(function() { - callback(null, 'I didn\'t time out'); - }, 50); - }, 200), - async.timeout(function asyncFn(callback) { - setTimeout(function() { - callback(null, 'I will time out'); - }, 300); - }, 150, info) - ], - function(err, results) { - test.ok(err.message === 'Callback function "asyncFn" timed out.'); - test.ok(err.code === 'ETIMEDOUT'); - test.ok(err.info === info); - test.ok(results[0] === 'I didn\'t time out'); - test.done(); - }); -}; - -exports['timeout with parallel'] = function (test) { - test.expect(4); - - async.parallel([ - async.timeout(function asyncFn(callback) { - setTimeout(function() { - callback(null, 'I didn\'t time out'); - }, 50); - }, 200), - async.timeout(function asyncFn(callback) { - setTimeout(function() { - callback(null, 'I will time out'); - }, 300); - }, 150) - ], - function(err, results) { - test.ok(err.message === 'Callback function "asyncFn" timed out.'); - test.ok(err.code === 'ETIMEDOUT'); - test.ok(err.info === undefined); - test.ok(results[0] === 'I didn\'t time out'); - test.done(); - }); -}; diff --git a/test/test.html b/test/test.html deleted file mode 100644 index 0047af4..0000000 --- a/test/test.html +++ /dev/null @@ -1,24 +0,0 @@ -<html> - <head> - <title>Async.js Test Suite</title> - <!-- - async must be included after nodeunit because nodeunit already uses - the async lib internally and will overwrite the version we want to test - --> - <script src="../deps/nodeunit.js"></script> - <script src="../dist/async.js"></script> - <link rel="stylesheet" href="../deps/nodeunit.css" type="text/css" media="screen" /> - <script> - var _async = this.async; - this.require = function () { return _async; }; - this.exports = {}; - </script> - <script src="test-async.js"></script> - </head> - <body> - <h1 id="nodeunit-header">Async.js Test Suite</h1> - <script> - nodeunit.run({'test-async': exports}); - </script> - </body> -</html> |