diff --git a/apply.js.html b/apply.js.html new file mode 100644 index 000000000..e93e09154 --- /dev/null +++ b/apply.js.html @@ -0,0 +1,158 @@ + + + + + + + apply.js - Documentation + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +

apply.js

+ + + + + + + +
+
+
import rest from './internal/rest';
+
+/**
+ * Creates a continuation function with some arguments already applied.
+ *
+ * Useful as a shorthand when combined with other control flow functions. Any
+ * arguments passed to the returned function are added to the arguments
+ * originally passed to apply.
+ *
+ * @name apply
+ * @static
+ * @memberOf module:Utils
+ * @method
+ * @category Util
+ * @param {Function} function - The function you want to eventually apply all
+ * arguments to. Invokes with (arguments...).
+ * @param {...*} arguments... - Any number of arguments to automatically apply
+ * when the continuation is called.
+ * @example
+ *
+ * // using apply
+ * async.parallel([
+ *     async.apply(fs.writeFile, 'testfile1', 'test1'),
+ *     async.apply(fs.writeFile, 'testfile2', 'test2')
+ * ]);
+ *
+ *
+ * // the same process without using apply
+ * async.parallel([
+ *     function(callback) {
+ *         fs.writeFile('testfile1', 'test1', callback);
+ *     },
+ *     function(callback) {
+ *         fs.writeFile('testfile2', 'test2', callback);
+ *     }
+ * ]);
+ *
+ * // It's possible to pass any number of additional arguments when calling the
+ * // continuation:
+ *
+ * node> var fn = async.apply(sys.puts, 'one');
+ * node> fn('two', 'three');
+ * one
+ * two
+ * three
+ */
+export default rest(function(fn, args) {
+    return rest(function(callArgs) {
+        return fn.apply(null, args.concat(callArgs));
+    });
+});
+
+
+
+ + + + +
+
+ + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/applyEach.js.html b/applyEach.js.html new file mode 100644 index 000000000..c2762cf1e --- /dev/null +++ b/applyEach.js.html @@ -0,0 +1,144 @@ + + + + + + + applyEach.js - Documentation + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +

applyEach.js

+ + + + + + + +
+
+
import applyEach from './internal/applyEach';
+import map from './map';
+
+/**
+ * Applies the provided arguments to each function in the array, calling
+ * `callback` after all functions have completed. If you only provide the first
+ * argument, `fns`, then it will return a function which lets you pass in the
+ * arguments as if it were a single function call. If more arguments are
+ * provided, `callback` is required while `args` is still optional.
+ *
+ * @name applyEach
+ * @static
+ * @memberOf module:ControlFlow
+ * @method
+ * @category Control Flow
+ * @param {Array|Iterable|Object} fns - A collection of asynchronous functions
+ * to all call with the same arguments
+ * @param {...*} [args] - any number of separate arguments to pass to the
+ * function.
+ * @param {Function} [callback] - the final argument should be the callback,
+ * called when all functions have completed processing.
+ * @returns {Function} - If only the first argument, `fns`, is provided, it will
+ * return a function which lets you pass in the arguments as if it were a single
+ * function call. The signature is `(..args, callback)`. If invoked with any
+ * arguments, `callback` is required.
+ * @example
+ *
+ * async.applyEach([enableSearch, updateSchema], 'bucket', callback);
+ *
+ * // partial application example:
+ * async.each(
+ *     buckets,
+ *     async.applyEach([enableSearch, updateSchema]),
+ *     callback
+ * );
+ */
+export default applyEach(map);
+
+
+
+ + + + +
+
+ + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/applyEachSeries.js.html b/applyEachSeries.js.html new file mode 100644 index 000000000..367e949e3 --- /dev/null +++ b/applyEachSeries.js.html @@ -0,0 +1,130 @@ + + + + + + + applyEachSeries.js - Documentation + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +

applyEachSeries.js

+ + + + + + + +
+
+
import applyEach from './internal/applyEach';
+import mapSeries from './mapSeries';
+
+/**
+ * The same as [`applyEach`]{@link module:ControlFlow.applyEach} but runs only a single async operation at a time.
+ *
+ * @name applyEachSeries
+ * @static
+ * @memberOf module:ControlFlow
+ * @method
+ * @see [async.applyEach]{@link module:ControlFlow.applyEach}
+ * @category Control Flow
+ * @param {Array|Iterable|Object} fns - A collection of asynchronous functions to all
+ * call with the same arguments
+ * @param {...*} [args] - any number of separate arguments to pass to the
+ * function.
+ * @param {Function} [callback] - the final argument should be the callback,
+ * called when all functions have completed processing.
+ * @returns {Function} - If only the first argument is provided, it will return
+ * a function which lets you pass in the arguments as if it were a single
+ * function call.
+ */
+export default applyEach(mapSeries);
+
+
+
+ + + + +
+
+ + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/asyncify.js.html b/asyncify.js.html new file mode 100644 index 000000000..36098ce18 --- /dev/null +++ b/asyncify.js.html @@ -0,0 +1,185 @@ + + + + + + + asyncify.js - Documentation + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +

asyncify.js

+ + + + + + + +
+
+
import isObject from 'lodash/isObject';
+import initialParams from './internal/initialParams';
+
+/**
+ * Take a sync function and make it async, passing its return value to a
+ * callback. This is useful for plugging sync functions into a waterfall,
+ * series, or other async functions. Any arguments passed to the generated
+ * function will be passed to the wrapped function (except for the final
+ * callback argument). Errors thrown will be passed to the callback.
+ *
+ * If the function passed to `asyncify` returns a Promise, that promises's
+ * resolved/rejected state will be used to call the callback, rather than simply
+ * the synchronous return value.
+ *
+ * This also means you can asyncify ES2016 `async` functions.
+ *
+ * @name asyncify
+ * @static
+ * @memberOf module:Utils
+ * @method
+ * @alias wrapSync
+ * @category Util
+ * @param {Function} func - The synchronous function to convert to an
+ * asynchronous function.
+ * @returns {Function} An asynchronous wrapper of the `func`. To be invoked with
+ * (callback).
+ * @example
+ *
+ * // passing a regular synchronous function
+ * async.waterfall([
+ *     async.apply(fs.readFile, filename, "utf8"),
+ *     async.asyncify(JSON.parse),
+ *     function (data, next) {
+ *         // data is the result of parsing the text.
+ *         // If there was a parsing error, it would have been caught.
+ *     }
+ * ], callback);
+ *
+ * // passing a function returning a promise
+ * async.waterfall([
+ *     async.apply(fs.readFile, filename, "utf8"),
+ *     async.asyncify(function (contents) {
+ *         return db.model.create(contents);
+ *     }),
+ *     function (model, next) {
+ *         // `model` is the instantiated model object.
+ *         // If there was an error, this function would be skipped.
+ *     }
+ * ], callback);
+ *
+ * // es6 example
+ * var q = async.queue(async.asyncify(async function(file) {
+ *     var intermediateStep = await processFile(file);
+ *     return await somePromise(intermediateStep)
+ * }));
+ *
+ * q.push(files);
+ */
+export default function asyncify(func) {
+    return initialParams(function (args, callback) {
+        var result;
+        try {
+            result = func.apply(this, args);
+        } catch (e) {
+            return callback(e);
+        }
+        // if result is Promise object
+        if (isObject(result) && typeof result.then === 'function') {
+            result.then(function(value) {
+                callback(null, value);
+            }, function(err) {
+                callback(err.message ? err : new Error(err));
+            });
+        } else {
+            callback(null, result);
+        }
+    });
+}
+
+
+
+ + + + +
+
+ + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/auto.js.html b/auto.js.html new file mode 100644 index 000000000..288d18922 --- /dev/null +++ b/auto.js.html @@ -0,0 +1,363 @@ + + + + + + + auto.js - Documentation + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +

auto.js

+ + + + + + + +
+
+
import arrayEach from 'lodash/_arrayEach';
+import forOwn from 'lodash/_baseForOwn';
+import indexOf from 'lodash/_baseIndexOf';
+import isArray from 'lodash/isArray';
+import okeys from 'lodash/keys';
+import noop from 'lodash/noop';
+import rest from './internal/rest';
+
+import once from './internal/once';
+import onlyOnce from './internal/onlyOnce';
+
+/**
+ * Determines the best order for running the functions in `tasks`, based on
+ * their requirements. Each function can optionally depend on other functions
+ * being completed first, and each function is run as soon as its requirements
+ * are satisfied.
+ *
+ * If any of the functions pass an error to their callback, the `auto` sequence
+ * will stop. Further tasks will not execute (so any other functions depending
+ * on it will not run), and the main `callback` is immediately called with the
+ * error.
+ *
+ * Functions also receive an object containing the results of functions which
+ * have completed so far as the first argument, if they have dependencies. If a
+ * task function has no dependencies, it will only be passed a callback.
+ *
+ * @name auto
+ * @static
+ * @memberOf module:ControlFlow
+ * @method
+ * @category Control Flow
+ * @param {Object} tasks - An object. Each of its properties is either a
+ * function or an array of requirements, with the function itself the last item
+ * in the array. The object's key of a property serves as the name of the task
+ * defined by that property, i.e. can be used when specifying requirements for
+ * other tasks. The function receives one or two arguments:
+ * * a `results` object, containing the results of the previously executed
+ *   functions, only passed if the task has any dependencies,
+ * * a `callback(err, result)` function, which must be called when finished,
+ *   passing an `error` (which can be `null`) and the result of the function's
+ *   execution.
+ * @param {number} [concurrency=Infinity] - An optional `integer` for
+ * determining the maximum number of tasks that can be run in parallel. By
+ * default, as many as possible.
+ * @param {Function} [callback] - An optional callback which is called when all
+ * the tasks have been completed. It receives the `err` argument if any `tasks`
+ * pass an error to their callback. Results are always returned; however, if an
+ * error occurs, no further `tasks` will be performed, and the results object
+ * will only contain partial results. Invoked with (err, results).
+ * @returns undefined
+ * @example
+ *
+ * async.auto({
+ *     // this function will just be passed a callback
+ *     readData: async.apply(fs.readFile, 'data.txt', 'utf-8'),
+ *     showData: ['readData', function(results, cb) {
+ *         // results.readData is the file's contents
+ *         // ...
+ *     }]
+ * }, callback);
+ *
+ * async.auto({
+ *     get_data: function(callback) {
+ *         console.log('in get_data');
+ *         // async code to get some data
+ *         callback(null, 'data', 'converted to array');
+ *     },
+ *     make_folder: function(callback) {
+ *         console.log('in make_folder');
+ *         // async code to create a directory to store a file in
+ *         // this is run at the same time as getting the data
+ *         callback(null, 'folder');
+ *     },
+ *     write_file: ['get_data', 'make_folder', function(results, callback) {
+ *         console.log('in write_file', JSON.stringify(results));
+ *         // once there is some data and the directory exists,
+ *         // write the data to a file in the directory
+ *         callback(null, 'filename');
+ *     }],
+ *     email_link: ['write_file', function(results, callback) {
+ *         console.log('in email_link', JSON.stringify(results));
+ *         // once the file is written let's email a link to it...
+ *         // results.write_file contains the filename returned by write_file.
+ *         callback(null, {'file':results.write_file, 'email':'user@example.com'});
+ *     }]
+ * }, function(err, results) {
+ *     console.log('err = ', err);
+ *     console.log('results = ', results);
+ * });
+ */
+export default function (tasks, concurrency, callback) {
+    if (typeof concurrency === 'function') {
+        // concurrency is optional, shift the args.
+        callback = concurrency;
+        concurrency = null;
+    }
+    callback = once(callback || noop);
+    var keys = okeys(tasks);
+    var numTasks = keys.length;
+    if (!numTasks) {
+        return callback(null);
+    }
+    if (!concurrency) {
+        concurrency = numTasks;
+    }
+
+    var results = {};
+    var runningTasks = 0;
+    var hasError = false;
+
+    var listeners = Object.create(null);
+
+    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;
+        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 `' +
+                    dependencyName + '` in ' +
+                    dependencies.join(', '));
+            }
+            addListener(dependencyName, function () {
+                remainingDependencies--;
+                if (remainingDependencies === 0) {
+                    enqueueTask(key, task);
+                }
+            });
+        });
+    });
+
+    checkForDeadlocks();
+    processQueue();
+
+    function enqueueTask(key, task) {
+        readyTasks.push(function () {
+            runTask(key, task);
+        });
+    }
+
+    function processQueue() {
+        if (readyTasks.length === 0 && runningTasks === 0) {
+            return callback(null, results);
+        }
+        while(readyTasks.length && runningTasks < concurrency) {
+            var run = readyTasks.shift();
+            run();
+        }
+
+    }
+
+    function addListener(taskName, fn) {
+        var taskListeners = listeners[taskName];
+        if (!taskListeners) {
+            taskListeners = listeners[taskName] = [];
+        }
+
+        taskListeners.push(fn);
+    }
+
+    function taskComplete(taskName) {
+        var taskListeners = listeners[taskName] || [];
+        arrayEach(taskListeners, function (fn) {
+            fn();
+        });
+        processQueue();
+    }
+
+
+    function runTask(key, task) {
+        if (hasError) return;
+
+        var taskCallback = onlyOnce(rest(function(err, args) {
+            runningTasks--;
+            if (args.length <= 1) {
+                args = args[0];
+            }
+            if (err) {
+                var safeResults = {};
+                forOwn(results, function(val, rkey) {
+                    safeResults[rkey] = val;
+                });
+                safeResults[key] = args;
+                hasError = true;
+                listeners = Object.create(null);
+
+                callback(err, safeResults);
+            } else {
+                results[key] = args;
+                taskComplete(key);
+            }
+        }));
+
+        runningTasks++;
+        var taskFn = task[task.length - 1];
+        if (task.length > 1) {
+            taskFn(results, taskCallback);
+        } else {
+            taskFn(taskCallback);
+        }
+    }
+
+    function checkForDeadlocks() {
+        // Kahn's algorithm
+        // https://en.wikipedia.org/wiki/Topological_sorting#Kahn.27s_algorithm
+        // http://connalle.blogspot.com/2013/10/topological-sortingkahn-algorithm.html
+        var currentTask;
+        var counter = 0;
+        while (readyToCheck.length) {
+            currentTask = readyToCheck.pop();
+            counter++;
+            arrayEach(getDependents(currentTask), function (dependent) {
+                if (--uncheckedDependencies[dependent] === 0) {
+                    readyToCheck.push(dependent);
+                }
+            });
+        }
+
+        if (counter !== numTasks) {
+            throw new Error(
+                'async.auto cannot execute tasks due to a recursive dependency'
+            );
+        }
+    }
+
+    function getDependents(taskName) {
+        var result = [];
+        forOwn(tasks, function (task, key) {
+            if (isArray(task) && indexOf(task, taskName, 0) >= 0) {
+                result.push(key);
+            }
+        });
+        return result;
+    }
+}
+
+
+
+ + + + +
+
+ + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/autoInject.js.html b/autoInject.js.html new file mode 100644 index 000000000..008968f07 --- /dev/null +++ b/autoInject.js.html @@ -0,0 +1,246 @@ + + + + + + + autoInject.js - Documentation + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +

autoInject.js

+ + + + + + + +
+
+
import auto from './auto';
+import forOwn from 'lodash/_baseForOwn';
+import arrayMap from 'lodash/_arrayMap';
+import isArray from 'lodash/isArray';
+import trim from 'lodash/trim';
+
+var FN_ARGS = /^(function)?\s*[^\(]*\(\s*([^\)]*)\)/m;
+var FN_ARG_SPLIT = /,/;
+var FN_ARG = /(=.+)?(\s*)$/;
+var STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg;
+
+function parseParams(func) {
+    func = func.toString().replace(STRIP_COMMENTS, '');
+    func = func.match(FN_ARGS)[2].replace(' ', '');
+    func = func ? func.split(FN_ARG_SPLIT) : [];
+    func = func.map(function (arg){
+        return trim(arg.replace(FN_ARG, ''));
+    });
+    return func;
+}
+
+/**
+ * A dependency-injected version of the [async.auto]{@link module:ControlFlow.auto} function. Dependent
+ * tasks are specified as parameters to the function, after the usual callback
+ * parameter, with the parameter names matching the names of the tasks it
+ * depends on. This can provide even more readable task graphs which can be
+ * easier to maintain.
+ *
+ * If a final callback is specified, the task results are similarly injected,
+ * specified as named parameters after the initial error parameter.
+ *
+ * The autoInject function is purely syntactic sugar and its semantics are
+ * otherwise equivalent to [async.auto]{@link module:ControlFlow.auto}.
+ *
+ * @name autoInject
+ * @static
+ * @memberOf module:ControlFlow
+ * @method
+ * @see [async.auto]{@link module:ControlFlow.auto}
+ * @category Control Flow
+ * @param {Object} tasks - An object, each of whose properties is a function of
+ * the form 'func([dependencies...], callback). The object's key of a property
+ * serves as the name of the task defined by that property, i.e. can be used
+ * when specifying requirements for other tasks.
+ * * The `callback` parameter is a `callback(err, result)` which must be called
+ *   when finished, passing an `error` (which can be `null`) and the result of
+ *   the function's execution. The remaining parameters name other tasks on
+ *   which the task is dependent, and the results from those tasks are the
+ *   arguments of those parameters.
+ * @param {Function} [callback] - An optional callback which is called when all
+ * the tasks have been completed. It receives the `err` argument if any `tasks`
+ * pass an error to their callback, and a `results` object with any completed
+ * task results, similar to `auto`.
+ * @example
+ *
+ * //  The example from `auto` can be rewritten as follows:
+ * async.autoInject({
+ *     get_data: function(callback) {
+ *         // async code to get some data
+ *         callback(null, 'data', 'converted to array');
+ *     },
+ *     make_folder: function(callback) {
+ *         // async code to create a directory to store a file in
+ *         // this is run at the same time as getting the data
+ *         callback(null, 'folder');
+ *     },
+ *     write_file: function(get_data, make_folder, callback) {
+ *         // once there is some data and the directory exists,
+ *         // write the data to a file in the directory
+ *         callback(null, 'filename');
+ *     },
+ *     email_link: function(write_file, callback) {
+ *         // once the file is written let's email a link to it...
+ *         // write_file contains the filename returned by write_file.
+ *         callback(null, {'file':write_file, 'email':'user@example.com'});
+ *     }
+ * }, function(err, results) {
+ *     console.log('err = ', err);
+ *     console.log('email_link = ', results.email_link);
+ * });
+ *
+ * // If you are using a JS minifier that mangles parameter names, `autoInject`
+ * // will not work with plain functions, since the parameter names will be
+ * // collapsed to a single letter identifier.  To work around this, you can
+ * // explicitly specify the names of the parameters your task function needs
+ * // in an array, similar to Angular.js dependency injection.
+ *
+ * // This still has an advantage over plain `auto`, since the results a task
+ * // depends on are still spread into arguments.
+ * async.autoInject({
+ *     //...
+ *     write_file: ['get_data', 'make_folder', function(get_data, make_folder, callback) {
+ *         callback(null, 'filename');
+ *     }],
+ *     email_link: ['write_file', function(write_file, callback) {
+ *         callback(null, {'file':write_file, 'email':'user@example.com'});
+ *     }]
+ *     //...
+ * }, function(err, results) {
+ *     console.log('err = ', err);
+ *     console.log('email_link = ', results.email_link);
+ * });
+ */
+export default function autoInject(tasks, callback) {
+    var newTasks = {};
+
+    forOwn(tasks, function (taskFn, key) {
+        var params;
+
+        if (isArray(taskFn)) {
+            params = taskFn.slice(0, -1);
+            taskFn = taskFn[taskFn.length - 1];
+
+            newTasks[key] = params.concat(params.length > 0 ? newTask : taskFn);
+        } else if (taskFn.length === 1) {
+            // no dependencies, use the function as-is
+            newTasks[key] = taskFn;
+        } else {
+            params = parseParams(taskFn);
+            if (taskFn.length === 0 && params.length === 0) {
+                throw new Error("autoInject task functions require explicit parameters.");
+            }
+
+            params.pop();
+
+            newTasks[key] = params.concat(newTask);
+        }
+
+        function newTask(results, taskCb) {
+            var newArgs = arrayMap(params, function (name) {
+                return results[name];
+            });
+            newArgs.push(taskCb);
+            taskFn.apply(null, newArgs);
+        }
+    });
+
+    auto(newTasks, callback);
+}
+
+
+
+ + + + +
+
+ + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/cargo.js.html b/cargo.js.html new file mode 100644 index 000000000..cee651733 --- /dev/null +++ b/cargo.js.html @@ -0,0 +1,190 @@ + + + + + + + cargo.js - Documentation + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +

cargo.js

+ + + + + + + +
+
+
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`]{@link module:ControlFlow.queue}.
+ * @typedef {Object} CargoObject
+ * @memberOf module:ControlFlow
+ * @property {Function} length - A function returning the number of items
+ * waiting to be processed. Invoke like `cargo.length()`.
+ * @property {number} payload - An `integer` for determining how many tasks
+ * should be process per round. This property can be changed after a `cargo` is
+ * created to alter the payload on-the-fly.
+ * @property {Function} push - Adds `task` to the `queue`. The callback is
+ * called once the `worker` has finished processing the task. Instead of a
+ * single task, an array of `tasks` can be submitted. The respective callback is
+ * used for every task in the list. Invoke like `cargo.push(task, [callback])`.
+ * @property {Function} saturated - A callback that is called when the
+ * `queue.length()` hits the concurrency and further tasks will be queued.
+ * @property {Function} empty - A callback that is called when the last item
+ * from the `queue` is given to a `worker`.
+ * @property {Function} drain - A callback that is called when the last item
+ * from the `queue` has returned from the `worker`.
+ * @property {Function} idle - a function returning false if there are items
+ * waiting or being processed, or true if not. Invoke like `cargo.idle()`.
+ * @property {Function} pause - a function that pauses the processing of tasks
+ * until `resume()` is called. Invoke like `cargo.pause()`.
+ * @property {Function} resume - a function that resumes the processing of
+ * queued tasks when the queue is paused. Invoke like `cargo.resume()`.
+ * @property {Function} kill - a function that removes the `drain` callback and
+ * empties remaining tasks from the queue forcing it to go idle. Invoke like `cargo.kill()`.
+ */
+
+/**
+ * Creates a `cargo` object with the specified payload. Tasks added to the
+ * cargo will be processed altogether (up to the `payload` limit). If the
+ * `worker` is in progress, the task is queued until it becomes available. Once
+ * the `worker` has completed some tasks, each callback of those tasks is
+ * called. Check out [these](https://camo.githubusercontent.com/6bbd36f4cf5b35a0f11a96dcd2e97711ffc2fb37/68747470733a2f2f662e636c6f75642e6769746875622e636f6d2f6173736574732f313637363837312f36383130382f62626330636662302d356632392d313165322d393734662d3333393763363464633835382e676966) [animations](https://camo.githubusercontent.com/f4810e00e1c5f5f8addbe3e9f49064fd5d102699/68747470733a2f2f662e636c6f75642e6769746875622e636f6d2f6173736574732f313637363837312f36383130312f38346339323036362d356632392d313165322d383134662d3964336430323431336266642e676966)
+ * for how `cargo` and `queue` work.
+ *
+ * While [`queue`]{@link module:ControlFlow.queue} passes only one task to one of a group of workers
+ * at a time, cargo passes an array of tasks to a single worker, repeating
+ * when the worker is finished.
+ *
+ * @name cargo
+ * @static
+ * @memberOf module:ControlFlow
+ * @method
+ * @see [async.queue]{@link module:ControlFlow.queue}
+ * @category Control Flow
+ * @param {Function} worker - An asynchronous function for processing an array
+ * of queued tasks, which must call its `callback(err)` argument when finished,
+ * with an optional `err` argument. Invoked with `(tasks, callback)`.
+ * @param {number} [payload=Infinity] - An optional `integer` for determining
+ * how many tasks should be processed per round; if omitted, the default is
+ * unlimited.
+ * @returns {module:ControlFlow.CargoObject} A cargo object to manage the tasks. Callbacks can
+ * attached as certain properties to listen for specific events during the
+ * lifecycle of the cargo and inner queue.
+ * @example
+ *
+ * // create a cargo object with payload 2
+ * var cargo = async.cargo(function(tasks, callback) {
+ *     for (var i=0; i<tasks.length; i++) {
+ *         console.log('hello ' + tasks[i].name);
+ *     }
+ *     callback();
+ * }, 2);
+ *
+ * // add some items
+ * cargo.push({name: 'foo'}, function(err) {
+ *     console.log('finished processing foo');
+ * });
+ * cargo.push({name: 'bar'}, function(err) {
+ *     console.log('finished processing bar');
+ * });
+ * cargo.push({name: 'baz'}, function(err) {
+ *     console.log('finished processing baz');
+ * });
+ */
+export default function cargo(worker, payload) {
+    return queue(worker, 1, payload);
+}
+
+
+
+ + + + +
+
+ + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/compose.js.html b/compose.js.html new file mode 100644 index 000000000..e44d2e903 --- /dev/null +++ b/compose.js.html @@ -0,0 +1,148 @@ + + + + + + + compose.js - Documentation + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +

compose.js

+ + + + + + + +
+
+
import seq from './seq';
+import rest from './internal/rest';
+
+/**
+ * Creates a function which is a composition of the passed asynchronous
+ * functions. Each function consumes the return value of the function that
+ * follows. Composing functions `f()`, `g()`, and `h()` would produce the result
+ * of `f(g(h()))`, only this version uses callbacks to obtain the return values.
+ *
+ * Each function is executed with the `this` binding of the composed function.
+ *
+ * @name compose
+ * @static
+ * @memberOf module:ControlFlow
+ * @method
+ * @category Control Flow
+ * @param {...Function} functions - the asynchronous functions to compose
+ * @returns {Function} an asynchronous function that is the composed
+ * asynchronous `functions`
+ * @example
+ *
+ * function add1(n, callback) {
+ *     setTimeout(function () {
+ *         callback(null, n + 1);
+ *     }, 10);
+ * }
+ *
+ * function mul3(n, callback) {
+ *     setTimeout(function () {
+ *         callback(null, n * 3);
+ *     }, 10);
+ * }
+ *
+ * var add1mul3 = async.compose(mul3, add1);
+ * add1mul3(4, function (err, result) {
+ *     // result now equals 15
+ * });
+ */
+export default rest(function(args) {
+    return seq.apply(null, args.reverse());
+});
+
+
+
+ + + + +
+
+ + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/concat.js.html b/concat.js.html new file mode 100644 index 000000000..6cedb3ef8 --- /dev/null +++ b/concat.js.html @@ -0,0 +1,138 @@ + + + + + + + concat.js - Documentation + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +

concat.js

+ + + + + + + +
+
+
import concat from './internal/concat';
+import doParallel from './internal/doParallel';
+
+/**
+ * Applies `iteratee` to each item in `coll`, concatenating the results. Returns
+ * the concatenated list. The `iteratee`s are called in parallel, and the
+ * results are concatenated as they return. There is no guarantee that the
+ * results array will be returned in the original order of `coll` passed to the
+ * `iteratee` function.
+ *
+ * @name concat
+ * @static
+ * @memberOf module:Collections
+ * @method
+ * @category Collection
+ * @param {Array|Iterable|Object} coll - A collection to iterate over.
+ * @param {Function} iteratee - A function to apply to each item in `coll`.
+ * The iteratee is passed a `callback(err, results)` which must be called once
+ * it has completed with an error (which can be `null`) and an array of results.
+ * Invoked with (item, callback).
+ * @param {Function} [callback(err)] - A callback which is called after all the
+ * `iteratee` functions have finished, or an error occurs. Results is an array
+ * containing the concatenated results of the `iteratee` function. Invoked with
+ * (err, results).
+ * @example
+ *
+ * async.concat(['dir1','dir2','dir3'], fs.readdir, function(err, files) {
+ *     // files is now a list of filenames that exist in the 3 directories
+ * });
+ */
+export default doParallel(concat);
+
+
+
+ + + + +
+
+ + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/concatSeries.js.html b/concatSeries.js.html new file mode 100644 index 000000000..d73fe254a --- /dev/null +++ b/concatSeries.js.html @@ -0,0 +1,130 @@ + + + + + + + concatSeries.js - Documentation + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +

concatSeries.js

+ + + + + + + +
+
+
import concat from './internal/concat';
+import doSeries from './internal/doSeries';
+
+/**
+ * The same as [`concat`]{@link module:Collections.concat} but runs only a single async operation at a time.
+ *
+ * @name concatSeries
+ * @static
+ * @memberOf module:Collections
+ * @method
+ * @see [async.concat]{@link module:Collections.concat}
+ * @category Collection
+ * @param {Array|Iterable|Object} coll - A collection to iterate over.
+ * @param {Function} iteratee - A function to apply to each item in `coll`.
+ * The iteratee is passed a `callback(err, results)` which must be called once
+ * it has completed with an error (which can be `null`) and an array of results.
+ * Invoked with (item, callback).
+ * @param {Function} [callback(err)] - A callback which is called after all the
+ * `iteratee` functions have finished, or an error occurs. Results is an array
+ * containing the concatenated results of the `iteratee` function. Invoked with
+ * (err, results).
+ */
+export default doSeries(concat);
+
+
+
+ + + + +
+
+ + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/constant.js.html b/constant.js.html new file mode 100644 index 000000000..c8d7537c5 --- /dev/null +++ b/constant.js.html @@ -0,0 +1,158 @@ + + + + + + + constant.js - Documentation + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +

constant.js

+ + + + + + + +
+
+
import rest from './internal/rest';
+import initialParams from './internal/initialParams';
+
+/**
+ * Returns a function that when called, calls-back with the values provided.
+ * Useful as the first function in a [`waterfall`]{@link module:ControlFlow.waterfall}, or for plugging values in to
+ * [`auto`]{@link module:ControlFlow.auto}.
+ *
+ * @name constant
+ * @static
+ * @memberOf module:Utils
+ * @method
+ * @category Util
+ * @param {...*} arguments... - Any number of arguments to automatically invoke
+ * callback with.
+ * @returns {Function} Returns a function that when invoked, automatically
+ * invokes the callback with the previous given arguments.
+ * @example
+ *
+ * async.waterfall([
+ *     async.constant(42),
+ *     function (value, next) {
+ *         // value === 42
+ *     },
+ *     //...
+ * ], callback);
+ *
+ * async.waterfall([
+ *     async.constant(filename, "utf8"),
+ *     fs.readFile,
+ *     function (fileData, next) {
+ *         //...
+ *     }
+ *     //...
+ * ], callback);
+ *
+ * async.auto({
+ *     hostname: async.constant("https://server.net/"),
+ *     port: findFreePort,
+ *     launchServer: ["hostname", "port", function (options, cb) {
+ *         startServer(options, cb);
+ *     }],
+ *     //...
+ * }, callback);
+ */
+export default rest(function(values) {
+    var args = [null].concat(values);
+    return initialParams(function (ignoredArgs, callback) {
+        return callback.apply(this, args);
+    });
+});
+
+
+
+ + + + +
+
+ + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/data/methodNames.json b/data/methodNames.json new file mode 100644 index 000000000..8ce73b6b7 --- /dev/null +++ b/data/methodNames.json @@ -0,0 +1,74 @@ +[ + "apply", + "applyEach", + "applyEachSeries", + "asyncify (wrapSync)", + "auto", + "autoInject", + "cargo", + "compose", + "concat", + "concatSeries", + "constant", + "detect (find)", + "detectLimit (findLimit)", + "detectSeries (findSeries)", + "dir", + "doDuring", + "doUntil", + "doWhilst", + "during", + "each (forEach)", + "eachLimit (forEachLimit)", + "eachOf (forEachOf)", + "eachOfLimit (forEachOfLimit)", + "eachOfSeries (forEachOfSeries)", + "eachSeries (forEachSeries)", + "ensureAsync", + "every (all)", + "everyLimit (allLimit)", + "everySeries (allSeries)", + "filter (select)", + "filterLimit (selectLimit)", + "filterSeries (selectSeries)", + "forever", + "log", + "map", + "mapLimit", + "mapSeries", + "mapValues", + "mapValuesLimit", + "mapValuesSeries", + "memoize", + "nextTick (setImmediate)", + "parallel", + "parallelLimit", + "priorityQueue", + "queue", + "race", + "reduce (foldl)", + "reduceRight (foldr)", + "reflect", + "reflectAll", + "reject", + "rejectLimit", + "rejectSeries", + "retry", + "retryable", + "seq", + "series", + "setImmediate (nextTick)", + "some (any)", + "someLimit (anyLimit)", + "someSeries (anySeries)", + "sortBy", + "timeout", + "times", + "timesLimit", + "timesSeries", + "transform", + "unmemoize", + "until", + "waterfall", + "whilst" +] diff --git a/data/sourceFiles.json b/data/sourceFiles.json new file mode 100644 index 000000000..480c2a56f --- /dev/null +++ b/data/sourceFiles.json @@ -0,0 +1,75 @@ +[ + "apply.js.html", + "applyEach.js.html", + "applyEachSeries.js.html", + "asyncify.js.html", + "auto.js.html", + "autoInject.js.html", + "cargo.js.html", + "compose.js.html", + "concat.js.html", + "concatSeries.js.html", + "constant.js.html", + "detect.js.html", + "detectLimit.js.html", + "detectSeries.js.html", + "dir.js.html", + "doDuring.js.html", + "doUntil.js.html", + "doWhilst.js.html", + "during.js.html", + "each.js.html", + "eachLimit.js.html", + "eachOf.js.html", + "eachOfLimit.js.html", + "eachOfSeries.js.html", + "eachSeries.js.html", + "ensureAsync.js.html", + "every.js.html", + "everyLimit.js.html", + "everySeries.js.html", + "filter.js.html", + "filterLimit.js.html", + "filterSeries.js.html", + "forever.js.html", + "index.js.html", + "log.js.html", + "map.js.html", + "mapLimit.js.html", + "mapSeries.js.html", + "mapValues.js.html", + "mapValuesLimit.js.html", + "mapValuesSeries.js.html", + "memoize.js.html", + "nextTick.js.html", + "parallel.js.html", + "parallelLimit.js.html", + "priorityQueue.js.html", + "queue.js.html", + "race.js.html", + "reduce.js.html", + "reduceRight.js.html", + "reflect.js.html", + "reflectAll.js.html", + "reject.js.html", + "rejectLimit.js.html", + "rejectSeries.js.html", + "retry.js.html", + "retryable.js.html", + "seq.js.html", + "series.js.html", + "setImmediate.js.html", + "some.js.html", + "someLimit.js.html", + "someSeries.js.html", + "sortBy.js.html", + "timeout.js.html", + "times.js.html", + "timesLimit.js.html", + "timesSeries.js.html", + "transform.js.html", + "unmemoize.js.html", + "until.js.html", + "waterfall.js.html", + "whilst.js.html" +] diff --git a/detect.js.html b/detect.js.html new file mode 100644 index 000000000..27d9ba0a0 --- /dev/null +++ b/detect.js.html @@ -0,0 +1,149 @@ + + + + + + + detect.js - Documentation + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +

detect.js

+ + + + + + + +
+
+
import identity from 'lodash/identity';
+
+import createTester from './internal/createTester';
+import doParallel from './internal/doParallel';
+import findGetResult from './internal/findGetResult';
+
+/**
+ * Returns the first value in `coll` that passes an async truth test. The
+ * `iteratee` is applied in parallel, meaning the first iteratee to return
+ * `true` will fire the detect `callback` with that result. That means the
+ * result might not be the first item in the original `coll` (in terms of order)
+ * that passes the test.
+
+ * If order within the original `coll` is important, then look at
+ * [`detectSeries`]{@link module:Collections.detectSeries}.
+ *
+ * @name detect
+ * @static
+ * @memberOf module:Collections
+ * @method
+ * @alias find
+ * @category Collections
+ * @param {Array|Iterable|Object} coll - A collection to iterate over.
+ * @param {Function} iteratee - A truth test to apply to each item in `coll`.
+ * The iteratee is passed a `callback(err, truthValue)` which must be called
+ * with a boolean argument once it has completed. Invoked with (item, callback).
+ * @param {Function} [callback] - A callback which is called as soon as any
+ * iteratee returns `true`, or after all the `iteratee` functions have finished.
+ * Result will be the first item in the array that passes the truth test
+ * (iteratee) or the value `undefined` if none passed. Invoked with
+ * (err, result).
+ * @example
+ *
+ * async.detect(['file1','file2','file3'], function(filePath, callback) {
+ *     fs.access(filePath, function(err) {
+ *         callback(null, !err)
+ *     });
+ * }, function(err, result) {
+ *     // result now equals the first file in the list that exists
+ * });
+ */
+export default doParallel(createTester(identity, findGetResult));
+
+
+
+ + + + +
+
+ + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/detectLimit.js.html b/detectLimit.js.html new file mode 100644 index 000000000..6cbf3bb4b --- /dev/null +++ b/detectLimit.js.html @@ -0,0 +1,136 @@ + + + + + + + detectLimit.js - Documentation + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +

detectLimit.js

+ + + + + + + +
+
+
import identity from 'lodash/identity';
+
+import createTester from './internal/createTester';
+import doParallelLimit from './internal/doParallelLimit';
+import findGetResult from './internal/findGetResult';
+
+/**
+ * The same as [`detect`]{@link module:Collections.detect} but runs a maximum of `limit` async operations at a
+ * time.
+ *
+ * @name detectLimit
+ * @static
+ * @memberOf module:Collections
+ * @method
+ * @see [async.detect]{@link module:Collections.detect}
+ * @alias findLimit
+ * @category Collections
+ * @param {Array|Iterable|Object} coll - A collection to iterate over.
+ * @param {number} limit - The maximum number of async operations at a time.
+ * @param {Function} iteratee - A truth test to apply to each item in `coll`.
+ * The iteratee is passed a `callback(err, truthValue)` which must be called
+ * with a boolean argument once it has completed. Invoked with (item, callback).
+ * @param {Function} [callback] - A callback which is called as soon as any
+ * iteratee returns `true`, or after all the `iteratee` functions have finished.
+ * Result will be the first item in the array that passes the truth test
+ * (iteratee) or the value `undefined` if none passed. Invoked with
+ * (err, result).
+ */
+export default doParallelLimit(createTester(identity, findGetResult));
+
+
+
+ + + + +
+
+ + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/detectSeries.js.html b/detectSeries.js.html new file mode 100644 index 000000000..3cb15b21d --- /dev/null +++ b/detectSeries.js.html @@ -0,0 +1,131 @@ + + + + + + + detectSeries.js - Documentation + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +

detectSeries.js

+ + + + + + + +
+
+
import detectLimit from './detectLimit';
+import doLimit from './internal/doLimit';
+
+/**
+ * The same as [`detect`]{@link module:Collections.detect} but runs only a single async operation at a time.
+ *
+ * @name detectSeries
+ * @static
+ * @memberOf module:Collections
+ * @method
+ * @see [async.detect]{@link module:Collections.detect}
+ * @alias findSeries
+ * @category Collections
+ * @param {Array|Iterable|Object} coll - A collection to iterate over.
+ * @param {Function} iteratee - A truth test to apply to each item in `coll`.
+ * The iteratee is passed a `callback(err, truthValue)` which must be called
+ * with a boolean argument once it has completed. Invoked with (item, callback).
+ * @param {Function} [callback] - A callback which is called as soon as any
+ * iteratee returns `true`, or after all the `iteratee` functions have finished.
+ * Result will be the first item in the array that passes the truth test
+ * (iteratee) or the value `undefined` if none passed. Invoked with
+ * (err, result).
+ */
+export default doLimit(detectLimit, 1);
+
+
+
+ + + + +
+
+ + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/dir.js.html b/dir.js.html new file mode 100644 index 000000000..f1d18e57d --- /dev/null +++ b/dir.js.html @@ -0,0 +1,138 @@ + + + + + + + dir.js - Documentation + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +

dir.js

+ + + + + + + +
+
+
import consoleFunc from './internal/consoleFunc';
+
+/**
+ * Logs the result of an `async` function to the `console` using `console.dir`
+ * to display the properties of the resulting object. Only works in Node.js or
+ * in browsers that support `console.dir` and `console.error` (such as FF and
+ * Chrome). If multiple arguments are returned from the async function,
+ * `console.dir` is called on each argument in order.
+ *
+ * @name dir
+ * @static
+ * @memberOf module:Utils
+ * @method
+ * @category Util
+ * @param {Function} function - The function you want to eventually apply all
+ * arguments to.
+ * @param {...*} arguments... - Any number of arguments to apply to the function.
+ * @example
+ *
+ * // in a module
+ * var hello = function(name, callback) {
+ *     setTimeout(function() {
+ *         callback(null, {hello: name});
+ *     }, 1000);
+ * };
+ *
+ * // in the node repl
+ * node> async.dir(hello, 'world');
+ * {hello: 'world'}
+ */
+export default consoleFunc('dir');
+
+
+
+ + + + +
+
+ + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/doDuring.js.html b/doDuring.js.html new file mode 100644 index 000000000..886d42753 --- /dev/null +++ b/doDuring.js.html @@ -0,0 +1,151 @@ + + + + + + + doDuring.js - Documentation + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +

doDuring.js

+ + + + + + + +
+
+
import noop from 'lodash/noop';
+import rest from './internal/rest';
+import onlyOnce from './internal/onlyOnce';
+
+/**
+ * The post-check version of [`during`]{@link module:ControlFlow.during}. To reflect the difference in
+ * the order of operations, the arguments `test` and `fn` are switched.
+ *
+ * Also a version of [`doWhilst`]{@link module:ControlFlow.doWhilst} with asynchronous `test` function.
+ * @name doDuring
+ * @static
+ * @memberOf module:ControlFlow
+ * @method
+ * @see [async.during]{@link module:ControlFlow.during}
+ * @category Control Flow
+ * @param {Function} fn - A function which is called each time `test` passes.
+ * The function is passed a `callback(err)`, which must be called once it has
+ * completed with an optional `err` argument. Invoked with (callback).
+ * @param {Function} test - asynchronous truth test to perform before each
+ * execution of `fn`. Invoked with (...args, callback), where `...args` are the
+ * non-error args from the previous callback of `fn`.
+ * @param {Function} [callback] - A callback which is called after the test
+ * function has failed and repeated execution of `fn` has stopped. `callback`
+ * will be passed an error if one occured, otherwise `null`.
+ */
+export default function doDuring(fn, test, callback) {
+    callback = onlyOnce(callback || noop);
+
+    var next = rest(function(err, args) {
+        if (err)  return callback(err);
+        args.push(check);
+        test.apply(this, args);
+    });
+
+    function check(err, truth) {
+        if (err) return callback(err);
+        if (!truth) return callback(null);
+        fn(next);
+    }
+
+    check(null, true);
+
+}
+
+
+
+
+ + + + +
+
+ + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/doUntil.js.html b/doUntil.js.html new file mode 100644 index 000000000..36ff42c04 --- /dev/null +++ b/doUntil.js.html @@ -0,0 +1,134 @@ + + + + + + + doUntil.js - Documentation + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +

doUntil.js

+ + + + + + + +
+
+
import doWhilst from './doWhilst';
+
+/**
+ * Like ['doWhilst']{@link module:ControlFlow.doWhilst}, except the `test` is inverted. Note the
+ * argument ordering differs from `until`.
+ *
+ * @name doUntil
+ * @static
+ * @memberOf module:ControlFlow
+ * @method
+ * @see [async.doWhilst]{@link module:ControlFlow.doWhilst}
+ * @category Control Flow
+ * @param {Function} fn - A function which is called each time `test` fails.
+ * The function is passed a `callback(err)`, which must be called once it has
+ * completed with an optional `err` argument. Invoked with (callback).
+ * @param {Function} test - synchronous truth test to perform after each
+ * execution of `fn`. Invoked with the non-error callback results of `fn`.
+ * @param {Function} [callback] - A callback which is called after the test
+ * function has passed and repeated execution of `fn` has stopped. `callback`
+ * will be passed an error and any arguments passed to the final `fn`'s
+ * callback. Invoked with (err, [results]);
+ */
+export default function doUntil(fn, test, callback) {
+    doWhilst(fn, function() {
+        return !test.apply(this, arguments);
+    }, callback);
+}
+
+
+
+ + + + +
+
+ + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/doWhilst.js.html b/doWhilst.js.html new file mode 100644 index 000000000..cb76b81e6 --- /dev/null +++ b/doWhilst.js.html @@ -0,0 +1,144 @@ + + + + + + + doWhilst.js - Documentation + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +

doWhilst.js

+ + + + + + + +
+
+
import noop from 'lodash/noop';
+import rest from './internal/rest';
+
+import onlyOnce from './internal/onlyOnce';
+
+/**
+ * The post-check version of [`whilst`]{@link module:ControlFlow.whilst}. To reflect the difference in
+ * the order of operations, the arguments `test` and `iteratee` are switched.
+ *
+ * `doWhilst` is to `whilst` as `do while` is to `while` in plain JavaScript.
+ *
+ * @name doWhilst
+ * @static
+ * @memberOf module:ControlFlow
+ * @method
+ * @see [async.whilst]{@link module:ControlFlow.whilst}
+ * @category Control Flow
+ * @param {Function} iteratee - A function which is called each time `test`
+ * passes. The function is passed a `callback(err)`, which must be called once
+ * it has completed with an optional `err` argument. Invoked with (callback).
+ * @param {Function} test - synchronous truth test to perform after each
+ * execution of `iteratee`. Invoked with the non-error callback results of 
+ * `iteratee`.
+ * @param {Function} [callback] - A callback which is called after the test
+ * function has failed and repeated execution of `iteratee` has stopped.
+ * `callback` will be passed an error and any arguments passed to the final
+ * `iteratee`'s callback. Invoked with (err, [results]);
+ */
+export default function doWhilst(iteratee, test, callback) {
+    callback = onlyOnce(callback || noop);
+    var next = rest(function(err, args) {
+        if (err) return callback(err);
+        if (test.apply(this, args)) return iteratee(next);
+        callback.apply(null, [null].concat(args));
+    });
+    iteratee(next);
+}
+
+
+
+ + + + +
+
+ + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/docs.html b/docs.html new file mode 100644 index 000000000..b1fa33074 --- /dev/null +++ b/docs.html @@ -0,0 +1,16576 @@ + + + + + + + + async - Documentation + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +

async

+ + + + + + + +
+ +
+ + + + + +
+ +
+
+ + +

Async is a utility module which provides straight-forward, powerful functions +for working with asynchronous JavaScript. Although originally designed for +use with Node.js and installable via +npm install --save async, it can also be used directly in the browser.

+ + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + +

Collections

+ + + + + + + +
+ +
+ + + + + +
+ +
+
+ + +

A collection of async functions for manipulating collections, such as +arrays and objects.

+ + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + +

Methods

+ + + + + + +

(static) concat(coll, iteratee, callback(err)opt)

+ + + + + +
+
import concat from 'async/concat';

Applies iteratee to each item in coll, concatenating the results. Returns +the concatenated list. The iteratees 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.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
coll + + +Array +| + +Iterable +| + +Object + + + + + +

A collection to iterate over.

iteratee + + +function + + + + + +

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).

callback(err) + + +function + + + + + + <optional> + +

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
+});
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + +

(static) concatSeries(coll, iteratee, callback(err)opt)

+ + + + + +
+
import concatSeries from 'async/concatSeries';

The same as concat but runs only a single async operation at a time.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
coll + + +Array +| + +Iterable +| + +Object + + + + + +

A collection to iterate over.

iteratee + + +function + + + + + +

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).

callback(err) + + +function + + + + + + <optional> + +

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).

+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +

(static) detect(coll, iteratee, callbackopt)

+ + + + + +
+
import detect from 'async/detect';

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.

+
+ + + +
+
Alias:
+
  • find
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
coll + + +Array +| + +Iterable +| + +Object + + + + + +

A collection to iterate over.

iteratee + + +function + + + + + +

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).

callback + + +function + + + + + + <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 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
+});
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + +

(static) detectLimit(coll, limit, iteratee, callbackopt)

+ + + + + +
+
import detectLimit from 'async/detectLimit';

The same as detect but runs a maximum of limit async operations at a +time.

+
+ + + +
+
Alias:
+
  • findLimit
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
coll + + +Array +| + +Iterable +| + +Object + + + + + +

A collection to iterate over.

limit + + +number + + + + + +

The maximum number of async operations at a time.

iteratee + + +function + + + + + +

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).

callback + + +function + + + + + + <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 value undefined if none passed. Invoked with +(err, result).

+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +

(static) detectSeries(coll, iteratee, callbackopt)

+ + + + + +
+
import detectSeries from 'async/detectSeries';

The same as detect but runs only a single async operation at a time.

+
+ + + +
+
Alias:
+
  • findSeries
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
coll + + +Array +| + +Iterable +| + +Object + + + + + +

A collection to iterate over.

iteratee + + +function + + + + + +

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).

callback + + +function + + + + + + <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 value undefined if none passed. Invoked with +(err, result).

+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +

(static) each(coll, iteratee, callbackopt)

+ + + + + +
+
import each from 'async/each';

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.

+
+ + + +
+
Alias:
+
  • forEach
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
coll + + +Array +| + +Iterable +| + +Object + + + + + +

A collection to iterate over.

iteratee + + +function + + + + + +

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.

callback + + +function + + + + + + <optional> + +

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');
+    }
+});
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + +

(static) eachLimit(coll, limit, iteratee, callbackopt)

+ + + + + +
+
import eachLimit from 'async/eachLimit';

The same as each but runs a maximum of limit async operations at a time.

+
+ + + +
+
Alias:
+
  • forEachLimit
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
coll + + +Array +| + +Iterable +| + +Object + + + + + +

A collection to iterate over.

limit + + +number + + + + + +

The maximum number of async operations at a time.

iteratee + + +function + + + + + +

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.

callback + + +function + + + + + + <optional> + +

A callback which is called when all +iteratee functions have finished, or an error occurs. Invoked with (err).

+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +

(static) eachOf(coll, iteratee, callbackopt)

+ + + + + +
+
import eachOf from 'async/eachOf';

Like each, except that it passes the key (or index) as the second argument +to the iteratee.

+
+ + + +
+
Alias:
+
  • forEachOf
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
coll + + +Array +| + +Iterable +| + +Object + + + + + +

A collection to iterate over.

iteratee + + +function + + + + + +

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).

callback + + +function + + + + + + <optional> + +

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);
+});
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +

(static) eachOfLimit(coll, limit, iteratee, callbackopt)

+ + + + + +
+
import eachOfLimit from 'async/eachOfLimit';

The same as eachOf but runs a maximum of limit async operations at a +time.

+
+ + + +
+
Alias:
+
  • forEachOfLimit
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
coll + + +Array +| + +Iterable +| + +Object + + + + + +

A collection to iterate over.

limit + + +number + + + + + +

The maximum number of async operations at a time.

iteratee + + +function + + + + + +

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).

callback + + +function + + + + + + <optional> + +

A callback which is called when all +iteratee functions have finished, or an error occurs. Invoked with (err).

+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +

(static) eachOfSeries(coll, iteratee, callbackopt)

+ + + + + +
+
import eachOfSeries from 'async/eachOfSeries';

The same as eachOf but runs only a single async operation at a time.

+
+ + + +
+
Alias:
+
  • forEachOfSeries
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
coll + + +Array +| + +Iterable +| + +Object + + + + + +

A collection to iterate over.

iteratee + + +function + + + + + +

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).

callback + + +function + + + + + + <optional> + +

A callback which is called when all iteratee +functions have finished, or an error occurs. Invoked with (err).

+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +

(static) eachSeries(coll, iteratee, callbackopt)

+ + + + + +
+
import eachSeries from 'async/eachSeries';

The same as each but runs only a single async operation at a time.

+
+ + + +
+
Alias:
+
  • forEachSeries
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
coll + + +Array +| + +Iterable +| + +Object + + + + + +

A collection to iterate over.

iteratee + + +function + + + + + +

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.

callback + + +function + + + + + + <optional> + +

A callback which is called when all +iteratee functions have finished, or an error occurs. Invoked with (err).

+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +

(static) every(coll, iteratee, callbackopt)

+ + + + + +
+
import every from 'async/every';

Returns true if every element in coll satisfies an async test. If any +iteratee call returns false, the main callback is immediately called.

+
+ + + +
+
Alias:
+
  • all
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
coll + + +Array +| + +Iterable +| + +Object + + + + + +

A collection to iterate over.

iteratee + + +function + + + + + +

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).

callback + + +function + + + + + + <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. 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
+});
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + +

(static) everyLimit(coll, limit, iteratee, callbackopt)

+ + + + + +
+
import everyLimit from 'async/everyLimit';

The same as every but runs a maximum of limit async operations at a time.

+
+ + + +
+
Alias:
+
  • allLimit
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
coll + + +Array +| + +Iterable +| + +Object + + + + + +

A collection to iterate over.

limit + + +number + + + + + +

The maximum number of async operations at a time.

iteratee + + +function + + + + + +

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).

callback + + +function + + + + + + <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. Invoked with (err, result).

+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +

(static) everySeries(coll, iteratee, callbackopt)

+ + + + + +
+
import everySeries from 'async/everySeries';

The same as every but runs only a single async operation at a time.

+
+ + + +
+
Alias:
+
  • allSeries
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
coll + + +Array +| + +Iterable +| + +Object + + + + + +

A collection to iterate over.

iteratee + + +function + + + + + +

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).

callback + + +function + + + + + + <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. Invoked with (err, result).

+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +

(static) filter(coll, iteratee, callbackopt)

+ + + + + +
+
import filter from 'async/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.

+
+ + + +
+
Alias:
+
  • select
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
coll + + +Array +| + +Iterable +| + +Object + + + + + +

A collection to iterate over.

iteratee + + +function + + + + + +

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).

callback + + +function + + + + + + <optional> + +

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
+});
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + +

(static) filterLimit(coll, limit, iteratee, callbackopt)

+ + + + + +
+
import filterLimit from 'async/filterLimit';

The same as filter but runs a maximum of limit async operations at a +time.

+
+ + + +
+
Alias:
+
  • selectLimit
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
coll + + +Array +| + +Iterable +| + +Object + + + + + +

A collection to iterate over.

limit + + +number + + + + + +

The maximum number of async operations at a time.

iteratee + + +function + + + + + +

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).

callback + + +function + + + + + + <optional> + +

A callback which is called after all the +iteratee functions have finished. Invoked with (err, results).

+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +

(static) filterSeries(coll, iteratee, callbackopt)

+ + + + + +
+
import filterSeries from 'async/filterSeries';

The same as filter but runs only a single async operation at a time.

+
+ + + +
+
Alias:
+
  • selectSeries
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
coll + + +Array +| + +Iterable +| + +Object + + + + + +

A collection to iterate over.

iteratee + + +function + + + + + +

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).

callback + + +function + + + + + + <optional> + +

A callback which is called after all the +iteratee functions have finished. Invoked with (err, results)

+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +

(static) map(coll, iteratee, callbackopt)

+ + + + + +
+
import map from 'async/map';

Produces a new collection of values by mapping each value in coll through +the iteratee function. The iteratee is called with an item from coll +and a callback for when it has finished processing. Each of these callback +takes 2 arguments: an error, and the transformed item from coll. If +iteratee passes an error to its callback, the main callback (for the +map function) is immediately called with the error.

+

Note, that since this function applies the iteratee to each item in +parallel, there is no guarantee that the iteratee functions will complete +in order. However, the results array will be in the same order as the +original coll.

+

If map is passed an Object, the results will be an Array. The results +will roughly be in the order of the original Objects' keys (but this can +vary across JavaScript engines)

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
coll + + +Array +| + +Iterable +| + +Object + + + + + +

A collection to iterate over.

iteratee + + +function + + + + + +

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).

callback + + +function + + + + + + <optional> + +

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
+});
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + +

(static) mapLimit(coll, limit, iteratee, callbackopt)

+ + + + + +
+
import mapLimit from 'async/mapLimit';

The same as map but runs a maximum of limit async operations at a time.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
coll + + +Array +| + +Iterable +| + +Object + + + + + +

A collection to iterate over.

limit + + +number + + + + + +

The maximum number of async operations at a time.

iteratee + + +function + + + + + +

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).

callback + + +function + + + + + + <optional> + +

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).

+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +

(static) mapSeries(coll, iteratee, callbackopt)

+ + + + + +
+
import mapSeries from 'async/mapSeries';

The same as map but runs only a single async operation at a time.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
coll + + +Array +| + +Iterable +| + +Object + + + + + +

A collection to iterate over.

iteratee + + +function + + + + + +

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).

callback + + +function + + + + + + <optional> + +

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).

+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +

(static) mapValues(obj, iteratee, callbackopt)

+ + + + + +
+
import mapValues from 'async/mapValues';

A relative of map, designed for use with objects.

+

Produces a new Object by mapping each value of obj through the iteratee +function. The iteratee is called each value and key from obj and a +callback for when it has finished processing. Each of these callbacks takes +two arguments: an error, and the transformed item from obj. If iteratee +passes an error to its callback, the main callback (for the mapValues +function) is immediately called with the error.

+

Note, the order of the keys in the result is not guaranteed. The keys will +be roughly in the order they complete, (but this is very engine-specific)

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
obj + + +Object + + + + + +

A collection to iterate over.

iteratee + + +function + + + + + +

A function to apply to each value and key in +coll. The iteratee is passed a callback(err, transformed) which must be +called once it has completed with an error (which can be null) and a +transformed value. Invoked with (value, key, callback).

callback + + +function + + + + + + <optional> + +

A callback which is called when all iteratee +functions have finished, or an error occurs. result is a new object consisting +of each key from obj, with each transformed value on the right-hand side. +Invoked with (err, result).

+ + + + + + +
Example
+ +
async.mapValues({
+    f1: 'file1',
+    f2: 'file2',
+    f3: 'file3'
+}, function (file, key, callback) {
+  fs.stat(file, callback);
+}, function(err, result) {
+    // result is now a map of stats for each file, e.g.
+    // {
+    //     f1: [stats for file1],
+    //     f2: [stats for file2],
+    //     f3: [stats for file3]
+    // }
+});
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + +

(static) mapValuesLimit(obj, limit, iteratee, callbackopt)

+ + + + + +
+
import mapValuesLimit from 'async/mapValuesLimit';

The same as mapValues but runs a maximum of limit async operations at a +time.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
obj + + +Object + + + + + +

A collection to iterate over.

limit + + +number + + + + + +

The maximum number of async operations at a time.

iteratee + + +function + + + + + +

A function to apply to each value in obj. +The iteratee is passed a callback(err, transformed) which must be called +once it has completed with an error (which can be null) and a +transformed value. Invoked with (value, key, callback).

callback + + +function + + + + + + <optional> + +

A callback which is called when all iteratee +functions have finished, or an error occurs. result is a new object consisting +of each key from obj, with each transformed value on the right-hand side. +Invoked with (err, result).

+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +

(static) mapValuesSeries(obj, iteratee, callbackopt)

+ + + + + +
+
import mapValuesSeries from 'async/mapValuesSeries';

The same as mapValues but runs only a single async operation at a time.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
obj + + +Object + + + + + +

A collection to iterate over.

iteratee + + +function + + + + + +

A function to apply to each value in obj. +The iteratee is passed a callback(err, transformed) which must be called +once it has completed with an error (which can be null) and a +transformed value. Invoked with (value, key, callback).

callback + + +function + + + + + + <optional> + +

A callback which is called when all iteratee +functions have finished, or an error occurs. result is a new object consisting +of each key from obj, with each transformed value on the right-hand side. +Invoked with (err, result).

+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +

(static) reduce(coll, memo, iteratee, callbackopt)

+ + + + + +
+
import reduce from 'async/reduce';

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.

+
+ + + +
+
Alias:
+
  • foldl
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
coll + + +Array +| + +Iterable +| + +Object + + + + + +

A collection to iterate over.

memo + + +* + + + + + +

The initial state of the reduction.

iteratee + + +function + + + + + +

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).

callback + + +function + + + + + + <optional> + +

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
+});
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + +

(static) reduceRight(array, memo, iteratee, callbackopt)

+ + + + + +
+
import reduceRight from 'async/reduceRight';

Same as reduce, only operates on array in reverse order.

+
+ + + +
+
Alias:
+
  • foldr
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
array + + +Array + + + + + +

A collection to iterate over.

memo + + +* + + + + + +

The initial state of the reduction.

iteratee + + +function + + + + + +

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).

callback + + +function + + + + + + <optional> + +

A callback which is called after all the +iteratee functions have finished. Result is the reduced value. Invoked with +(err, result).

+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +

(static) reject(coll, iteratee, callbackopt)

+ + + + + +
+
import reject from 'async/reject';

The opposite of filter. Removes values that pass an async truth test.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
coll + + +Array +| + +Iterable +| + +Object + + + + + +

A collection to iterate over.

iteratee + + +function + + + + + +

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).

callback + + +function + + + + + + <optional> + +

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);
+});
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +

(static) rejectLimit(coll, limit, iteratee, callbackopt)

+ + + + + +
+
import rejectLimit from 'async/rejectLimit';

The same as reject but runs a maximum of limit async operations at a +time.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
coll + + +Array +| + +Iterable +| + +Object + + + + + +

A collection to iterate over.

limit + + +number + + + + + +

The maximum number of async operations at a time.

iteratee + + +function + + + + + +

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).

callback + + +function + + + + + + <optional> + +

A callback which is called after all the +iteratee functions have finished. Invoked with (err, results).

+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +

(static) rejectSeries(coll, iteratee, callbackopt)

+ + + + + +
+
import rejectSeries from 'async/rejectSeries';

The same as reject but runs only a single async operation at a time.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
coll + + +Array +| + +Iterable +| + +Object + + + + + +

A collection to iterate over.

iteratee + + +function + + + + + +

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).

callback + + +function + + + + + + <optional> + +

A callback which is called after all the +iteratee functions have finished. Invoked with (err, results).

+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +

(static) some(coll, iteratee, callbackopt)

+ + + + + +
+
import some from 'async/some';

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.

+
+ + + +
+
Alias:
+
  • any
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
coll + + +Array +| + +Iterable +| + +Object + + + + + +

A collection to iterate over.

iteratee + + +function + + + + + +

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).

callback + + +function + + + + + + <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. 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
+});
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + +

(static) someLimit(coll, limit, iteratee, callbackopt)

+ + + + + +
+
import someLimit from 'async/someLimit';

The same as some but runs a maximum of limit async operations at a time.

+
+ + + +
+
Alias:
+
  • anyLimit
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
coll + + +Array +| + +Iterable +| + +Object + + + + + +

A collection to iterate over.

limit + + +number + + + + + +

The maximum number of async operations at a time.

iteratee + + +function + + + + + +

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).

callback + + +function + + + + + + <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. Invoked with (err, result).

+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +

(static) someSeries(coll, iteratee, callbackopt)

+ + + + + +
+
import someSeries from 'async/someSeries';

The same as some but runs only a single async operation at a time.

+
+ + + +
+
Alias:
+
  • anySeries
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
coll + + +Array +| + +Iterable +| + +Object + + + + + +

A collection to iterate over.

iteratee + + +function + + + + + +

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).

callback + + +function + + + + + + <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. Invoked with (err, result).

+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +

(static) sortBy(coll, iteratee, callback)

+ + + + + +
+
import sortBy from 'async/sortBy';

Sorts a list by the results of running each coll value through an async +iteratee.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
coll + + +Array +| + +Iterable +| + +Object + + + + + +

A collection to iterate over.

iteratee + + +function + + + + + +

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).

callback + + +function + + + + + +

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
+});
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + +

(static) transform(coll, accumulatoropt, iteratee, callbackopt)

+ + + + + +
+
import transform from 'async/transform';

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.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
coll + + +Array +| + +Iterable +| + +Object + + + + + +

A collection to iterate over.

accumulator + + +* + + + + + + <optional> + +

The initial state of the transform. If omitted, +it will default to an empty Object or Array, depending on the type of coll

iteratee + + +function + + + + + +

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).

callback + + +function + + + + + + <optional> + +

A callback which is called after all the +iteratee functions have finished. Result is the transformed accumulator. +Invoked with (err, result).

+ + + + + + +
Examples
+ +
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]
+});
+ +
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}
+})
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + +

Control Flow

+ + + + + + + +
+ +
+ + + + + +
+ +
+
+ + +

A collection of async functions for controlling the flow through a script.

+ + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + +

Methods

+ + + + + + +

(static) applyEach(fns, …argsopt, callbackopt) → {function}

+ + + + + +
+
import applyEach from 'async/applyEach';

Applies the provided arguments to each function in the array, calling +callback after all functions have completed. If you only provide the first +argument, fns, then it will return a function which lets you pass in the +arguments as if it were a single function call. If more arguments are +provided, callback is required while args is still optional.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
fns + + +Array +| + +Iterable +| + +Object + + + + + +

A collection of asynchronous functions +to all call with the same arguments

args + + +* + + + + + + <optional> + +

any number of separate arguments to pass to the +function.

callback + + +function + + + + + + <optional> + +

the final argument should be the callback, +called when all functions have completed processing.

+ + + + +
Returns:
+ + +
+
    +
  • If only the first argument, fns, is provided, it will +return a function which lets you pass in the arguments as if it were a single +function call. The signature is (..args, callback). If invoked with any +arguments, callback is required.
  • +
+
+ + + +
+
+ Type +
+
+ +function + + +
+
+ + + + +
Example
+ +
async.applyEach([enableSearch, updateSchema], 'bucket', callback);
+
+// partial application example:
+async.each(
+    buckets,
+    async.applyEach([enableSearch, updateSchema]),
+    callback
+);
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + +

(static) applyEachSeries(fns, …argsopt, callbackopt) → {function}

+ + + + + +
+
import applyEachSeries from 'async/applyEachSeries';

The same as applyEach but runs only a single async operation at a time.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
fns + + +Array +| + +Iterable +| + +Object + + + + + +

A collection of asynchronous functions to all +call with the same arguments

args + + +* + + + + + + <optional> + +

any number of separate arguments to pass to the +function.

callback + + +function + + + + + + <optional> + +

the final argument should be the callback, +called when all functions have completed processing.

+ + + + +
Returns:
+ + +
+
    +
  • 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.
  • +
+
+ + + +
+
+ Type +
+
+ +function + + +
+
+ + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +

(static) auto(tasks, concurrencyopt, callbackopt)

+ + + + + +
+
import auto from 'async/auto';

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.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDefaultDescription
tasks + + +Object + + + + + + + +

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.
  • +
concurrency + + +number + + + + + + <optional> + + + + Infinity + +

An optional integer for +determining the maximum number of tasks that can be run in parallel. By +default, as many as possible.

callback + + +function + + + + + + <optional> + + + +

An optional callback which is called when all +the tasks have been completed. It receives the err argument if any tasks +pass an error to their callback. Results are always returned; however, if an +error occurs, no further tasks will be performed, and the results object +will only contain partial results. Invoked with (err, results).

+ + + + +
Returns:
+ + +
+

undefined

+
+ + + + + + +
Example
+ +
async.auto({
+    // this function will just be passed a callback
+    readData: async.apply(fs.readFile, 'data.txt', 'utf-8'),
+    showData: ['readData', function(results, cb) {
+        // results.readData is the file's contents
+        // ...
+    }]
+}, callback);
+
+async.auto({
+    get_data: function(callback) {
+        console.log('in get_data');
+        // async code to get some data
+        callback(null, 'data', 'converted to array');
+    },
+    make_folder: function(callback) {
+        console.log('in make_folder');
+        // async code to create a directory to store a file in
+        // this is run at the same time as getting the data
+        callback(null, 'folder');
+    },
+    write_file: ['get_data', 'make_folder', function(results, callback) {
+        console.log('in write_file', JSON.stringify(results));
+        // once there is some data and the directory exists,
+        // write the data to a file in the directory
+        callback(null, 'filename');
+    }],
+    email_link: ['write_file', function(results, callback) {
+        console.log('in email_link', JSON.stringify(results));
+        // once the file is written let's email a link to it...
+        // results.write_file contains the filename returned by write_file.
+        callback(null, {'file':results.write_file, 'email':'user@example.com'});
+    }]
+}, function(err, results) {
+    console.log('err = ', err);
+    console.log('results = ', results);
+});
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + +

(static) autoInject(tasks, callbackopt)

+ + + + + +
+
import autoInject from 'async/autoInject';

A dependency-injected version of the 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 async.auto.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
tasks + + +Object + + + + + +

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.
  • +
callback + + +function + + + + + + <optional> + +

An optional callback which is called when all +the tasks have been completed. It receives the err argument if any tasks +pass an error to their callback, and a results object with any completed +task results, similar to auto.

+ + + + + + +
Example
+ +
//  The example from `auto` can be rewritten as follows:
+async.autoInject({
+    get_data: function(callback) {
+        // async code to get some data
+        callback(null, 'data', 'converted to array');
+    },
+    make_folder: function(callback) {
+        // async code to create a directory to store a file in
+        // this is run at the same time as getting the data
+        callback(null, 'folder');
+    },
+    write_file: function(get_data, make_folder, callback) {
+        // once there is some data and the directory exists,
+        // write the data to a file in the directory
+        callback(null, 'filename');
+    },
+    email_link: function(write_file, callback) {
+        // once the file is written let's email a link to it...
+        // write_file contains the filename returned by write_file.
+        callback(null, {'file':write_file, 'email':'user@example.com'});
+    }
+}, function(err, results) {
+    console.log('err = ', err);
+    console.log('email_link = ', results.email_link);
+});
+
+// If you are using a JS minifier that mangles parameter names, `autoInject`
+// will not work with plain functions, since the parameter names will be
+// collapsed to a single letter identifier.  To work around this, you can
+// explicitly specify the names of the parameters your task function needs
+// in an array, similar to Angular.js dependency injection.
+
+// This still has an advantage over plain `auto`, since the results a task
+// depends on are still spread into arguments.
+async.autoInject({
+    //...
+    write_file: ['get_data', 'make_folder', function(get_data, make_folder, callback) {
+        callback(null, 'filename');
+    }],
+    email_link: ['write_file', function(write_file, callback) {
+        callback(null, {'file':write_file, 'email':'user@example.com'});
+    }]
+    //...
+}, function(err, results) {
+    console.log('err = ', err);
+    console.log('email_link = ', results.email_link);
+});
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +

(static) cargo(worker, payloadopt) → {CargoObject}

+ + + + + +
+
import cargo from 'async/cargo';

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 animations +for how cargo and queue work.

+

While 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.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDefaultDescription
worker + + +function + + + + + + + +

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).

payload + + +number + + + + + + <optional> + + + + Infinity + +

An optional integer for determining +how many tasks should be processed per round; if omitted, the default is +unlimited.

+ + + + +
Returns:
+ + +
+

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.

+
+ + + +
+
+ Type +
+
+ +CargoObject + + +
+
+ + + + +
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');
+});
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +

(static) compose(…functions) → {function}

+ + + + + +
+
import compose from 'async/compose';

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.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
functions + + +function + + + + + +

the asynchronous functions to compose

+ + + + +
Returns:
+ + +
+

an asynchronous function that is the composed +asynchronous functions

+
+ + + +
+
+ Type +
+
+ +function + + +
+
+ + + + +
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
+});
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + +

(static) doDuring(fn, test, callbackopt)

+ + + + + +
+
import doDuring from 'async/doDuring';

The post-check version of during. To reflect the difference in +the order of operations, the arguments test and fn are switched.

+

Also a version of doWhilst with asynchronous test function.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
fn + + +function + + + + + +

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).

test + + +function + + + + + +

asynchronous truth test to perform before each +execution of fn. Invoked with (...args, callback), where ...args are the +non-error args from the previous callback of fn.

callback + + +function + + + + + + <optional> + +

A callback which is called after the test +function has failed and repeated execution of fn has stopped. callback +will be passed an error if one occured, otherwise null.

+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +

(static) doUntil(fn, test, callbackopt)

+ + + + + +
+
import doUntil from 'async/doUntil';

Like 'doWhilst', except the test is inverted. Note the +argument ordering differs from until.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
fn + + +function + + + + + +

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).

test + + +function + + + + + +

synchronous truth test to perform after each +execution of fn. Invoked with the non-error callback results of fn.

callback + + +function + + + + + + <optional> + +

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]);

+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +

(static) doWhilst(iteratee, test, callbackopt)

+ + + + + +
+
import doWhilst from 'async/doWhilst';

The post-check version of whilst. To reflect the difference in +the order of operations, the arguments test and iteratee are switched.

+

doWhilst is to whilst as do while is to while in plain JavaScript.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
iteratee + + +function + + + + + +

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).

test + + +function + + + + + +

synchronous truth test to perform after each +execution of iteratee. Invoked with the non-error callback results of +iteratee.

callback + + +function + + + + + + <optional> + +

A callback which is called after the test +function has failed and repeated execution of iteratee has stopped. +callback will be passed an error and any arguments passed to the final +iteratee's callback. Invoked with (err, [results]);

+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +

(static) during(test, fn, callbackopt)

+ + + + + +
+
import during from 'async/during';

Like 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.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
test + + +function + + + + + +

asynchronous truth test to perform before each +execution of fn. Invoked with (callback).

fn + + +function + + + + + +

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).

callback + + +function + + + + + + <optional> + +

A callback which is called after the test +function has failed and repeated execution of fn has stopped. callback +will be passed an error, if one occured, otherwise null.

+ + + + + + +
Example
+ +
var count = 0;
+
+async.during(
+    function (callback) {
+        return callback(null, count < 5);
+    },
+    function (callback) {
+        count++;
+        setTimeout(callback, 1000);
+    },
+    function (err) {
+        // 5 seconds have passed
+    }
+);
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +

(static) forever(fn, errbackopt)

+ + + + + +
+
import forever from 'async/forever';

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.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
fn + + +function + + + + + +

a function to call repeatedly. Invoked with (next).

errback + + +function + + + + + + <optional> + +

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.
+    }
+);
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + +

(static) parallel(tasks, callbackopt)

+ + + + + +
+
import parallel from 'async/parallel';

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 async.parallel.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
tasks + + +Array +| + +Iterable +| + +Object + + + + + +

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.

callback + + +function + + + + + + <optional> + +

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}
+});
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + +

(static) parallelLimit(tasks, limit, callbackopt)

+ + + + + +
+
import parallelLimit from 'async/parallelLimit';

The same as parallel but runs a maximum of limit async operations at a +time.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
tasks + + +Array +| + +Collection + + + + + +

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.

limit + + +number + + + + + +

The maximum number of async operations at a time.

callback + + +function + + + + + + <optional> + +

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).

+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +

(static) priorityQueue(worker, concurrency) → {QueueObject}

+ + + + + +
+
import priorityQueue from 'async/priorityQueue';

The same as async.queue only tasks are assigned a priority and +completed in ascending priority order.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
worker + + +function + + + + + +

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).

concurrency + + +number + + + + + +

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:
+ + +
+

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.
  • +
+
+ + + +
+
+ Type +
+
+ +QueueObject + + +
+
+ + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +

(static) queue(worker, concurrencyopt) → {QueueObject}

+ + + + + +
+
import queue from 'async/queue';

Creates a queue object with the specified concurrency. Tasks added to the +queue are processed in parallel (up to the concurrency limit). If all +workers are in progress, the task is queued until one becomes available. +Once a worker completes a task, that task's callback is called.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDefaultDescription
worker + + +function + + + + + + + +

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).

concurrency + + +number + + + + + + <optional> + + + + 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:
+ + +
+

A queue object to manage the tasks. Callbacks can +attached as certain properties to listen for specific events during the +lifecycle of the queue.

+
+ + + +
+
+ Type +
+
+ +QueueObject + + +
+
+ + + + +
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');
+});
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + +

(static) race(tasks, callback)

+ + + + + +
+
import race from 'async/race';

Runs the tasks array of functions in parallel, without waiting until the +previous function has completed. Once any of the tasks complete or pass an +error to its callback, the main callback is immediately called. It's +equivalent to Promise.race().

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
tasks + + +Array + + + + + +

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.

callback + + +function + + + + + +

A callback to run once any of the functions have +completed. This function gets an error or result from the first function that +completed. Invoked with (err, result).

+ + + + +
Returns:
+ + +
+

undefined

+
+ + + + + + +
Example
+ +
async.race([
+    function(callback) {
+        setTimeout(function() {
+            callback(null, 'one');
+        }, 200);
+    },
+    function(callback) {
+        setTimeout(function() {
+            callback(null, 'two');
+        }, 100);
+    }
+],
+// main callback
+function(err, result) {
+    // the result will be equal to 'two' as it finishes earlier
+});
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + +

(static) retry(optsopt, task, callbackopt)

+ + + + + +
+
import retry from 'async/retry';

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.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDefaultDescription
opts + + +Object +| + +number + + + + + + <optional> + + + + {times: 5, interval: 0}| 5 + +

Can be either an +object with times and interval or a number.

+
    +
  • times - The number of attempts to make before giving up. The default +is 5.
  • +
  • interval - The time to wait between retries, in milliseconds. The +default is 0. The interval may also be specified as a function of the +retry count (see example).
  • +
  • errorFilter - An optional synchronous function that is invoked on +erroneous result. If it returns true the retry attempts will continue; +if the function returns false the retry flow is aborted with the current +attempt's error and result being returned to the final callback. +Invoked with (err).
  • +
  • If opts is a number, the number specifies the number of times to retry, +with the default interval of 0.
  • +
task + + +function + + + + + + + +

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).

callback + + +function + + + + + + <optional> + + + +

An optional callback which is called when the +task has succeeded, or after the final failed attempt. It receives the err +and result arguments of the last attempt at completing the task. Invoked +with (err, results).

+ + + + + + +
Example
+ +
// The `retry` function can be used as a stand-alone control flow by passing
+// a callback, as shown below:
+
+// try calling apiMethod 3 times
+async.retry(3, apiMethod, function(err, result) {
+    // do something with the result
+});
+
+// try calling apiMethod 3 times, waiting 200 ms between each retry
+async.retry({times: 3, interval: 200}, apiMethod, function(err, result) {
+    // do something with the result
+});
+
+// try calling apiMethod 10 times with exponential backoff
+// (i.e. intervals of 100, 200, 400, 800, 1600, ... milliseconds)
+async.retry({
+  times: 10,
+  interval: function(retryCount) {
+    return 50 * Math.pow(2, retryCount);
+  }
+}, apiMethod, function(err, result) {
+    // do something with the result
+});
+
+// try calling apiMethod the default 5 times no delay between each retry
+async.retry(apiMethod, function(err, result) {
+    // do something with the result
+});
+
+// try calling apiMethod only when error condition satisfies, all other
+// errors will abort the retry control flow and return to final callback
+async.retry({
+  errorFilter: function(err) {
+    return err.message === 'Temporary error'; // only retry on a specific error
+  }
+}, 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
+});
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + +

(static) retryable(optsopt, task) → {Functions}

+ + + + + +
+
import retryable from 'async/retryable';

A close relative of retry. This method wraps a task and makes it +retryable, rather than immediately calling it with retries.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDefaultDescription
opts + + +Object +| + +number + + + + + + <optional> + + + + {times: 5, interval: 0}| 5 + +

optional +options, exactly the same as from retry

task + + +function + + + + + + + +

the asynchronous function to wrap

+ + + + +
Returns:
+ + +
+

The wrapped function, which when invoked, will retry on +an error, based on the parameters specified in opts.

+
+ + + +
+
+ Type +
+
+ +Functions + + +
+
+ + + + +
Example
+ +
async.auto({
+    dep1: async.retryable(3, getFromFlakyService),
+    process: ["dep1", async.retryable(3, function (results, cb) {
+        maybeProcessData(results.dep1, cb);
+    })]
+}, callback);
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +

(static) seq(…functions) → {function}

+ + + + + +
+
import seq from 'async/seq';

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 with the arguments reversed.

+

Each function is executed with the this binding of the composed function.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
functions + + +function + + + + + +

the asynchronous functions to compose

+ + + + +
Returns:
+ + +
+

a function that composes the functions in order

+
+ + + +
+
+ Type +
+
+ +function + + +
+
+ + + + +
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 });
+        }
+    });
+});
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +

(static) series(tasks, callbackopt)

+ + + + + +
+
import series from 'async/series';

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 async.series.

+

Note that while many implementations preserve the order of object +properties, the ECMAScript Language Specification +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.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
tasks + + +Array +| + +Iterable +| + +Object + + + + + +

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.

callback + + +function + + + + + + <optional> + +

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}
+});
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + +

(static) times(n, iteratee, callback)

+ + + + + +
+
import times from 'async/times';

Calls the iteratee function n times, and accumulates results in the same +manner you would use with map.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
n + + +number + + + + + +

The number of times to run the function.

iteratee + + +function + + + + + +

The function to call n times. Invoked with the +iteration index and a callback (n, next).

callback + + +function + + + + + +

see 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
+});
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +

(static) timesLimit(count, limit, iteratee, callback)

+ + + + + +
+
import timesLimit from 'async/timesLimit';

The same as times but runs a maximum of limit async operations at a +time.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
count + + +number + + + + + +

The number of times to run the function.

limit + + +number + + + + + +

The maximum number of async operations at a time.

iteratee + + +function + + + + + +

The function to call n times. Invoked with the +iteration index and a callback (n, next).

callback + + +function + + + + + +

see async.map.

+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +

(static) timesSeries(n, iteratee, callback)

+ + + + + +
+
import timesSeries from 'async/timesSeries';

The same as times but runs only a single async operation at a time.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
n + + +number + + + + + +

The number of times to run the function.

iteratee + + +function + + + + + +

The function to call n times. Invoked with the +iteration index and a callback (n, next).

callback + + +function + + + + + +

see map.

+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +

(static) until(test, fn, callbackopt)

+ + + + + +
+
import until from 'async/until';

Repeatedly call fn until test returns true. Calls callback when +stopped, or an error occurs. callback will be passed an error and any +arguments passed to the final fn's callback.

+

The inverse of whilst.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
test + + +function + + + + + +

synchronous truth test to perform before each +execution of fn. Invoked with ().

fn + + +function + + + + + +

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).

callback + + +function + + + + + + <optional> + +

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]);

+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +

(static) waterfall(tasks, callbackopt)

+ + + + + +
+
import waterfall from 'async/waterfall';

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.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
tasks + + +Array + + + + + +

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.

callback + + +function + + + + + + <optional> + +

An optional callback to run once all the +functions have completed. This will be passed the results of the last task's +callback. Invoked with (err, [results]).

+ + + + +
Returns:
+ + +
+

undefined

+
+ + + + + + +
Example
+ +
async.waterfall([
+    function(callback) {
+        callback(null, 'one', 'two');
+    },
+    function(arg1, arg2, callback) {
+        // arg1 now equals 'one' and arg2 now equals 'two'
+        callback(null, 'three');
+    },
+    function(arg1, callback) {
+        // arg1 now equals 'three'
+        callback(null, 'done');
+    }
+], function (err, result) {
+    // result now equals 'done'
+});
+
+// Or, with named functions:
+async.waterfall([
+    myFirstFunction,
+    mySecondFunction,
+    myLastFunction,
+], function (err, result) {
+    // result now equals 'done'
+});
+function myFirstFunction(callback) {
+    callback(null, 'one', 'two');
+}
+function mySecondFunction(arg1, arg2, callback) {
+    // arg1 now equals 'one' and arg2 now equals 'two'
+    callback(null, 'three');
+}
+function myLastFunction(arg1, callback) {
+    // arg1 now equals 'three'
+    callback(null, 'done');
+}
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + +

(static) whilst(test, iteratee, callbackopt)

+ + + + + +
+
import whilst from 'async/whilst';

Repeatedly call iteratee, while test returns true. Calls callback when +stopped, or an error occurs.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
test + + +function + + + + + +

synchronous truth test to perform before each +execution of iteratee. Invoked with ().

iteratee + + +function + + + + + +

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).

callback + + +function + + + + + + <optional> + +

A callback which is called after the test +function has failed and repeated execution of iteratee has stopped. callback +will be passed an error and any arguments passed to the final iteratee's +callback. Invoked with (err, [results]);

+ + + + +
Returns:
+ + +
+

undefined

+
+ + + + + + +
Example
+ +
var count = 0;
+async.whilst(
+    function() { return count < 5; },
+    function(callback) {
+        count++;
+        setTimeout(function() {
+            callback(null, count);
+        }, 1000);
+    },
+    function (err, n) {
+        // 5 seconds have passed, n = 5
+    }
+);
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + +

Type Definitions

+ + + +

CargoObject

+ + + + +
+
import cargo from 'async/cargo';

A cargo of tasks for the worker function to complete. Cargo inherits all of +the same methods and event callbacks as queue.

+
+ + + +
Type:
+
    +
  • + +Object + + +
  • +
+ + + + + +
Properties:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
length + + +function + + + +

A function returning the number of items +waiting to be processed. Invoke like cargo.length().

payload + + +number + + + +

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.

push + + +function + + + +

Adds task to the queue. The callback is +called once the worker has finished processing the task. Instead of a +single task, an array of tasks can be submitted. The respective callback is +used for every task in the list. Invoke like cargo.push(task, [callback]).

saturated + + +function + + + +

A callback that is called when the +queue.length() hits the concurrency and further tasks will be queued.

empty + + +function + + + +

A callback that is called when the last item +from the queue is given to a worker.

drain + + +function + + + +

A callback that is called when the last item +from the queue has returned from the worker.

idle + + +function + + + +

a function returning false if there are items +waiting or being processed, or true if not. Invoke like cargo.idle().

pause + + +function + + + +

a function that pauses the processing of tasks +until resume() is called. Invoke like cargo.pause().

resume + + +function + + + +

a function that resumes the processing of +queued tasks when the queue is paused. Invoke like cargo.resume().

kill + + +function + + + +

a function that removes the drain callback and +empties remaining tasks from the queue forcing it to go idle. Invoke like cargo.kill().

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + +

QueueObject

+ + + + +
+
import queue from 'async/queue';

A queue of tasks for the worker function to complete.

+
+ + + +
Type:
+
    +
  • + +Object + + +
  • +
+ + + + + +
Properties:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
length + + +function + + + +

a function returning the number of items +waiting to be processed. Invoke with queue.length().

started + + +boolean + + + +

a boolean indicating whether or not any +items have been pushed and processed by the queue.

running + + +function + + + +

a function returning the number of items +currently being processed. Invoke with queue.running().

workersList + + +function + + + +

a function returning the array of items +currently being processed. Invoke with queue.workersList().

idle + + +function + + + +

a function returning false if there are items +waiting or being processed, or true if not. Invoke with queue.idle().

concurrency + + +number + + + +

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.

push + + +function + + + +

add a new task to the queue. Calls callback +once the worker has finished processing the task. Instead of a single task, +a tasks array can be submitted. The respective callback is used for every +task in the list. Invoke with queue.push(task, [callback]),

unshift + + +function + + + +

add a new task to the front of the queue. +Invoke with queue.unshift(task, [callback]).

saturated + + +function + + + +

a callback that is called when the number of +running workers hits the concurrency limit, and further tasks will be +queued.

unsaturated + + +function + + + +

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.

buffer + + +number + + + +

A minimum threshold buffer in order to say that +the queue is unsaturated.

empty + + +function + + + +

a callback that is called when the last item +from the queue is given to a worker.

drain + + +function + + + +

a callback that is called when the last item +from the queue has returned from the worker.

error + + +function + + + +

a callback that is called when a task errors. +Has the signature function(error, task).

paused + + +boolean + + + +

a boolean for determining whether the queue is +in a paused state.

pause + + +function + + + +

a function that pauses the processing of tasks +until resume() is called. Invoke with queue.pause().

resume + + +function + + + +

a function that resumes the processing of +queued tasks when the queue is paused. Invoke with queue.resume().

kill + + +function + + + +

a function that removes the drain callback and +empties remaining tasks from the queue forcing it to go idle. Invoke with queue.kill().

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + +
+ +
+ + + + + + +

Utils

+ + + + + + + +
+ +
+ + + + + +
+ +
+
+ + +

A collection of async utility functions.

+ + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + +

Methods

+ + + + + + +

(static) apply(function)

+ + + + + +
+
import apply from 'async/apply';

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.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
function + + +function + + + + + +

The function you want to eventually apply all +arguments to. Invokes with (arguments...).

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
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + +

(static) asyncify(func) → {function}

+ + + + + +
+
import asyncify from 'async/asyncify';

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.

+
+ + + +
+
Alias:
+
  • wrapSync
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
func + + +function + + + + + +

The synchronous function to convert to an +asynchronous function.

+ + + + +
Returns:
+ + +
+

An asynchronous wrapper of the func. To be invoked with +(callback).

+
+ + + +
+
+ Type +
+
+ +function + + +
+
+ + + + +
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);
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + +

(static) constant() → {function}

+ + + + + +
+
import constant from 'async/constant';

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.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
arguments... + + +* + + + + + +

Any number of arguments to automatically invoke +callback with.

+ + + + +
Returns:
+ + +
+

Returns a function that when invoked, automatically +invokes the callback with the previous given arguments.

+
+ + + +
+
+ Type +
+
+ +function + + +
+
+ + + + +
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);
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + +

(static) dir(function)

+ + + + + +
+
import dir from 'async/dir';

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.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
function + + +function + + + + + +

The function you want to eventually apply all +arguments to.

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'}
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + +

(static) ensureAsync(fn) → {function}

+ + + + + +
+
import ensureAsync from 'async/ensureAsync';

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 +contained.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
fn + + +function + + + + + +

an async function, one that expects a node-style +callback as its last argument.

+ + + + +
Returns:
+ + +
+

Returns a wrapped function with the exact same call +signature as the function passed in.

+
+ + + +
+
+ Type +
+
+ +function + + +
+
+ + + + +
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);
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + +

(static) log(function)

+ + + + + +
+
import log from 'async/log';

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.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
function + + +function + + + + + +

The function you want to eventually apply all +arguments to.

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'
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + +

(static) memoize(fn, hasher) → {function}

+ + + + + +
+
import memoize from 'async/memoize';

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.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
fn + + +function + + + + + +

The function to proxy and cache results from.

hasher + + +function + + + + + +

An optional function for generating a custom hash +for storing results. It has all the arguments applied to it apart from the +callback, and must be synchronous.

+ + + + +
Returns:
+ + +
+

a memoized version of fn

+
+ + + +
+
+ Type +
+
+ +function + + +
+
+ + + + +
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
+});
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + +

(static) nextTick(callback)

+ + + + + +
+
import nextTick from 'async/nextTick';

Calls callback on a later loop around the event loop. In Node.js this just +calls setImmediate. In the browser it will use setImmediate if +available, otherwise setTimeout(callback, 0), which means other higher +priority events may precede the execution of callback.

+

This is used internally for browser-compatibility purposes.

+
+ + + +
+
Alias:
+
  • setImmediate
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
callback + + +function + + + + + +

The function to call on a later loop around +the event loop. Invoked with (args...).

args... + + +* + + + + + +

any number of additional arguments to pass to the +callback on the next tick.

+ + + + + + +
Example
+ +
var call_order = [];
+async.nextTick(function() {
+    call_order.push('two');
+    // call_order now equals ['one','two']
+});
+call_order.push('one');
+
+async.setImmediate(function (a, b, c) {
+    // a, b, and c equal 1, 2, and 3
+}, 1, 2, 3);
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + +

(static) reflect(fn) → {function}

+ + + + + +
+
import reflect from 'async/reflect';

Wraps the function in another function that always returns data even when it +errors.

+

The object returned has either the property error or value.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
fn + + +function + + + + + +

The function you want to wrap

+ + + + +
Returns:
+ + +
+
    +
  • 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.
  • +
+
+ + + +
+
+ Type +
+
+ +function + + +
+
+ + + + +
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'
+});
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + +

(static) reflectAll(tasks) → {Array}

+ + + + + +
+
import reflectAll from 'async/reflectAll';

A helper function that wraps an array or an object of functions with reflect.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
tasks + + +Array + + + + + +

The array of functions to wrap in async.reflect.

+ + + + +
Returns:
+ + +
+

Returns an array of functions, each function wrapped in +async.reflect

+
+ + + +
+
+ Type +
+
+ +Array + + +
+
+ + + + +
Example
+ +
let tasks = [
+    function(callback) {
+        setTimeout(function() {
+            callback(null, 'one');
+        }, 200);
+    },
+    function(callback) {
+        // do some more stuff but error ...
+        callback(new Error('bad stuff happened'));
+    },
+    function(callback) {
+        setTimeout(function() {
+            callback(null, 'two');
+        }, 100);
+    }
+];
+
+async.parallel(async.reflectAll(tasks),
+// optional callback
+function(err, results) {
+    // values
+    // results[0].value = 'one'
+    // results[1].error = Error('bad stuff happened')
+    // results[2].value = 'two'
+});
+
+// an example using an object instead of an array
+let tasks = {
+    one: function(callback) {
+        setTimeout(function() {
+            callback(null, 'one');
+        }, 200);
+    },
+    two: function(callback) {
+        callback('two');
+    },
+    three: function(callback) {
+        setTimeout(function() {
+            callback(null, 'three');
+        }, 100);
+    }
+};
+
+async.parallel(async.reflectAll(tasks),
+// optional callback
+function(err, results) {
+    // values
+    // results.one.value = 'one'
+    // results.two.error = 'two'
+    // results.three.value = 'three'
+});
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +

(static) setImmediate(callback)

+ + + + + +
+
import setImmediate from 'async/setImmediate';

Calls callback on a later loop around the event loop. In Node.js this just +calls setImmediate. In the browser it will use setImmediate if +available, otherwise setTimeout(callback, 0), which means other higher +priority events may precede the execution of callback.

+

This is used internally for browser-compatibility purposes.

+
+ + + +
+
Alias:
+
  • nextTick
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
callback + + +function + + + + + +

The function to call on a later loop around +the event loop. Invoked with (args...).

args... + + +* + + + + + +

any number of additional arguments to pass to the +callback on the next tick.

+ + + + + + +
Example
+ +
var call_order = [];
+async.nextTick(function() {
+    call_order.push('two');
+    // call_order now equals ['one','two']
+});
+call_order.push('one');
+
+async.setImmediate(function (a, b, c) {
+    // a, b, and c equal 1, 2, and 3
+}, 1, 2, 3);
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + +

(static) timeout(asyncFn, milliseconds, infoopt) → {function}

+ + + + + +
+
import timeout from 'async/timeout';

Sets a time limit on an asynchronous function. If the function does not call +its callback within the specified milliseconds, it will be called with a +timeout error. The code property for the error object will be 'ETIMEDOUT'.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
asyncFn + + +function + + + + + +

The asynchronous function you want to set the +time limit.

milliseconds + + +number + + + + + +

The specified time limit.

info + + +* + + + + + + <optional> + +

Any variable you want attached (string, object, etc) +to timeout Error for more information..

+ + + + +
Returns:
+ + +
+

Returns a wrapped function that can be used with any of +the control flow functions. Invoke this function with the same +parameters as you would asyncFunc.

+
+ + + +
+
+ Type +
+
+ +function + + +
+
+ + + + +
Example
+ +
function myFunction(foo, callback) {
+    doAsyncTask(foo, function(err, data) {
+        // handle errors
+        if (err) return callback(err);
+
+        // do some stuff ...
+
+        // return processed data
+        return callback(null, data);
+    });
+}
+
+var wrapped = async.timeout(myFunction, 1000);
+
+// call `wrapped` as you would `myFunction`
+wrapped({ bar: 'bar' }, function(err, data) {
+    // if `myFunction` takes < 1000 ms to execute, `err`
+    // and `data` will have their expected values
+
+    // else `err` will be an Error with the code 'ETIMEDOUT'
+});
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + +

(static) unmemoize(fn) → {function}

+ + + + + +
+
import unmemoize from 'async/unmemoize';

Undoes a memoized function, reverting it to the original, +unmemoized form. Handy for testing.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
fn + + +function + + + + + +

the memoized function

+ + + + +
Returns:
+ + +
+

a function that calls the original unmemoized function

+
+ + + +
+
+ Type +
+
+ +function + + +
+
+ + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + + +
+ +
+ + + + +
+
+ + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/during.js.html b/during.js.html new file mode 100644 index 000000000..35c298215 --- /dev/null +++ b/during.js.html @@ -0,0 +1,163 @@ + + + + + + + during.js - Documentation + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +

during.js

+ + + + + + + +
+
+
import noop from 'lodash/noop';
+import onlyOnce from './internal/onlyOnce';
+
+/**
+ * Like [`whilst`]{@link module:ControlFlow.whilst}, except the `test` is an asynchronous function that
+ * is passed a callback in the form of `function (err, truth)`. If error is
+ * passed to `test` or `fn`, the main callback is immediately called with the
+ * value of the error.
+ *
+ * @name during
+ * @static
+ * @memberOf module:ControlFlow
+ * @method
+ * @see [async.whilst]{@link module:ControlFlow.whilst}
+ * @category Control Flow
+ * @param {Function} test - asynchronous truth test to perform before each
+ * execution of `fn`. Invoked with (callback).
+ * @param {Function} fn - A function which is called each time `test` passes.
+ * The function is passed a `callback(err)`, which must be called once it has
+ * completed with an optional `err` argument. Invoked with (callback).
+ * @param {Function} [callback] - A callback which is called after the test
+ * function has failed and repeated execution of `fn` has stopped. `callback`
+ * will be passed an error, if one occured, otherwise `null`.
+ * @example
+ *
+ * var count = 0;
+ *
+ * async.during(
+ *     function (callback) {
+ *         return callback(null, count < 5);
+ *     },
+ *     function (callback) {
+ *         count++;
+ *         setTimeout(callback, 1000);
+ *     },
+ *     function (err) {
+ *         // 5 seconds have passed
+ *     }
+ * );
+ */
+export default function during(test, fn, callback) {
+    callback = onlyOnce(callback || noop);
+
+    function next(err) {
+        if (err) return callback(err);
+        test(check);
+    }
+
+    function check(err, truth) {
+        if (err) return callback(err);
+        if (!truth) return callback(null);
+        fn(next);
+    }
+
+    test(check);
+}
+
+
+
+ + + + +
+
+ + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/each.js.html b/each.js.html new file mode 100644 index 000000000..411b19a3f --- /dev/null +++ b/each.js.html @@ -0,0 +1,172 @@ + + + + + + + each.js - Documentation + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +

each.js

+ + + + + + + +
+
+
import eachOf from './eachOf';
+import withoutIndex from './internal/withoutIndex';
+
+/**
+ * Applies the function `iteratee` to each item in `coll`, in parallel.
+ * The `iteratee` is called with an item from the list, and a callback for when
+ * it has finished. If the `iteratee` passes an error to its `callback`, the
+ * main `callback` (for the `each` function) is immediately called with the
+ * error.
+ *
+ * Note, that since this function applies `iteratee` to each item in parallel,
+ * there is no guarantee that the iteratee functions will complete in order.
+ *
+ * @name each
+ * @static
+ * @memberOf module:Collections
+ * @method
+ * @alias forEach
+ * @category Collection
+ * @param {Array|Iterable|Object} coll - A collection to iterate over.
+ * @param {Function} iteratee - A function to apply to each item
+ * in `coll`. The iteratee is passed a `callback(err)` which must be called once
+ * it has completed. If no error has occurred, the `callback` should be run
+ * without arguments or with an explicit `null` argument. The array index is not
+ * passed to the iteratee. Invoked with (item, callback). If you need the index,
+ * use `eachOf`.
+ * @param {Function} [callback] - A callback which is called when all
+ * `iteratee` functions have finished, or an error occurs. Invoked with (err).
+ * @example
+ *
+ * // assuming openFiles is an array of file names and saveFile is a function
+ * // to save the modified contents of that file:
+ *
+ * async.each(openFiles, saveFile, function(err){
+ *   // if any of the saves produced an error, err would equal that error
+ * });
+ *
+ * // assuming openFiles is an array of file names
+ * async.each(openFiles, function(file, callback) {
+ *
+ *     // Perform operation on file here.
+ *     console.log('Processing file ' + file);
+ *
+ *     if( file.length > 32 ) {
+ *       console.log('This file name is too long');
+ *       callback('File name too long');
+ *     } else {
+ *       // Do work to process file here
+ *       console.log('File processed');
+ *       callback();
+ *     }
+ * }, function(err) {
+ *     // if any of the file processing produced an error, err would equal that error
+ *     if( err ) {
+ *       // One of the iterations produced an error.
+ *       // All processing will now stop.
+ *       console.log('A file failed to process');
+ *     } else {
+ *       console.log('All files have been processed successfully');
+ *     }
+ * });
+ */
+export default function eachLimit(coll, iteratee, callback) {
+    eachOf(coll, withoutIndex(iteratee), callback);
+}
+
+
+
+ + + + +
+
+ + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/eachLimit.js.html b/eachLimit.js.html new file mode 100644 index 000000000..7acd910e4 --- /dev/null +++ b/eachLimit.js.html @@ -0,0 +1,134 @@ + + + + + + + eachLimit.js - Documentation + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +

eachLimit.js

+ + + + + + + +
+
+
import eachOfLimit from './internal/eachOfLimit';
+import withoutIndex from './internal/withoutIndex';
+
+/**
+ * The same as [`each`]{@link module:Collections.each} but runs a maximum of `limit` async operations at a time.
+ *
+ * @name eachLimit
+ * @static
+ * @memberOf module:Collections
+ * @method
+ * @see [async.each]{@link module:Collections.each}
+ * @alias forEachLimit
+ * @category Collection
+ * @param {Array|Iterable|Object} coll - A 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)` 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).
+ */
+export default function eachLimit(coll, limit, iteratee, callback) {
+    eachOfLimit(limit)(coll, withoutIndex(iteratee), callback);
+}
+
+
+
+ + + + +
+
+ + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/eachOf.js.html b/eachOf.js.html new file mode 100644 index 000000000..de2be7083 --- /dev/null +++ b/eachOf.js.html @@ -0,0 +1,187 @@ + + + + + + + eachOf.js - Documentation + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +

eachOf.js

+ + + + + + + +
+
+
import isArrayLike from 'lodash/isArrayLike';
+
+import breakLoop from './internal/breakLoop';
+import eachOfLimit from './eachOfLimit';
+import doLimit from './internal/doLimit';
+import noop from 'lodash/noop';
+import once from './internal/once';
+import onlyOnce from './internal/onlyOnce';
+
+// eachOf implementation optimized for array-likes
+function eachOfArrayLike(coll, iteratee, callback) {
+    callback = once(callback || noop);
+    var index = 0,
+        completed = 0,
+        length = coll.length;
+    if (length === 0) {
+        callback(null);
+    }
+
+    function iteratorCallback(err, value) {
+        if (err) {
+            callback(err);
+        } else if ((++completed === length) || value === breakLoop) {
+            callback(null);
+        }
+    }
+
+    for (; index < length; index++) {
+        iteratee(coll[index], index, onlyOnce(iteratorCallback));
+    }
+}
+
+// a generic version of eachOf which can handle array, object, and iterator cases.
+var eachOfGeneric = doLimit(eachOfLimit, Infinity);
+
+/**
+ * Like [`each`]{@link module:Collections.each}, except that it passes the key (or index) as the second argument
+ * to the iteratee.
+ *
+ * @name eachOf
+ * @static
+ * @memberOf module:Collections
+ * @method
+ * @alias forEachOf
+ * @category Collection
+ * @see [async.each]{@link module:Collections.each}
+ * @param {Array|Iterable|Object} coll - A collection to iterate over.
+ * @param {Function} iteratee - A function to apply to each
+ * item in `coll`. The `key` is the item's key, or index in the case of an
+ * array. The iteratee is passed a `callback(err)` which must be called once it
+ * has completed. If no error has occurred, the callback should be run without
+ * arguments or with an explicit `null` argument. Invoked with
+ * (item, key, callback).
+ * @param {Function} [callback] - A callback which is called when all
+ * `iteratee` functions have finished, or an error occurs. Invoked with (err).
+ * @example
+ *
+ * var obj = {dev: "/dev.json", test: "/test.json", prod: "/prod.json"};
+ * var configs = {};
+ *
+ * async.forEachOf(obj, function (value, key, callback) {
+ *     fs.readFile(__dirname + value, "utf8", function (err, data) {
+ *         if (err) return callback(err);
+ *         try {
+ *             configs[key] = JSON.parse(data);
+ *         } catch (e) {
+ *             return callback(e);
+ *         }
+ *         callback();
+ *     });
+ * }, function (err) {
+ *     if (err) console.error(err.message);
+ *     // configs is now a map of JSON data
+ *     doSomethingWith(configs);
+ * });
+ */
+export default function(coll, iteratee, callback) {
+    var eachOfImplementation = isArrayLike(coll) ? eachOfArrayLike : eachOfGeneric;
+    eachOfImplementation(coll, iteratee, callback);
+}
+
+
+
+ + + + +
+
+ + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/eachOfLimit.js.html b/eachOfLimit.js.html new file mode 100644 index 000000000..e34f09160 --- /dev/null +++ b/eachOfLimit.js.html @@ -0,0 +1,134 @@ + + + + + + + eachOfLimit.js - Documentation + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +

eachOfLimit.js

+ + + + + + + +
+
+
import _eachOfLimit from './internal/eachOfLimit';
+
+/**
+ * The same as [`eachOf`]{@link module:Collections.eachOf} but runs a maximum of `limit` async operations at a
+ * time.
+ *
+ * @name eachOfLimit
+ * @static
+ * @memberOf module:Collections
+ * @method
+ * @see [async.eachOf]{@link module:Collections.eachOf}
+ * @alias forEachOfLimit
+ * @category Collection
+ * @param {Array|Iterable|Object} coll - A collection to iterate over.
+ * @param {number} limit - The maximum number of async operations at a time.
+ * @param {Function} iteratee - A function to apply to each
+ * item in `coll`. The `key` is the item's key, or index in the case of an
+ * array. The iteratee is passed a `callback(err)` which must be called once it
+ * has completed. If no error has occurred, the callback should be run without
+ * arguments or with an explicit `null` argument. Invoked with
+ * (item, key, callback).
+ * @param {Function} [callback] - A callback which is called when all
+ * `iteratee` functions have finished, or an error occurs. Invoked with (err).
+ */
+export default function eachOfLimit(coll, limit, iteratee, callback) {
+    _eachOfLimit(limit)(coll, iteratee, callback);
+}
+
+
+
+ + + + +
+
+ + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/eachOfSeries.js.html b/eachOfSeries.js.html new file mode 100644 index 000000000..b614c71f2 --- /dev/null +++ b/eachOfSeries.js.html @@ -0,0 +1,130 @@ + + + + + + + eachOfSeries.js - Documentation + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +

eachOfSeries.js

+ + + + + + + +
+
+
import eachOfLimit from './eachOfLimit';
+import doLimit from './internal/doLimit';
+
+/**
+ * The same as [`eachOf`]{@link module:Collections.eachOf} but runs only a single async operation at a time.
+ *
+ * @name eachOfSeries
+ * @static
+ * @memberOf module:Collections
+ * @method
+ * @see [async.eachOf]{@link module:Collections.eachOf}
+ * @alias forEachOfSeries
+ * @category Collection
+ * @param {Array|Iterable|Object} coll - A collection to iterate over.
+ * @param {Function} iteratee - A function to apply to each item in `coll`. The
+ * `key` is the item's key, or index in the case of an array. The iteratee is
+ * passed a `callback(err)` which must be called once it has completed. If no
+ * error has occurred, the callback should be run without arguments or with an
+ * explicit `null` argument. Invoked with (item, key, callback).
+ * @param {Function} [callback] - A callback which is called when all `iteratee`
+ * functions have finished, or an error occurs. Invoked with (err).
+ */
+export default doLimit(eachOfLimit, 1);
+
+
+
+ + + + +
+
+ + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/eachSeries.js.html b/eachSeries.js.html new file mode 100644 index 000000000..94221eaef --- /dev/null +++ b/eachSeries.js.html @@ -0,0 +1,131 @@ + + + + + + + eachSeries.js - Documentation + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +

eachSeries.js

+ + + + + + + +
+
+
import eachLimit from './eachLimit';
+import doLimit from './internal/doLimit';
+
+/**
+ * The same as [`each`]{@link module:Collections.each} but runs only a single async operation at a time.
+ *
+ * @name eachSeries
+ * @static
+ * @memberOf module:Collections
+ * @method
+ * @see [async.each]{@link module:Collections.each}
+ * @alias forEachSeries
+ * @category Collection
+ * @param {Array|Iterable|Object} coll - A collection to iterate over.
+ * @param {Function} iteratee - A function to apply to each
+ * item in `coll`. The iteratee is passed a `callback(err)` which must be called
+ * once it has completed. If no error has occurred, the `callback` should be run
+ * without arguments or with an explicit `null` argument. The array index is
+ * not passed to the iteratee. Invoked with (item, callback). If you need the
+ * index, use `eachOfSeries`.
+ * @param {Function} [callback] - A callback which is called when all
+ * `iteratee` functions have finished, or an error occurs. Invoked with (err).
+ */
+export default doLimit(eachLimit, 1);
+
+
+
+ + + + +
+
+ + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ensureAsync.js.html b/ensureAsync.js.html new file mode 100644 index 000000000..122859903 --- /dev/null +++ b/ensureAsync.js.html @@ -0,0 +1,161 @@ + + + + + + + ensureAsync.js - Documentation + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +

ensureAsync.js

+ + + + + + + +
+
+
import setImmediate from './internal/setImmediate';
+import initialParams from './internal/initialParams';
+
+/**
+ * Wrap an async function and ensure it calls its callback on a later tick of
+ * the event loop.  If the function already calls its callback on a next tick,
+ * no extra deferral is added. This is useful for preventing stack overflows
+ * (`RangeError: Maximum call stack size exceeded`) and generally keeping
+ * [Zalgo](http://blog.izs.me/post/59142742143/designing-apis-for-asynchrony)
+ * contained.
+ *
+ * @name ensureAsync
+ * @static
+ * @memberOf module:Utils
+ * @method
+ * @category Util
+ * @param {Function} fn - an async function, one that expects a node-style
+ * callback as its last argument.
+ * @returns {Function} Returns a wrapped function with the exact same call
+ * signature as the function passed in.
+ * @example
+ *
+ * function sometimesAsync(arg, callback) {
+ *     if (cache[arg]) {
+ *         return callback(null, cache[arg]); // this would be synchronous!!
+ *     } else {
+ *         doSomeIO(arg, callback); // this IO would be asynchronous
+ *     }
+ * }
+ *
+ * // this has a risk of stack overflows if many results are cached in a row
+ * async.mapSeries(args, sometimesAsync, done);
+ *
+ * // this will defer sometimesAsync's callback if necessary,
+ * // preventing stack overflows
+ * async.mapSeries(args, async.ensureAsync(sometimesAsync), done);
+ */
+export default function ensureAsync(fn) {
+    return initialParams(function (args, callback) {
+        var sync = true;
+        args.push(function () {
+            var innerArgs = arguments;
+            if (sync) {
+                setImmediate(function () {
+                    callback.apply(null, innerArgs);
+                });
+            } else {
+                callback.apply(null, innerArgs);
+            }
+        });
+        fn.apply(this, args);
+        sync = false;
+    });
+}
+
+
+
+ + + + +
+
+ + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/every.js.html b/every.js.html new file mode 100644 index 000000000..f385d1495 --- /dev/null +++ b/every.js.html @@ -0,0 +1,140 @@ + + + + + + + every.js - Documentation + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +

every.js

+ + + + + + + +
+
+
import createTester from './internal/createTester';
+import doParallel from './internal/doParallel';
+import notId from './internal/notId';
+
+/**
+ * Returns `true` if every element in `coll` satisfies an async test. If any
+ * iteratee call returns `false`, the main `callback` is immediately called.
+ *
+ * @name every
+ * @static
+ * @memberOf module:Collections
+ * @method
+ * @alias all
+ * @category Collection
+ * @param {Array|Iterable|Object} coll - A collection to iterate over.
+ * @param {Function} iteratee - A truth test to apply to each item in the
+ * collection in parallel. The iteratee is passed a `callback(err, truthValue)`
+ * which must be called with a  boolean argument once it has completed. Invoked
+ * with (item, callback).
+ * @param {Function} [callback] - A callback which is called after all the
+ * `iteratee` functions have finished. Result will be either `true` or `false`
+ * depending on the values of the async tests. Invoked with (err, result).
+ * @example
+ *
+ * async.every(['file1','file2','file3'], function(filePath, callback) {
+ *     fs.access(filePath, function(err) {
+ *         callback(null, !err)
+ *     });
+ * }, function(err, result) {
+ *     // if result is true then every file exists
+ * });
+ */
+export default doParallel(createTester(notId, notId));
+
+
+
+ + + + +
+
+ + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/everyLimit.js.html b/everyLimit.js.html new file mode 100644 index 000000000..f8396b20e --- /dev/null +++ b/everyLimit.js.html @@ -0,0 +1,132 @@ + + + + + + + everyLimit.js - Documentation + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +

everyLimit.js

+ + + + + + + +
+
+
import createTester from './internal/createTester';
+import doParallelLimit from './internal/doParallelLimit';
+import notId from './internal/notId';
+
+/**
+ * The same as [`every`]{@link module:Collections.every} but runs a maximum of `limit` async operations at a time.
+ *
+ * @name everyLimit
+ * @static
+ * @memberOf module:Collections
+ * @method
+ * @see [async.every]{@link module:Collections.every}
+ * @alias allLimit
+ * @category Collection
+ * @param {Array|Iterable|Object} coll - A collection to iterate over.
+ * @param {number} limit - The maximum number of async operations at a time.
+ * @param {Function} iteratee - A truth test to apply to each item in the
+ * collection in parallel. The iteratee is passed a `callback(err, truthValue)`
+ * which must be called with a  boolean argument once it has completed. Invoked
+ * with (item, callback).
+ * @param {Function} [callback] - A callback which is called after all the
+ * `iteratee` functions have finished. Result will be either `true` or `false`
+ * depending on the values of the async tests. Invoked with (err, result).
+ */
+export default doParallelLimit(createTester(notId, notId));
+
+
+
+ + + + +
+
+ + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/everySeries.js.html b/everySeries.js.html new file mode 100644 index 000000000..9d451a971 --- /dev/null +++ b/everySeries.js.html @@ -0,0 +1,130 @@ + + + + + + + everySeries.js - Documentation + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +

everySeries.js

+ + + + + + + +
+
+
import everyLimit from './everyLimit';
+import doLimit from './internal/doLimit';
+
+/**
+ * The same as [`every`]{@link module:Collections.every} but runs only a single async operation at a time.
+ *
+ * @name everySeries
+ * @static
+ * @memberOf module:Collections
+ * @method
+ * @see [async.every]{@link module:Collections.every}
+ * @alias allSeries
+ * @category Collection
+ * @param {Array|Iterable|Object} coll - A collection to iterate over.
+ * @param {Function} iteratee - A truth test to apply to each item in the
+ * collection in parallel. The iteratee is passed a `callback(err, truthValue)`
+ * which must be called with a  boolean argument once it has completed. Invoked
+ * with (item, callback).
+ * @param {Function} [callback] - A callback which is called after all the
+ * `iteratee` functions have finished. Result will be either `true` or `false`
+ * depending on the values of the async tests. Invoked with (err, result).
+ */
+export default doLimit(everyLimit, 1);
+
+
+
+ + + + +
+
+ + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/favicon.ico b/favicon.ico new file mode 100755 index 000000000..4a90dff47 Binary files /dev/null and b/favicon.ico differ diff --git a/filter.js.html b/filter.js.html new file mode 100644 index 000000000..555ec40f5 --- /dev/null +++ b/filter.js.html @@ -0,0 +1,138 @@ + + + + + + + filter.js - Documentation + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +

filter.js

+ + + + + + + +
+
+
import filter from './internal/filter';
+import doParallel from './internal/doParallel';
+
+/**
+ * Returns a new array of all the values in `coll` which pass an async truth
+ * test. This operation is performed in parallel, but the results array will be
+ * in the same order as the original.
+ *
+ * @name filter
+ * @static
+ * @memberOf module:Collections
+ * @method
+ * @alias select
+ * @category Collection
+ * @param {Array|Iterable|Object} coll - A collection to iterate over.
+ * @param {Function} iteratee - A truth test to apply to each item in `coll`.
+ * The `iteratee` is passed a `callback(err, truthValue)`, which must be called
+ * with a boolean argument once it has completed. Invoked with (item, callback).
+ * @param {Function} [callback] - A callback which is called after all the
+ * `iteratee` functions have finished. Invoked with (err, results).
+ * @example
+ *
+ * async.filter(['file1','file2','file3'], function(filePath, callback) {
+ *     fs.access(filePath, function(err) {
+ *         callback(null, !err)
+ *     });
+ * }, function(err, results) {
+ *     // results now equals an array of the existing files
+ * });
+ */
+export default doParallel(filter);
+
+
+
+ + + + +
+
+ + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/filterLimit.js.html b/filterLimit.js.html new file mode 100644 index 000000000..710809fb8 --- /dev/null +++ b/filterLimit.js.html @@ -0,0 +1,130 @@ + + + + + + + filterLimit.js - Documentation + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +

filterLimit.js

+ + + + + + + +
+
+
import filter from './internal/filter';
+import doParallelLimit from './internal/doParallelLimit';
+
+/**
+ * The same as [`filter`]{@link module:Collections.filter} but runs a maximum of `limit` async operations at a
+ * time.
+ *
+ * @name filterLimit
+ * @static
+ * @memberOf module:Collections
+ * @method
+ * @see [async.filter]{@link module:Collections.filter}
+ * @alias selectLimit
+ * @category Collection
+ * @param {Array|Iterable|Object} coll - A collection to iterate over.
+ * @param {number} limit - The maximum number of async operations at a time.
+ * @param {Function} iteratee - A truth test to apply to each item in `coll`.
+ * The `iteratee` is passed a `callback(err, truthValue)`, which must be called
+ * with a boolean argument once it has completed. Invoked with (item, callback).
+ * @param {Function} [callback] - A callback which is called after all the
+ * `iteratee` functions have finished. Invoked with (err, results).
+ */
+export default doParallelLimit(filter);
+
+
+
+ + + + +
+
+ + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/filterSeries.js.html b/filterSeries.js.html new file mode 100644 index 000000000..5b7d1f220 --- /dev/null +++ b/filterSeries.js.html @@ -0,0 +1,128 @@ + + + + + + + filterSeries.js - Documentation + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +

filterSeries.js

+ + + + + + + +
+
+
import filterLimit from './filterLimit';
+import doLimit from './internal/doLimit';
+
+/**
+ * The same as [`filter`]{@link module:Collections.filter} but runs only a single async operation at a time.
+ *
+ * @name filterSeries
+ * @static
+ * @memberOf module:Collections
+ * @method
+ * @see [async.filter]{@link module:Collections.filter}
+ * @alias selectSeries
+ * @category Collection
+ * @param {Array|Iterable|Object} coll - A collection to iterate over.
+ * @param {Function} iteratee - A truth test to apply to each item in `coll`.
+ * The `iteratee` is passed a `callback(err, truthValue)`, which must be called
+ * with a boolean argument once it has completed. Invoked with (item, callback).
+ * @param {Function} [callback] - A callback which is called after all the
+ * `iteratee` functions have finished. Invoked with (err, results)
+ */
+export default doLimit(filterLimit, 1);
+
+
+
+ + + + +
+
+ + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/fonts/OpenSans-Bold-webfont.eot b/fonts/OpenSans-Bold-webfont.eot new file mode 100644 index 000000000..5d20d9163 Binary files /dev/null and b/fonts/OpenSans-Bold-webfont.eot differ diff --git a/fonts/OpenSans-Bold-webfont.svg b/fonts/OpenSans-Bold-webfont.svg new file mode 100644 index 000000000..3ed7be4bc --- /dev/null +++ b/fonts/OpenSans-Bold-webfont.svg @@ -0,0 +1,1830 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/fonts/OpenSans-Bold-webfont.woff b/fonts/OpenSans-Bold-webfont.woff new file mode 100644 index 000000000..1205787b0 Binary files /dev/null and b/fonts/OpenSans-Bold-webfont.woff differ diff --git a/fonts/OpenSans-BoldItalic-webfont.eot b/fonts/OpenSans-BoldItalic-webfont.eot new file mode 100644 index 000000000..1f639a15f Binary files /dev/null and b/fonts/OpenSans-BoldItalic-webfont.eot differ diff --git a/fonts/OpenSans-BoldItalic-webfont.svg b/fonts/OpenSans-BoldItalic-webfont.svg new file mode 100644 index 000000000..6a2607b9d --- /dev/null +++ b/fonts/OpenSans-BoldItalic-webfont.svg @@ -0,0 +1,1830 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/fonts/OpenSans-BoldItalic-webfont.woff b/fonts/OpenSans-BoldItalic-webfont.woff new file mode 100644 index 000000000..ed760c062 Binary files /dev/null and b/fonts/OpenSans-BoldItalic-webfont.woff differ diff --git a/fonts/OpenSans-Italic-webfont.eot b/fonts/OpenSans-Italic-webfont.eot new file mode 100644 index 000000000..0c8a0ae06 Binary files /dev/null and b/fonts/OpenSans-Italic-webfont.eot differ diff --git a/fonts/OpenSans-Italic-webfont.svg b/fonts/OpenSans-Italic-webfont.svg new file mode 100644 index 000000000..e1075dcc2 --- /dev/null +++ b/fonts/OpenSans-Italic-webfont.svg @@ -0,0 +1,1830 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/fonts/OpenSans-Italic-webfont.woff b/fonts/OpenSans-Italic-webfont.woff new file mode 100644 index 000000000..ff652e643 Binary files /dev/null and b/fonts/OpenSans-Italic-webfont.woff differ diff --git a/fonts/OpenSans-Light-webfont.eot b/fonts/OpenSans-Light-webfont.eot new file mode 100644 index 000000000..14868406a Binary files /dev/null and b/fonts/OpenSans-Light-webfont.eot differ diff --git a/fonts/OpenSans-Light-webfont.svg b/fonts/OpenSans-Light-webfont.svg new file mode 100644 index 000000000..11a472ca8 --- /dev/null +++ b/fonts/OpenSans-Light-webfont.svg @@ -0,0 +1,1831 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/fonts/OpenSans-Light-webfont.woff b/fonts/OpenSans-Light-webfont.woff new file mode 100644 index 000000000..e78607481 Binary files /dev/null and b/fonts/OpenSans-Light-webfont.woff differ diff --git a/fonts/OpenSans-LightItalic-webfont.eot b/fonts/OpenSans-LightItalic-webfont.eot new file mode 100644 index 000000000..8f445929f Binary files /dev/null and b/fonts/OpenSans-LightItalic-webfont.eot differ diff --git a/fonts/OpenSans-LightItalic-webfont.svg b/fonts/OpenSans-LightItalic-webfont.svg new file mode 100644 index 000000000..431d7e354 --- /dev/null +++ b/fonts/OpenSans-LightItalic-webfont.svg @@ -0,0 +1,1835 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/fonts/OpenSans-LightItalic-webfont.woff b/fonts/OpenSans-LightItalic-webfont.woff new file mode 100644 index 000000000..43e8b9e6c Binary files /dev/null and b/fonts/OpenSans-LightItalic-webfont.woff differ diff --git a/fonts/OpenSans-Regular-webfont.eot b/fonts/OpenSans-Regular-webfont.eot new file mode 100644 index 000000000..6bbc3cf58 Binary files /dev/null and b/fonts/OpenSans-Regular-webfont.eot differ diff --git a/fonts/OpenSans-Regular-webfont.svg b/fonts/OpenSans-Regular-webfont.svg new file mode 100644 index 000000000..25a395234 --- /dev/null +++ b/fonts/OpenSans-Regular-webfont.svg @@ -0,0 +1,1831 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/fonts/OpenSans-Regular-webfont.woff b/fonts/OpenSans-Regular-webfont.woff new file mode 100644 index 000000000..e231183dc Binary files /dev/null and b/fonts/OpenSans-Regular-webfont.woff differ diff --git a/fonts/OpenSans-Semibold-webfont.eot b/fonts/OpenSans-Semibold-webfont.eot new file mode 100644 index 000000000..d8375dd0a Binary files /dev/null and b/fonts/OpenSans-Semibold-webfont.eot differ diff --git a/fonts/OpenSans-Semibold-webfont.svg b/fonts/OpenSans-Semibold-webfont.svg new file mode 100644 index 000000000..eec4db8bd --- /dev/null +++ b/fonts/OpenSans-Semibold-webfont.svg @@ -0,0 +1,1830 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/fonts/OpenSans-Semibold-webfont.ttf b/fonts/OpenSans-Semibold-webfont.ttf new file mode 100644 index 000000000..b3290843a Binary files /dev/null and b/fonts/OpenSans-Semibold-webfont.ttf differ diff --git a/fonts/OpenSans-Semibold-webfont.woff b/fonts/OpenSans-Semibold-webfont.woff new file mode 100644 index 000000000..28d6adee0 Binary files /dev/null and b/fonts/OpenSans-Semibold-webfont.woff differ diff --git a/fonts/OpenSans-SemiboldItalic-webfont.eot b/fonts/OpenSans-SemiboldItalic-webfont.eot new file mode 100644 index 000000000..0ab1db22e Binary files /dev/null and b/fonts/OpenSans-SemiboldItalic-webfont.eot differ diff --git a/fonts/OpenSans-SemiboldItalic-webfont.svg b/fonts/OpenSans-SemiboldItalic-webfont.svg new file mode 100644 index 000000000..7166ec1b9 --- /dev/null +++ b/fonts/OpenSans-SemiboldItalic-webfont.svg @@ -0,0 +1,1830 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/fonts/OpenSans-SemiboldItalic-webfont.ttf b/fonts/OpenSans-SemiboldItalic-webfont.ttf new file mode 100644 index 000000000..d2d6318f6 Binary files /dev/null and b/fonts/OpenSans-SemiboldItalic-webfont.ttf differ diff --git a/fonts/OpenSans-SemiboldItalic-webfont.woff b/fonts/OpenSans-SemiboldItalic-webfont.woff new file mode 100644 index 000000000..d4dfca402 Binary files /dev/null and b/fonts/OpenSans-SemiboldItalic-webfont.woff differ diff --git a/forever.js.html b/forever.js.html new file mode 100644 index 000000000..6d6cf6f0c --- /dev/null +++ b/forever.js.html @@ -0,0 +1,151 @@ + + + + + + + forever.js - Documentation + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +

forever.js

+ + + + + + + +
+
+
import noop from 'lodash/noop';
+
+import onlyOnce from './internal/onlyOnce';
+import ensureAsync from './ensureAsync';
+
+/**
+ * Calls the asynchronous function `fn` with a callback parameter that allows it
+ * to call itself again, in series, indefinitely.
+
+ * If an error is passed to the
+ * callback then `errback` is called with the error, and execution stops,
+ * otherwise it will never be called.
+ *
+ * @name forever
+ * @static
+ * @memberOf module:ControlFlow
+ * @method
+ * @category Control Flow
+ * @param {Function} fn - a function to call repeatedly. Invoked with (next).
+ * @param {Function} [errback] - when `fn` passes an error to it's callback,
+ * this function will be called, and execution stops. Invoked with (err).
+ * @example
+ *
+ * async.forever(
+ *     function(next) {
+ *         // next is suitable for passing to things that need a callback(err [, whatever]);
+ *         // it will result in this function being called again.
+ *     },
+ *     function(err) {
+ *         // if next is called with a value in its first parameter, it will appear
+ *         // in here as 'err', and execution will stop.
+ *     }
+ * );
+ */
+export default function forever(fn, errback) {
+    var done = onlyOnce(errback || noop);
+    var task = ensureAsync(fn);
+
+    function next(err) {
+        if (err) return done(err);
+        task(next);
+    }
+    next();
+}
+
+
+
+ + + + +
+
+ + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/img/async-logo.svg b/img/async-logo.svg new file mode 100644 index 000000000..d108be788 --- /dev/null +++ b/img/async-logo.svg @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + diff --git a/index.html b/index.html new file mode 100644 index 000000000..8486ed571 --- /dev/null +++ b/index.html @@ -0,0 +1,248 @@ + + + + + + + Home - Documentation + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + + + + + + + + + + + + + + + + + +
+

Async Logo

+

Build Status via Travis CI +NPM version +Coverage Status +Join the chat at https://gitter.im/caolan/async

+

For Async v1.5.x documentation, go HERE

+

Async is a utility module which provides straight-forward, powerful functions +for working with asynchronous JavaScript. Although originally designed for +use with Node.js and installable via npm install --save async, +it can also be used directly in the browser.

+

Async is also installable via:

+
    +
  • bower: bower install async
  • +
  • component: component install caolan/async
  • +
  • jam: jam install async
  • +
+

Async provides around 70 functions that include the usual 'functional' +suspects (map, reduce, filter, each…) as well as some common patterns +for asynchronous control flow (parallel, series, waterfall…). All these +functions assume you follow the Node.js convention of providing a single +callback as the last argument of your asynchronous function -- a callback which expects an Error as its first argument -- and calling the callback once.

+

Quick Examples

async.map(['file1','file2','file3'], fs.stat, function(err, results) {
+    // results is now an array of stats for each file
+});
+
+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
+});
+
+async.parallel([
+    function(callback) { ... },
+    function(callback) { ... }
+], function(err, results) {
+    // optional callback
+});
+
+async.series([
+    function(callback) { ... },
+    function(callback) { ... }
+]);

There are many more functions available so take a look at the docs below for a +full list. This module aims to be comprehensive, so if you feel anything is +missing please create a GitHub issue for it.

+

Common Pitfalls (StackOverflow)

Synchronous iteration functions

If you get an error like RangeError: Maximum call stack size exceeded. or other stack overflow issues when using async, you are likely using a synchronous iteratee. By synchronous we mean a function that calls its callback on the same tick in the javascript event loop, without doing any I/O or using any timers. Calling many callbacks iteratively will quickly overflow the stack. If you run into this issue, just defer your callback with async.setImmediate to start a new call stack on the next tick of the event loop.

+

This can also arise by accident if you callback early in certain cases:

+
async.eachSeries(hugeArray, function iteratee(item, callback) {
+    if (inCache(item)) {
+        callback(null, cache[item]); // if many items are cached, you'll overflow
+    } else {
+        doSomeIO(item, callback);
+    }
+}, function done() {
+    //...
+});

Just change it to:

+
async.eachSeries(hugeArray, function iteratee(item, callback) {
+    if (inCache(item)) {
+        async.setImmediate(function() {
+            callback(null, cache[item]);
+        });
+    } else {
+        doSomeIO(item, callback);
+        //...
+    }
+});

Async does not guard against synchronous iteratees for performance reasons. If you are still running into stack overflows, you can defer as suggested above, or wrap functions with async.ensureAsync Functions that are asynchronous by their nature do not have this problem and don't need the extra callback deferral.

+

If JavaScript's event loop is still a bit nebulous, check out this article or this talk for more detailed information about how it works.

+

Multiple callbacks

Make sure to always return when calling a callback early, otherwise you will cause multiple callbacks and unpredictable behavior in many cases.

+
async.waterfall([
+    function(callback) {
+        getSomething(options, function (err, result) {
+            if (err) {
+                callback(new Error("failed getting something:" + err.message));
+                // we should return here
+            }
+            // since we did not return, this callback still will be called and
+            // `processData` will be called twice
+            callback(null, result);
+        });
+    },
+    processData
+], done)

It is always good practice to return callback(err, result) whenever a callback call is not the last statement of a function.

+

Binding a context to an iteratee

This section is really about bind, not about async. If you are wondering how to +make async execute your iteratees in a given context, or are confused as to why +a method of another library isn't working as an iteratee, study this example:

+
// Here is a simple object with an (unnecessarily roundabout) squaring method
+var AsyncSquaringLibrary = {
+    squareExponent: 2,
+    square: function(number, callback){
+        var result = Math.pow(number, this.squareExponent);
+        setTimeout(function(){
+            callback(null, result);
+        }, 200);
+    }
+};
+
+async.map([1, 2, 3], AsyncSquaringLibrary.square, function(err, result) {
+    // result is [NaN, NaN, NaN]
+    // This fails because the `this.squareExponent` expression in the square
+    // function is not evaluated in the context of AsyncSquaringLibrary, and is
+    // therefore undefined.
+});
+
+async.map([1, 2, 3], AsyncSquaringLibrary.square.bind(AsyncSquaringLibrary), function(err, result) {
+    // result is [1, 4, 9]
+    // With the help of bind we can attach a context to the iteratee before
+    // passing it to async. Now the square function will be executed in its
+    // 'home' AsyncSquaringLibrary context and the value of `this.squareExponent`
+    // will be as expected.
+});

Download

The source is available for download from +GitHub. +Alternatively, you can install using npm:

+
$ npm install --save async

As well as using Bower:

+
$ bower install async

You can then require() async as normal:

+
var async = require("async");

Or require individual methods:

+
var waterfall = require("async/waterfall");
+var map = require("async/map");

Development: async.js - 29.6kb Uncompressed

+

In the Browser

Async should work in any ES5 environment (IE9 and above).

+

Usage:

+
<script type="text/javascript" src="async.js"></script>
+<script type="text/javascript">
+
+    async.map(data, asyncProcess, function(err, results) {
+        alert(results);
+    });
+
+</script>

The portable versions of async, including async.js and async.min.js, are +included in the /dist folder. Async can also be found on the jsDelivr CDN.

+

ES Modules

We also provide async as a collection of ES2015 modules, in an alternative async-es package on npm.

+
$ npm install --save async-es
import waterfall from 'async-es/waterfall';
+import async from 'async-es';
+
+ + + + + + +
+
+ + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/index.js.html b/index.js.html new file mode 100644 index 000000000..78fcff413 --- /dev/null +++ b/index.js.html @@ -0,0 +1,393 @@ + + + + + + + index.js - Documentation + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +

index.js

+ + + + + + + +
+
+
/**
+ * 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`, it can also be used directly in the browser.
+ * @module async
+ */
+
+/**
+ * A collection of `async` functions for manipulating collections, such as
+ * arrays and objects.
+ * @module Collections
+ */
+
+/**
+ * A collection of `async` functions for controlling the flow through a script.
+ * @module ControlFlow
+ */
+
+ /**
+  * A collection of `async` utility functions.
+  * @module Utils
+  */
+import applyEach from './applyEach';
+import applyEachSeries from './applyEachSeries';
+import apply from './apply';
+import asyncify from './asyncify';
+import auto from './auto';
+import autoInject from './autoInject';
+import cargo from './cargo';
+import compose from './compose';
+import concat from './concat';
+import concatSeries from './concatSeries';
+import constant from './constant';
+import detect from './detect';
+import detectLimit from './detectLimit';
+import detectSeries from './detectSeries';
+import dir from './dir';
+import doDuring from './doDuring';
+import doUntil from './doUntil';
+import doWhilst from './doWhilst';
+import during from './during';
+import each from './each';
+import eachLimit from './eachLimit';
+import eachOf from './eachOf';
+import eachOfLimit from './eachOfLimit';
+import eachOfSeries from './eachOfSeries';
+import eachSeries from './eachSeries';
+import ensureAsync from './ensureAsync';
+import every from './every';
+import everyLimit from './everyLimit';
+import everySeries from './everySeries';
+import filter from './filter';
+import filterLimit from './filterLimit';
+import filterSeries from './filterSeries';
+import forever from './forever';
+import log from './log';
+import map from './map';
+import mapLimit from './mapLimit';
+import mapSeries from './mapSeries';
+import mapValues from './mapValues';
+import mapValuesLimit from './mapValuesLimit';
+import mapValuesSeries from './mapValuesSeries';
+import memoize from './memoize';
+import nextTick from './nextTick';
+import parallel from './parallel';
+import parallelLimit from './parallelLimit';
+import priorityQueue from './priorityQueue';
+import queue from './queue';
+import race from './race';
+import reduce from './reduce';
+import reduceRight from './reduceRight';
+import reflect from './reflect';
+import reject from './reject';
+import reflectAll from './reflectAll';
+import rejectLimit from './rejectLimit';
+import rejectSeries from './rejectSeries';
+import retry from './retry';
+import retryable from './retryable';
+import seq from './seq';
+import series from './series';
+import setImmediate from './setImmediate';
+import some from './some';
+import someLimit from './someLimit';
+import someSeries from './someSeries';
+import sortBy from './sortBy';
+import timeout from './timeout';
+import times from './times';
+import timesLimit from './timesLimit';
+import timesSeries from './timesSeries';
+import transform from './transform';
+import unmemoize from './unmemoize';
+import until from './until';
+import waterfall from './waterfall';
+import whilst from './whilst';
+
+export default {
+    applyEach: applyEach,
+    applyEachSeries: applyEachSeries,
+    apply: apply,
+    asyncify: asyncify,
+    auto: auto,
+    autoInject: autoInject,
+    cargo: cargo,
+    compose: compose,
+    concat: concat,
+    concatSeries: concatSeries,
+    constant: constant,
+    detect: detect,
+    detectLimit: detectLimit,
+    detectSeries: detectSeries,
+    dir: dir,
+    doDuring: doDuring,
+    doUntil: doUntil,
+    doWhilst: doWhilst,
+    during: during,
+    each: each,
+    eachLimit: eachLimit,
+    eachOf: eachOf,
+    eachOfLimit: eachOfLimit,
+    eachOfSeries: eachOfSeries,
+    eachSeries: eachSeries,
+    ensureAsync: ensureAsync,
+    every: every,
+    everyLimit: everyLimit,
+    everySeries: everySeries,
+    filter: filter,
+    filterLimit: filterLimit,
+    filterSeries: filterSeries,
+    forever: forever,
+    log: log,
+    map: map,
+    mapLimit: mapLimit,
+    mapSeries: mapSeries,
+    mapValues: mapValues,
+    mapValuesLimit: mapValuesLimit,
+    mapValuesSeries: mapValuesSeries,
+    memoize: memoize,
+    nextTick: nextTick,
+    parallel: parallel,
+    parallelLimit: parallelLimit,
+    priorityQueue: priorityQueue,
+    queue: queue,
+    race: race,
+    reduce: reduce,
+    reduceRight: reduceRight,
+    reflect: reflect,
+    reflectAll: reflectAll,
+    reject: reject,
+    rejectLimit: rejectLimit,
+    rejectSeries: rejectSeries,
+    retry: retry,
+    retryable: retryable,
+    seq: seq,
+    series: series,
+    setImmediate: setImmediate,
+    some: some,
+    someLimit: someLimit,
+    someSeries: someSeries,
+    sortBy: sortBy,
+    timeout: timeout,
+    times: times,
+    timesLimit: timesLimit,
+    timesSeries: timesSeries,
+    transform: transform,
+    unmemoize: unmemoize,
+    until: until,
+    waterfall: waterfall,
+    whilst: whilst,
+
+    // aliases
+    all: every,
+    any: some,
+    forEach: each,
+    forEachSeries: eachSeries,
+    forEachLimit: eachLimit,
+    forEachOf: eachOf,
+    forEachOfSeries: eachOfSeries,
+    forEachOfLimit: eachOfLimit,
+    inject: reduce,
+    foldl: reduce,
+    foldr: reduceRight,
+    select: filter,
+    selectLimit: filterLimit,
+    selectSeries: filterSeries,
+    wrapSync: asyncify
+};
+
+export {
+    applyEach as applyEach,
+    applyEachSeries as applyEachSeries,
+    apply as apply,
+    asyncify as asyncify,
+    auto as auto,
+    autoInject as autoInject,
+    cargo as cargo,
+    compose as compose,
+    concat as concat,
+    concatSeries as concatSeries,
+    constant as constant,
+    detect as detect,
+    detectLimit as detectLimit,
+    detectSeries as detectSeries,
+    dir as dir,
+    doDuring as doDuring,
+    doUntil as doUntil,
+    doWhilst as doWhilst,
+    during as during,
+    each as each,
+    eachLimit as eachLimit,
+    eachOf as eachOf,
+    eachOfLimit as eachOfLimit,
+    eachOfSeries as eachOfSeries,
+    eachSeries as eachSeries,
+    ensureAsync as ensureAsync,
+    every as every,
+    everyLimit as everyLimit,
+    everySeries as everySeries,
+    filter as filter,
+    filterLimit as filterLimit,
+    filterSeries as filterSeries,
+    forever as forever,
+    log as log,
+    map as map,
+    mapLimit as mapLimit,
+    mapSeries as mapSeries,
+    mapValues as mapValues,
+    mapValuesLimit as mapValuesLimit,
+    mapValuesSeries as mapValuesSeries,
+    memoize as memoize,
+    nextTick as nextTick,
+    parallel as parallel,
+    parallelLimit as parallelLimit,
+    priorityQueue as priorityQueue,
+    queue as queue,
+    race as race,
+    reduce as reduce,
+    reduceRight as reduceRight,
+    reflect as reflect,
+    reflectAll as reflectAll,
+    reject as reject,
+    rejectLimit as rejectLimit,
+    rejectSeries as rejectSeries,
+    retry as retry,
+    retryable as retryable,
+    seq as seq,
+    series as series,
+    setImmediate as setImmediate,
+    some as some,
+    someLimit as someLimit,
+    someSeries as someSeries,
+    sortBy as sortBy,
+    timeout as timeout,
+    times as times,
+    timesLimit as timesLimit,
+    timesSeries as timesSeries,
+    transform as transform,
+    unmemoize as unmemoize,
+    until as until,
+    waterfall as waterfall,
+    whilst as whilst,
+
+    // Aliases
+    every as all,
+    everyLimit as allLimit,
+    everySeries as allSeries,
+    some as any,
+    someLimit as anyLimit,
+    someSeries as anySeries,
+    detect as find,
+    detectLimit as findLimit,
+    detectSeries as findSeries,
+    each as forEach,
+    eachSeries as forEachSeries,
+    eachLimit as forEachLimit,
+    eachOf as forEachOf,
+    eachOfSeries as forEachOfSeries,
+    eachOfLimit as forEachOfLimit,
+    reduce as inject,
+    reduce as foldl,
+    reduceRight as foldr,
+    filter as select,
+    filterLimit as selectLimit,
+    filterSeries as selectSeries,
+    asyncify as wrapSync
+};
+
+
+
+ + + + +
+
+ + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/log.js.html b/log.js.html new file mode 100644 index 000000000..c6401f265 --- /dev/null +++ b/log.js.html @@ -0,0 +1,137 @@ + + + + + + + log.js - Documentation + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +

log.js

+ + + + + + + +
+
+
import consoleFunc from './internal/consoleFunc';
+
+/**
+ * Logs the result of an `async` function to the `console`. Only works in
+ * Node.js or in browsers that support `console.log` and `console.error` (such
+ * as FF and Chrome). If multiple arguments are returned from the async
+ * function, `console.log` is called on each argument in order.
+ *
+ * @name log
+ * @static
+ * @memberOf module:Utils
+ * @method
+ * @category Util
+ * @param {Function} function - The function you want to eventually apply all
+ * arguments to.
+ * @param {...*} arguments... - Any number of arguments to apply to the function.
+ * @example
+ *
+ * // in a module
+ * var hello = function(name, callback) {
+ *     setTimeout(function() {
+ *         callback(null, 'hello ' + name);
+ *     }, 1000);
+ * };
+ *
+ * // in the node repl
+ * node> async.log(hello, 'world');
+ * 'hello world'
+ */
+export default consoleFunc('log');
+
+
+
+ + + + +
+
+ + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/map.js.html b/map.js.html new file mode 100644 index 000000000..4bbff4ee8 --- /dev/null +++ b/map.js.html @@ -0,0 +1,147 @@ + + + + + + + map.js - Documentation + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +

map.js

+ + + + + + + +
+
+
import doParallel from './internal/doParallel';
+import map from './internal/map';
+
+/**
+ * Produces a new collection of values by mapping each value in `coll` through
+ * the `iteratee` function. The `iteratee` is called with an item from `coll`
+ * and a callback for when it has finished processing. Each of these callback
+ * takes 2 arguments: an `error`, and the transformed item from `coll`. If
+ * `iteratee` passes an error to its callback, the main `callback` (for the
+ * `map` function) is immediately called with the error.
+ *
+ * Note, that since this function applies the `iteratee` to each item in
+ * parallel, there is no guarantee that the `iteratee` functions will complete
+ * in order. However, the results array will be in the same order as the
+ * original `coll`.
+ *
+ * If `map` is passed an Object, the results will be an Array.  The results
+ * will roughly be in the order of the original Objects' keys (but this can
+ * vary across JavaScript engines)
+ *
+ * @name map
+ * @static
+ * @memberOf module:Collections
+ * @method
+ * @category Collection
+ * @param {Array|Iterable|Object} coll - A collection to iterate over.
+ * @param {Function} iteratee - A function to apply to each item in `coll`.
+ * The iteratee is passed a `callback(err, transformed)` which must be called
+ * once it has completed with an error (which can be `null`) and a
+ * transformed item. Invoked with (item, callback).
+ * @param {Function} [callback] - A callback which is called when all `iteratee`
+ * functions have finished, or an error occurs. Results is an Array of the
+ * transformed items from the `coll`. Invoked with (err, results).
+ * @example
+ *
+ * async.map(['file1','file2','file3'], fs.stat, function(err, results) {
+ *     // results is now an array of stats for each file
+ * });
+ */
+export default doParallel(map);
+
+
+
+ + + + +
+
+ + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/mapLimit.js.html b/mapLimit.js.html new file mode 100644 index 000000000..251fd5fd2 --- /dev/null +++ b/mapLimit.js.html @@ -0,0 +1,130 @@ + + + + + + + mapLimit.js - Documentation + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +

mapLimit.js

+ + + + + + + +
+
+
import doParallelLimit from './internal/doParallelLimit';
+import map from './internal/map';
+
+/**
+ * The same as [`map`]{@link module:Collections.map} but runs a maximum of `limit` async operations at a time.
+ *
+ * @name mapLimit
+ * @static
+ * @memberOf module:Collections
+ * @method
+ * @see [async.map]{@link module:Collections.map}
+ * @category Collection
+ * @param {Array|Iterable|Object} coll - A collection to iterate over.
+ * @param {number} limit - The maximum number of async operations at a time.
+ * @param {Function} iteratee - A function to apply to each item in `coll`.
+ * The iteratee is passed a `callback(err, transformed)` which must be called
+ * once it has completed with an error (which can be `null`) and a transformed
+ * item. Invoked with (item, callback).
+ * @param {Function} [callback] - A callback which is called when all `iteratee`
+ * functions have finished, or an error occurs. Results is an array of the
+ * transformed items from the `coll`. Invoked with (err, results).
+ */
+export default doParallelLimit(map);
+
+
+
+ + + + +
+
+ + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/mapSeries.js.html b/mapSeries.js.html new file mode 100644 index 000000000..b82c5d35c --- /dev/null +++ b/mapSeries.js.html @@ -0,0 +1,129 @@ + + + + + + + mapSeries.js - Documentation + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +

mapSeries.js

+ + + + + + + +
+
+
import mapLimit from './mapLimit';
+import doLimit from './internal/doLimit';
+
+/**
+ * The same as [`map`]{@link module:Collections.map} but runs only a single async operation at a time.
+ *
+ * @name mapSeries
+ * @static
+ * @memberOf module:Collections
+ * @method
+ * @see [async.map]{@link module:Collections.map}
+ * @category Collection
+ * @param {Array|Iterable|Object} coll - A collection to iterate over.
+ * @param {Function} iteratee - A function to apply to each item in `coll`.
+ * The iteratee is passed a `callback(err, transformed)` which must be called
+ * once it has completed with an error (which can be `null`) and a
+ * transformed item. Invoked with (item, callback).
+ * @param {Function} [callback] - A callback which is called when all `iteratee`
+ * functions have finished, or an error occurs. Results is an array of the
+ * transformed items from the `coll`. Invoked with (err, results).
+ */
+export default doLimit(mapLimit, 1);
+
+
+
+ + + + +
+
+ + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/mapValues.js.html b/mapValues.js.html new file mode 100644 index 000000000..f122570d0 --- /dev/null +++ b/mapValues.js.html @@ -0,0 +1,157 @@ + + + + + + + mapValues.js - Documentation + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +

mapValues.js

+ + + + + + + +
+
+
import mapValuesLimit from './mapValuesLimit';
+import doLimit from './internal/doLimit';
+
+
+/**
+ * A relative of [`map`]{@link module:Collections.map}, designed for use with objects.
+ *
+ * Produces a new Object by mapping each value of `obj` through the `iteratee`
+ * function. The `iteratee` is called each `value` and `key` from `obj` and a
+ * callback for when it has finished processing. Each of these callbacks takes
+ * two arguments: an `error`, and the transformed item from `obj`. If `iteratee`
+ * passes an error to its callback, the main `callback` (for the `mapValues`
+ * function) is immediately called with the error.
+ *
+ * Note, the order of the keys in the result is not guaranteed.  The keys will
+ * be roughly in the order they complete, (but this is very engine-specific)
+ *
+ * @name mapValues
+ * @static
+ * @memberOf module:Collections
+ * @method
+ * @category Collection
+ * @param {Object} obj - A collection to iterate over.
+ * @param {Function} iteratee - A function to apply to each value and key in
+ * `coll`. The iteratee is passed a `callback(err, transformed)` which must be
+ * called once it has completed with an error (which can be `null`) and a
+ * transformed value. Invoked with (value, key, callback).
+ * @param {Function} [callback] - A callback which is called when all `iteratee`
+ * functions have finished, or an error occurs. `result` is a new object consisting
+ * of each key from `obj`, with each transformed value on the right-hand side.
+ * Invoked with (err, result).
+ * @example
+ *
+ * async.mapValues({
+ *     f1: 'file1',
+ *     f2: 'file2',
+ *     f3: 'file3'
+ * }, function (file, key, callback) {
+ *   fs.stat(file, callback);
+ * }, function(err, result) {
+ *     // result is now a map of stats for each file, e.g.
+ *     // {
+ *     //     f1: [stats for file1],
+ *     //     f2: [stats for file2],
+ *     //     f3: [stats for file3]
+ *     // }
+ * });
+ */
+
+export default doLimit(mapValuesLimit, Infinity);
+
+
+
+ + + + +
+
+ + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/mapValuesLimit.js.html b/mapValuesLimit.js.html new file mode 100644 index 000000000..621245913 --- /dev/null +++ b/mapValuesLimit.js.html @@ -0,0 +1,146 @@ + + + + + + + mapValuesLimit.js - Documentation + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +

mapValuesLimit.js

+ + + + + + + +
+
+
import eachOfLimit from './eachOfLimit';
+
+import noop from 'lodash/noop';
+import once from './internal/once';
+
+/**
+ * The same as [`mapValues`]{@link module:Collections.mapValues} but runs a maximum of `limit` async operations at a
+ * time.
+ *
+ * @name mapValuesLimit
+ * @static
+ * @memberOf module:Collections
+ * @method
+ * @see [async.mapValues]{@link module:Collections.mapValues}
+ * @category Collection
+ * @param {Object} obj - A collection to iterate over.
+ * @param {number} limit - The maximum number of async operations at a time.
+ * @param {Function} iteratee - A function to apply to each value in `obj`.
+ * The iteratee is passed a `callback(err, transformed)` which must be called
+ * once it has completed with an error (which can be `null`) and a
+ * transformed value. Invoked with (value, key, callback).
+ * @param {Function} [callback] - A callback which is called when all `iteratee`
+ * functions have finished, or an error occurs. `result` is a new object consisting
+ * of each key from `obj`, with each transformed value on the right-hand side.
+ * Invoked with (err, result).
+ */
+export default function mapValuesLimit(obj, limit, iteratee, callback) {
+    callback = once(callback || noop);
+    var newObj = {};
+    eachOfLimit(obj, limit, function(val, key, next) {
+        iteratee(val, key, function (err, result) {
+            if (err) return next(err);
+            newObj[key] = result;
+            next();
+        });
+    }, function (err) {
+        callback(err, newObj);
+    });
+}
+
+
+
+ + + + +
+
+ + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/mapValuesSeries.js.html b/mapValuesSeries.js.html new file mode 100644 index 000000000..51dd185c7 --- /dev/null +++ b/mapValuesSeries.js.html @@ -0,0 +1,130 @@ + + + + + + + mapValuesSeries.js - Documentation + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +

mapValuesSeries.js

+ + + + + + + +
+
+
import mapValuesLimit from './mapValuesLimit';
+import doLimit from './internal/doLimit';
+
+/**
+ * The same as [`mapValues`]{@link module:Collections.mapValues} but runs only a single async operation at a time.
+ *
+ * @name mapValuesSeries
+ * @static
+ * @memberOf module:Collections
+ * @method
+ * @see [async.mapValues]{@link module:Collections.mapValues}
+ * @category Collection
+ * @param {Object} obj - A collection to iterate over.
+ * @param {Function} iteratee - A function to apply to each value in `obj`.
+ * The iteratee is passed a `callback(err, transformed)` which must be called
+ * once it has completed with an error (which can be `null`) and a
+ * transformed value. Invoked with (value, key, callback).
+ * @param {Function} [callback] - A callback which is called when all `iteratee`
+ * functions have finished, or an error occurs. `result` is a new object consisting
+ * of each key from `obj`, with each transformed value on the right-hand side.
+ * Invoked with (err, result).
+ */
+export default doLimit(mapValuesLimit, 1);
+
+
+
+ + + + +
+
+ + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/memoize.js.html b/memoize.js.html new file mode 100644 index 000000000..ef0501158 --- /dev/null +++ b/memoize.js.html @@ -0,0 +1,182 @@ + + + + + + + memoize.js - Documentation + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +

memoize.js

+ + + + + + + +
+
+
import identity from 'lodash/identity';
+import rest from './internal/rest';
+
+import setImmediate from './internal/setImmediate';
+import initialParams from './internal/initialParams';
+
+function has(obj, key) {
+    return key in obj;
+}
+
+/**
+ * Caches the results of an `async` function. When creating a hash to store
+ * function results against, the callback is omitted from the hash and an
+ * optional hash function can be used.
+ *
+ * If no hash function is specified, the first argument is used as a hash key,
+ * which may work reasonably if it is a string or a data type that converts to a
+ * distinct string. Note that objects and arrays will not behave reasonably.
+ * Neither will cases where the other arguments are significant. In such cases,
+ * specify your own hash function.
+ *
+ * The cache of results is exposed as the `memo` property of the function
+ * returned by `memoize`.
+ *
+ * @name memoize
+ * @static
+ * @memberOf module:Utils
+ * @method
+ * @category Util
+ * @param {Function} fn - The function to proxy and cache results from.
+ * @param {Function} hasher - An optional function for generating a custom hash
+ * for storing results. It has all the arguments applied to it apart from the
+ * callback, and must be synchronous.
+ * @returns {Function} a memoized version of `fn`
+ * @example
+ *
+ * var slow_fn = function(name, callback) {
+ *     // do something
+ *     callback(null, result);
+ * };
+ * var fn = async.memoize(slow_fn);
+ *
+ * // fn can now be used as if it were slow_fn
+ * fn('some name', function() {
+ *     // callback
+ * });
+ */
+export default function memoize(fn, hasher) {
+    var memo = Object.create(null);
+    var queues = Object.create(null);
+    hasher = hasher || identity;
+    var memoized = initialParams(function memoized(args, callback) {
+        var key = hasher.apply(null, args);
+        if (has(memo, key)) {
+            setImmediate(function() {
+                callback.apply(null, memo[key]);
+            });
+        } else if (has(queues, key)) {
+            queues[key].push(callback);
+        } else {
+            queues[key] = [callback];
+            fn.apply(null, args.concat(rest(function(args) {
+                memo[key] = args;
+                var q = queues[key];
+                delete queues[key];
+                for (var i = 0, l = q.length; i < l; i++) {
+                    q[i].apply(null, args);
+                }
+            })));
+        }
+    });
+    memoized.memo = memo;
+    memoized.unmemoized = fn;
+    return memoized;
+}
+
+
+
+ + + + +
+
+ + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/module-Collections.html b/module-Collections.html new file mode 100644 index 000000000..bad3eda77 --- /dev/null +++ b/module-Collections.html @@ -0,0 +1,7308 @@ + + + + + + + Collections - Documentation + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +

Collections

+ + + + + + + +
+ +
+ + + + + +
+ +
+
+ + +

A collection of async functions for manipulating collections, such as +arrays and objects.

+ + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + +

Methods

+ + + + + + +

(static) concat(coll, iteratee, callback(err)opt)

+ + + + + +
+
import concat from 'async/concat';

Applies iteratee to each item in coll, concatenating the results. Returns +the concatenated list. The iteratees 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.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
coll + + +Array +| + +Iterable +| + +Object + + + + + +

A collection to iterate over.

iteratee + + +function + + + + + +

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).

callback(err) + + +function + + + + + + <optional> + +

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
+});
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + +

(static) concatSeries(coll, iteratee, callback(err)opt)

+ + + + + +
+
import concatSeries from 'async/concatSeries';

The same as concat but runs only a single async operation at a time.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
coll + + +Array +| + +Iterable +| + +Object + + + + + +

A collection to iterate over.

iteratee + + +function + + + + + +

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).

callback(err) + + +function + + + + + + <optional> + +

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).

+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +

(static) detect(coll, iteratee, callbackopt)

+ + + + + +
+
import detect from 'async/detect';

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.

+
+ + + +
+
Alias:
+
  • find
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
coll + + +Array +| + +Iterable +| + +Object + + + + + +

A collection to iterate over.

iteratee + + +function + + + + + +

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).

callback + + +function + + + + + + <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 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
+});
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + +

(static) detectLimit(coll, limit, iteratee, callbackopt)

+ + + + + +
+
import detectLimit from 'async/detectLimit';

The same as detect but runs a maximum of limit async operations at a +time.

+
+ + + +
+
Alias:
+
  • findLimit
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
coll + + +Array +| + +Iterable +| + +Object + + + + + +

A collection to iterate over.

limit + + +number + + + + + +

The maximum number of async operations at a time.

iteratee + + +function + + + + + +

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).

callback + + +function + + + + + + <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 value undefined if none passed. Invoked with +(err, result).

+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +

(static) detectSeries(coll, iteratee, callbackopt)

+ + + + + +
+
import detectSeries from 'async/detectSeries';

The same as detect but runs only a single async operation at a time.

+
+ + + +
+
Alias:
+
  • findSeries
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
coll + + +Array +| + +Iterable +| + +Object + + + + + +

A collection to iterate over.

iteratee + + +function + + + + + +

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).

callback + + +function + + + + + + <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 value undefined if none passed. Invoked with +(err, result).

+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +

(static) each(coll, iteratee, callbackopt)

+ + + + + +
+
import each from 'async/each';

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.

+
+ + + +
+
Alias:
+
  • forEach
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
coll + + +Array +| + +Iterable +| + +Object + + + + + +

A collection to iterate over.

iteratee + + +function + + + + + +

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.

callback + + +function + + + + + + <optional> + +

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');
+    }
+});
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + +

(static) eachLimit(coll, limit, iteratee, callbackopt)

+ + + + + +
+
import eachLimit from 'async/eachLimit';

The same as each but runs a maximum of limit async operations at a time.

+
+ + + +
+
Alias:
+
  • forEachLimit
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
coll + + +Array +| + +Iterable +| + +Object + + + + + +

A collection to iterate over.

limit + + +number + + + + + +

The maximum number of async operations at a time.

iteratee + + +function + + + + + +

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.

callback + + +function + + + + + + <optional> + +

A callback which is called when all +iteratee functions have finished, or an error occurs. Invoked with (err).

+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +

(static) eachOf(coll, iteratee, callbackopt)

+ + + + + +
+
import eachOf from 'async/eachOf';

Like each, except that it passes the key (or index) as the second argument +to the iteratee.

+
+ + + +
+
Alias:
+
  • forEachOf
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
coll + + +Array +| + +Iterable +| + +Object + + + + + +

A collection to iterate over.

iteratee + + +function + + + + + +

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).

callback + + +function + + + + + + <optional> + +

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);
+});
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +

(static) eachOfLimit(coll, limit, iteratee, callbackopt)

+ + + + + +
+
import eachOfLimit from 'async/eachOfLimit';

The same as eachOf but runs a maximum of limit async operations at a +time.

+
+ + + +
+
Alias:
+
  • forEachOfLimit
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
coll + + +Array +| + +Iterable +| + +Object + + + + + +

A collection to iterate over.

limit + + +number + + + + + +

The maximum number of async operations at a time.

iteratee + + +function + + + + + +

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).

callback + + +function + + + + + + <optional> + +

A callback which is called when all +iteratee functions have finished, or an error occurs. Invoked with (err).

+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +

(static) eachOfSeries(coll, iteratee, callbackopt)

+ + + + + +
+
import eachOfSeries from 'async/eachOfSeries';

The same as eachOf but runs only a single async operation at a time.

+
+ + + +
+
Alias:
+
  • forEachOfSeries
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
coll + + +Array +| + +Iterable +| + +Object + + + + + +

A collection to iterate over.

iteratee + + +function + + + + + +

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).

callback + + +function + + + + + + <optional> + +

A callback which is called when all iteratee +functions have finished, or an error occurs. Invoked with (err).

+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +

(static) eachSeries(coll, iteratee, callbackopt)

+ + + + + +
+
import eachSeries from 'async/eachSeries';

The same as each but runs only a single async operation at a time.

+
+ + + +
+
Alias:
+
  • forEachSeries
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
coll + + +Array +| + +Iterable +| + +Object + + + + + +

A collection to iterate over.

iteratee + + +function + + + + + +

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.

callback + + +function + + + + + + <optional> + +

A callback which is called when all +iteratee functions have finished, or an error occurs. Invoked with (err).

+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +

(static) every(coll, iteratee, callbackopt)

+ + + + + +
+
import every from 'async/every';

Returns true if every element in coll satisfies an async test. If any +iteratee call returns false, the main callback is immediately called.

+
+ + + +
+
Alias:
+
  • all
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
coll + + +Array +| + +Iterable +| + +Object + + + + + +

A collection to iterate over.

iteratee + + +function + + + + + +

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).

callback + + +function + + + + + + <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. 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
+});
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + +

(static) everyLimit(coll, limit, iteratee, callbackopt)

+ + + + + +
+
import everyLimit from 'async/everyLimit';

The same as every but runs a maximum of limit async operations at a time.

+
+ + + +
+
Alias:
+
  • allLimit
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
coll + + +Array +| + +Iterable +| + +Object + + + + + +

A collection to iterate over.

limit + + +number + + + + + +

The maximum number of async operations at a time.

iteratee + + +function + + + + + +

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).

callback + + +function + + + + + + <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. Invoked with (err, result).

+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +

(static) everySeries(coll, iteratee, callbackopt)

+ + + + + +
+
import everySeries from 'async/everySeries';

The same as every but runs only a single async operation at a time.

+
+ + + +
+
Alias:
+
  • allSeries
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
coll + + +Array +| + +Iterable +| + +Object + + + + + +

A collection to iterate over.

iteratee + + +function + + + + + +

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).

callback + + +function + + + + + + <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. Invoked with (err, result).

+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +

(static) filter(coll, iteratee, callbackopt)

+ + + + + +
+
import filter from 'async/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.

+
+ + + +
+
Alias:
+
  • select
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
coll + + +Array +| + +Iterable +| + +Object + + + + + +

A collection to iterate over.

iteratee + + +function + + + + + +

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).

callback + + +function + + + + + + <optional> + +

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
+});
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + +

(static) filterLimit(coll, limit, iteratee, callbackopt)

+ + + + + +
+
import filterLimit from 'async/filterLimit';

The same as filter but runs a maximum of limit async operations at a +time.

+
+ + + +
+
Alias:
+
  • selectLimit
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
coll + + +Array +| + +Iterable +| + +Object + + + + + +

A collection to iterate over.

limit + + +number + + + + + +

The maximum number of async operations at a time.

iteratee + + +function + + + + + +

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).

callback + + +function + + + + + + <optional> + +

A callback which is called after all the +iteratee functions have finished. Invoked with (err, results).

+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +

(static) filterSeries(coll, iteratee, callbackopt)

+ + + + + +
+
import filterSeries from 'async/filterSeries';

The same as filter but runs only a single async operation at a time.

+
+ + + +
+
Alias:
+
  • selectSeries
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
coll + + +Array +| + +Iterable +| + +Object + + + + + +

A collection to iterate over.

iteratee + + +function + + + + + +

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).

callback + + +function + + + + + + <optional> + +

A callback which is called after all the +iteratee functions have finished. Invoked with (err, results)

+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +

(static) map(coll, iteratee, callbackopt)

+ + + + + +
+
import map from 'async/map';

Produces a new collection of values by mapping each value in coll through +the iteratee function. The iteratee is called with an item from coll +and a callback for when it has finished processing. Each of these callback +takes 2 arguments: an error, and the transformed item from coll. If +iteratee passes an error to its callback, the main callback (for the +map function) is immediately called with the error.

+

Note, that since this function applies the iteratee to each item in +parallel, there is no guarantee that the iteratee functions will complete +in order. However, the results array will be in the same order as the +original coll.

+

If map is passed an Object, the results will be an Array. The results +will roughly be in the order of the original Objects' keys (but this can +vary across JavaScript engines)

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
coll + + +Array +| + +Iterable +| + +Object + + + + + +

A collection to iterate over.

iteratee + + +function + + + + + +

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).

callback + + +function + + + + + + <optional> + +

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
+});
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + +

(static) mapLimit(coll, limit, iteratee, callbackopt)

+ + + + + +
+
import mapLimit from 'async/mapLimit';

The same as map but runs a maximum of limit async operations at a time.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
coll + + +Array +| + +Iterable +| + +Object + + + + + +

A collection to iterate over.

limit + + +number + + + + + +

The maximum number of async operations at a time.

iteratee + + +function + + + + + +

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).

callback + + +function + + + + + + <optional> + +

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).

+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +

(static) mapSeries(coll, iteratee, callbackopt)

+ + + + + +
+
import mapSeries from 'async/mapSeries';

The same as map but runs only a single async operation at a time.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
coll + + +Array +| + +Iterable +| + +Object + + + + + +

A collection to iterate over.

iteratee + + +function + + + + + +

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).

callback + + +function + + + + + + <optional> + +

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).

+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +

(static) mapValues(obj, iteratee, callbackopt)

+ + + + + +
+
import mapValues from 'async/mapValues';

A relative of map, designed for use with objects.

+

Produces a new Object by mapping each value of obj through the iteratee +function. The iteratee is called each value and key from obj and a +callback for when it has finished processing. Each of these callbacks takes +two arguments: an error, and the transformed item from obj. If iteratee +passes an error to its callback, the main callback (for the mapValues +function) is immediately called with the error.

+

Note, the order of the keys in the result is not guaranteed. The keys will +be roughly in the order they complete, (but this is very engine-specific)

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
obj + + +Object + + + + + +

A collection to iterate over.

iteratee + + +function + + + + + +

A function to apply to each value and key in +coll. The iteratee is passed a callback(err, transformed) which must be +called once it has completed with an error (which can be null) and a +transformed value. Invoked with (value, key, callback).

callback + + +function + + + + + + <optional> + +

A callback which is called when all iteratee +functions have finished, or an error occurs. result is a new object consisting +of each key from obj, with each transformed value on the right-hand side. +Invoked with (err, result).

+ + + + + + +
Example
+ +
async.mapValues({
+    f1: 'file1',
+    f2: 'file2',
+    f3: 'file3'
+}, function (file, key, callback) {
+  fs.stat(file, callback);
+}, function(err, result) {
+    // result is now a map of stats for each file, e.g.
+    // {
+    //     f1: [stats for file1],
+    //     f2: [stats for file2],
+    //     f3: [stats for file3]
+    // }
+});
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + +

(static) mapValuesLimit(obj, limit, iteratee, callbackopt)

+ + + + + +
+
import mapValuesLimit from 'async/mapValuesLimit';

The same as mapValues but runs a maximum of limit async operations at a +time.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
obj + + +Object + + + + + +

A collection to iterate over.

limit + + +number + + + + + +

The maximum number of async operations at a time.

iteratee + + +function + + + + + +

A function to apply to each value in obj. +The iteratee is passed a callback(err, transformed) which must be called +once it has completed with an error (which can be null) and a +transformed value. Invoked with (value, key, callback).

callback + + +function + + + + + + <optional> + +

A callback which is called when all iteratee +functions have finished, or an error occurs. result is a new object consisting +of each key from obj, with each transformed value on the right-hand side. +Invoked with (err, result).

+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +

(static) mapValuesSeries(obj, iteratee, callbackopt)

+ + + + + +
+
import mapValuesSeries from 'async/mapValuesSeries';

The same as mapValues but runs only a single async operation at a time.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
obj + + +Object + + + + + +

A collection to iterate over.

iteratee + + +function + + + + + +

A function to apply to each value in obj. +The iteratee is passed a callback(err, transformed) which must be called +once it has completed with an error (which can be null) and a +transformed value. Invoked with (value, key, callback).

callback + + +function + + + + + + <optional> + +

A callback which is called when all iteratee +functions have finished, or an error occurs. result is a new object consisting +of each key from obj, with each transformed value on the right-hand side. +Invoked with (err, result).

+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +

(static) reduce(coll, memo, iteratee, callbackopt)

+ + + + + +
+
import reduce from 'async/reduce';

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.

+
+ + + +
+
Alias:
+
  • foldl
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
coll + + +Array +| + +Iterable +| + +Object + + + + + +

A collection to iterate over.

memo + + +* + + + + + +

The initial state of the reduction.

iteratee + + +function + + + + + +

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).

callback + + +function + + + + + + <optional> + +

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
+});
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + +

(static) reduceRight(array, memo, iteratee, callbackopt)

+ + + + + +
+
import reduceRight from 'async/reduceRight';

Same as reduce, only operates on array in reverse order.

+
+ + + +
+
Alias:
+
  • foldr
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
array + + +Array + + + + + +

A collection to iterate over.

memo + + +* + + + + + +

The initial state of the reduction.

iteratee + + +function + + + + + +

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).

callback + + +function + + + + + + <optional> + +

A callback which is called after all the +iteratee functions have finished. Result is the reduced value. Invoked with +(err, result).

+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +

(static) reject(coll, iteratee, callbackopt)

+ + + + + +
+
import reject from 'async/reject';

The opposite of filter. Removes values that pass an async truth test.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
coll + + +Array +| + +Iterable +| + +Object + + + + + +

A collection to iterate over.

iteratee + + +function + + + + + +

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).

callback + + +function + + + + + + <optional> + +

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);
+});
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +

(static) rejectLimit(coll, limit, iteratee, callbackopt)

+ + + + + +
+
import rejectLimit from 'async/rejectLimit';

The same as reject but runs a maximum of limit async operations at a +time.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
coll + + +Array +| + +Iterable +| + +Object + + + + + +

A collection to iterate over.

limit + + +number + + + + + +

The maximum number of async operations at a time.

iteratee + + +function + + + + + +

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).

callback + + +function + + + + + + <optional> + +

A callback which is called after all the +iteratee functions have finished. Invoked with (err, results).

+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +

(static) rejectSeries(coll, iteratee, callbackopt)

+ + + + + +
+
import rejectSeries from 'async/rejectSeries';

The same as reject but runs only a single async operation at a time.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
coll + + +Array +| + +Iterable +| + +Object + + + + + +

A collection to iterate over.

iteratee + + +function + + + + + +

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).

callback + + +function + + + + + + <optional> + +

A callback which is called after all the +iteratee functions have finished. Invoked with (err, results).

+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +

(static) some(coll, iteratee, callbackopt)

+ + + + + +
+
import some from 'async/some';

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.

+
+ + + +
+
Alias:
+
  • any
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
coll + + +Array +| + +Iterable +| + +Object + + + + + +

A collection to iterate over.

iteratee + + +function + + + + + +

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).

callback + + +function + + + + + + <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. 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
+});
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + +

(static) someLimit(coll, limit, iteratee, callbackopt)

+ + + + + +
+
import someLimit from 'async/someLimit';

The same as some but runs a maximum of limit async operations at a time.

+
+ + + +
+
Alias:
+
  • anyLimit
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
coll + + +Array +| + +Iterable +| + +Object + + + + + +

A collection to iterate over.

limit + + +number + + + + + +

The maximum number of async operations at a time.

iteratee + + +function + + + + + +

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).

callback + + +function + + + + + + <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. Invoked with (err, result).

+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +

(static) someSeries(coll, iteratee, callbackopt)

+ + + + + +
+
import someSeries from 'async/someSeries';

The same as some but runs only a single async operation at a time.

+
+ + + +
+
Alias:
+
  • anySeries
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
coll + + +Array +| + +Iterable +| + +Object + + + + + +

A collection to iterate over.

iteratee + + +function + + + + + +

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).

callback + + +function + + + + + + <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. Invoked with (err, result).

+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +

(static) sortBy(coll, iteratee, callback)

+ + + + + +
+
import sortBy from 'async/sortBy';

Sorts a list by the results of running each coll value through an async +iteratee.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
coll + + +Array +| + +Iterable +| + +Object + + + + + +

A collection to iterate over.

iteratee + + +function + + + + + +

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).

callback + + +function + + + + + +

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
+});
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + +

(static) transform(coll, accumulatoropt, iteratee, callbackopt)

+ + + + + +
+
import transform from 'async/transform';

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.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
coll + + +Array +| + +Iterable +| + +Object + + + + + +

A collection to iterate over.

accumulator + + +* + + + + + + <optional> + +

The initial state of the transform. If omitted, +it will default to an empty Object or Array, depending on the type of coll

iteratee + + +function + + + + + +

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).

callback + + +function + + + + + + <optional> + +

A callback which is called after all the +iteratee functions have finished. Result is the transformed accumulator. +Invoked with (err, result).

+ + + + + + +
Examples
+ +
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]
+});
+ +
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}
+})
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + + +
+ +
+ + + + +
+
+ + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/module-ControlFlow.html b/module-ControlFlow.html new file mode 100644 index 000000000..76a17a2ed --- /dev/null +++ b/module-ControlFlow.html @@ -0,0 +1,6627 @@ + + + + + + + ControlFlow - Documentation + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +

Control Flow

+ + + + + + + +
+ +
+ + + + + +
+ +
+
+ + +

A collection of async functions for controlling the flow through a script.

+ + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + +

Methods

+ + + + + + +

(static) applyEach(fns, …argsopt, callbackopt) → {function}

+ + + + + +
+
import applyEach from 'async/applyEach';

Applies the provided arguments to each function in the array, calling +callback after all functions have completed. If you only provide the first +argument, fns, then it will return a function which lets you pass in the +arguments as if it were a single function call. If more arguments are +provided, callback is required while args is still optional.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
fns + + +Array +| + +Iterable +| + +Object + + + + + +

A collection of asynchronous functions +to all call with the same arguments

args + + +* + + + + + + <optional> + +

any number of separate arguments to pass to the +function.

callback + + +function + + + + + + <optional> + +

the final argument should be the callback, +called when all functions have completed processing.

+ + + + +
Returns:
+ + +
+
    +
  • If only the first argument, fns, is provided, it will +return a function which lets you pass in the arguments as if it were a single +function call. The signature is (..args, callback). If invoked with any +arguments, callback is required.
  • +
+
+ + + +
+
+ Type +
+
+ +function + + +
+
+ + + + +
Example
+ +
async.applyEach([enableSearch, updateSchema], 'bucket', callback);
+
+// partial application example:
+async.each(
+    buckets,
+    async.applyEach([enableSearch, updateSchema]),
+    callback
+);
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + +

(static) applyEachSeries(fns, …argsopt, callbackopt) → {function}

+ + + + + +
+
import applyEachSeries from 'async/applyEachSeries';

The same as applyEach but runs only a single async operation at a time.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
fns + + +Array +| + +Iterable +| + +Object + + + + + +

A collection of asynchronous functions to all +call with the same arguments

args + + +* + + + + + + <optional> + +

any number of separate arguments to pass to the +function.

callback + + +function + + + + + + <optional> + +

the final argument should be the callback, +called when all functions have completed processing.

+ + + + +
Returns:
+ + +
+
    +
  • 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.
  • +
+
+ + + +
+
+ Type +
+
+ +function + + +
+
+ + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +

(static) auto(tasks, concurrencyopt, callbackopt)

+ + + + + +
+
import auto from 'async/auto';

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.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDefaultDescription
tasks + + +Object + + + + + + + +

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.
  • +
concurrency + + +number + + + + + + <optional> + + + + Infinity + +

An optional integer for +determining the maximum number of tasks that can be run in parallel. By +default, as many as possible.

callback + + +function + + + + + + <optional> + + + +

An optional callback which is called when all +the tasks have been completed. It receives the err argument if any tasks +pass an error to their callback. Results are always returned; however, if an +error occurs, no further tasks will be performed, and the results object +will only contain partial results. Invoked with (err, results).

+ + + + +
Returns:
+ + +
+

undefined

+
+ + + + + + +
Example
+ +
async.auto({
+    // this function will just be passed a callback
+    readData: async.apply(fs.readFile, 'data.txt', 'utf-8'),
+    showData: ['readData', function(results, cb) {
+        // results.readData is the file's contents
+        // ...
+    }]
+}, callback);
+
+async.auto({
+    get_data: function(callback) {
+        console.log('in get_data');
+        // async code to get some data
+        callback(null, 'data', 'converted to array');
+    },
+    make_folder: function(callback) {
+        console.log('in make_folder');
+        // async code to create a directory to store a file in
+        // this is run at the same time as getting the data
+        callback(null, 'folder');
+    },
+    write_file: ['get_data', 'make_folder', function(results, callback) {
+        console.log('in write_file', JSON.stringify(results));
+        // once there is some data and the directory exists,
+        // write the data to a file in the directory
+        callback(null, 'filename');
+    }],
+    email_link: ['write_file', function(results, callback) {
+        console.log('in email_link', JSON.stringify(results));
+        // once the file is written let's email a link to it...
+        // results.write_file contains the filename returned by write_file.
+        callback(null, {'file':results.write_file, 'email':'user@example.com'});
+    }]
+}, function(err, results) {
+    console.log('err = ', err);
+    console.log('results = ', results);
+});
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + +

(static) autoInject(tasks, callbackopt)

+ + + + + +
+
import autoInject from 'async/autoInject';

A dependency-injected version of the 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 async.auto.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
tasks + + +Object + + + + + +

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.
  • +
callback + + +function + + + + + + <optional> + +

An optional callback which is called when all +the tasks have been completed. It receives the err argument if any tasks +pass an error to their callback, and a results object with any completed +task results, similar to auto.

+ + + + + + +
Example
+ +
//  The example from `auto` can be rewritten as follows:
+async.autoInject({
+    get_data: function(callback) {
+        // async code to get some data
+        callback(null, 'data', 'converted to array');
+    },
+    make_folder: function(callback) {
+        // async code to create a directory to store a file in
+        // this is run at the same time as getting the data
+        callback(null, 'folder');
+    },
+    write_file: function(get_data, make_folder, callback) {
+        // once there is some data and the directory exists,
+        // write the data to a file in the directory
+        callback(null, 'filename');
+    },
+    email_link: function(write_file, callback) {
+        // once the file is written let's email a link to it...
+        // write_file contains the filename returned by write_file.
+        callback(null, {'file':write_file, 'email':'user@example.com'});
+    }
+}, function(err, results) {
+    console.log('err = ', err);
+    console.log('email_link = ', results.email_link);
+});
+
+// If you are using a JS minifier that mangles parameter names, `autoInject`
+// will not work with plain functions, since the parameter names will be
+// collapsed to a single letter identifier.  To work around this, you can
+// explicitly specify the names of the parameters your task function needs
+// in an array, similar to Angular.js dependency injection.
+
+// This still has an advantage over plain `auto`, since the results a task
+// depends on are still spread into arguments.
+async.autoInject({
+    //...
+    write_file: ['get_data', 'make_folder', function(get_data, make_folder, callback) {
+        callback(null, 'filename');
+    }],
+    email_link: ['write_file', function(write_file, callback) {
+        callback(null, {'file':write_file, 'email':'user@example.com'});
+    }]
+    //...
+}, function(err, results) {
+    console.log('err = ', err);
+    console.log('email_link = ', results.email_link);
+});
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +

(static) cargo(worker, payloadopt) → {CargoObject}

+ + + + + +
+
import cargo from 'async/cargo';

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 animations +for how cargo and queue work.

+

While 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.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDefaultDescription
worker + + +function + + + + + + + +

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).

payload + + +number + + + + + + <optional> + + + + Infinity + +

An optional integer for determining +how many tasks should be processed per round; if omitted, the default is +unlimited.

+ + + + +
Returns:
+ + +
+

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.

+
+ + + +
+
+ Type +
+
+ +CargoObject + + +
+
+ + + + +
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');
+});
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +

(static) compose(…functions) → {function}

+ + + + + +
+
import compose from 'async/compose';

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.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
functions + + +function + + + + + +

the asynchronous functions to compose

+ + + + +
Returns:
+ + +
+

an asynchronous function that is the composed +asynchronous functions

+
+ + + +
+
+ Type +
+
+ +function + + +
+
+ + + + +
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
+});
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + +

(static) doDuring(fn, test, callbackopt)

+ + + + + +
+
import doDuring from 'async/doDuring';

The post-check version of during. To reflect the difference in +the order of operations, the arguments test and fn are switched.

+

Also a version of doWhilst with asynchronous test function.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
fn + + +function + + + + + +

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).

test + + +function + + + + + +

asynchronous truth test to perform before each +execution of fn. Invoked with (...args, callback), where ...args are the +non-error args from the previous callback of fn.

callback + + +function + + + + + + <optional> + +

A callback which is called after the test +function has failed and repeated execution of fn has stopped. callback +will be passed an error if one occured, otherwise null.

+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +

(static) doUntil(fn, test, callbackopt)

+ + + + + +
+
import doUntil from 'async/doUntil';

Like 'doWhilst', except the test is inverted. Note the +argument ordering differs from until.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
fn + + +function + + + + + +

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).

test + + +function + + + + + +

synchronous truth test to perform after each +execution of fn. Invoked with the non-error callback results of fn.

callback + + +function + + + + + + <optional> + +

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]);

+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +

(static) doWhilst(iteratee, test, callbackopt)

+ + + + + +
+
import doWhilst from 'async/doWhilst';

The post-check version of whilst. To reflect the difference in +the order of operations, the arguments test and iteratee are switched.

+

doWhilst is to whilst as do while is to while in plain JavaScript.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
iteratee + + +function + + + + + +

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).

test + + +function + + + + + +

synchronous truth test to perform after each +execution of iteratee. Invoked with the non-error callback results of +iteratee.

callback + + +function + + + + + + <optional> + +

A callback which is called after the test +function has failed and repeated execution of iteratee has stopped. +callback will be passed an error and any arguments passed to the final +iteratee's callback. Invoked with (err, [results]);

+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +

(static) during(test, fn, callbackopt)

+ + + + + +
+
import during from 'async/during';

Like 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.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
test + + +function + + + + + +

asynchronous truth test to perform before each +execution of fn. Invoked with (callback).

fn + + +function + + + + + +

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).

callback + + +function + + + + + + <optional> + +

A callback which is called after the test +function has failed and repeated execution of fn has stopped. callback +will be passed an error, if one occured, otherwise null.

+ + + + + + +
Example
+ +
var count = 0;
+
+async.during(
+    function (callback) {
+        return callback(null, count < 5);
+    },
+    function (callback) {
+        count++;
+        setTimeout(callback, 1000);
+    },
+    function (err) {
+        // 5 seconds have passed
+    }
+);
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +

(static) forever(fn, errbackopt)

+ + + + + +
+
import forever from 'async/forever';

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.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
fn + + +function + + + + + +

a function to call repeatedly. Invoked with (next).

errback + + +function + + + + + + <optional> + +

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.
+    }
+);
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + +

(static) parallel(tasks, callbackopt)

+ + + + + +
+
import parallel from 'async/parallel';

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 async.parallel.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
tasks + + +Array +| + +Iterable +| + +Object + + + + + +

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.

callback + + +function + + + + + + <optional> + +

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}
+});
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + +

(static) parallelLimit(tasks, limit, callbackopt)

+ + + + + +
+
import parallelLimit from 'async/parallelLimit';

The same as parallel but runs a maximum of limit async operations at a +time.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
tasks + + +Array +| + +Collection + + + + + +

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.

limit + + +number + + + + + +

The maximum number of async operations at a time.

callback + + +function + + + + + + <optional> + +

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).

+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +

(static) priorityQueue(worker, concurrency) → {QueueObject}

+ + + + + +
+
import priorityQueue from 'async/priorityQueue';

The same as async.queue only tasks are assigned a priority and +completed in ascending priority order.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
worker + + +function + + + + + +

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).

concurrency + + +number + + + + + +

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:
+ + +
+

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.
  • +
+
+ + + +
+
+ Type +
+
+ +QueueObject + + +
+
+ + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +

(static) queue(worker, concurrencyopt) → {QueueObject}

+ + + + + +
+
import queue from 'async/queue';

Creates a queue object with the specified concurrency. Tasks added to the +queue are processed in parallel (up to the concurrency limit). If all +workers are in progress, the task is queued until one becomes available. +Once a worker completes a task, that task's callback is called.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDefaultDescription
worker + + +function + + + + + + + +

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).

concurrency + + +number + + + + + + <optional> + + + + 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:
+ + +
+

A queue object to manage the tasks. Callbacks can +attached as certain properties to listen for specific events during the +lifecycle of the queue.

+
+ + + +
+
+ Type +
+
+ +QueueObject + + +
+
+ + + + +
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');
+});
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + +

(static) race(tasks, callback)

+ + + + + +
+
import race from 'async/race';

Runs the tasks array of functions in parallel, without waiting until the +previous function has completed. Once any of the tasks complete or pass an +error to its callback, the main callback is immediately called. It's +equivalent to Promise.race().

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
tasks + + +Array + + + + + +

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.

callback + + +function + + + + + +

A callback to run once any of the functions have +completed. This function gets an error or result from the first function that +completed. Invoked with (err, result).

+ + + + +
Returns:
+ + +
+

undefined

+
+ + + + + + +
Example
+ +
async.race([
+    function(callback) {
+        setTimeout(function() {
+            callback(null, 'one');
+        }, 200);
+    },
+    function(callback) {
+        setTimeout(function() {
+            callback(null, 'two');
+        }, 100);
+    }
+],
+// main callback
+function(err, result) {
+    // the result will be equal to 'two' as it finishes earlier
+});
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + +

(static) retry(optsopt, task, callbackopt)

+ + + + + +
+
import retry from 'async/retry';

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.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDefaultDescription
opts + + +Object +| + +number + + + + + + <optional> + + + + {times: 5, interval: 0}| 5 + +

Can be either an +object with times and interval or a number.

+
    +
  • times - The number of attempts to make before giving up. The default +is 5.
  • +
  • interval - The time to wait between retries, in milliseconds. The +default is 0. The interval may also be specified as a function of the +retry count (see example).
  • +
  • errorFilter - An optional synchronous function that is invoked on +erroneous result. If it returns true the retry attempts will continue; +if the function returns false the retry flow is aborted with the current +attempt's error and result being returned to the final callback. +Invoked with (err).
  • +
  • If opts is a number, the number specifies the number of times to retry, +with the default interval of 0.
  • +
task + + +function + + + + + + + +

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).

callback + + +function + + + + + + <optional> + + + +

An optional callback which is called when the +task has succeeded, or after the final failed attempt. It receives the err +and result arguments of the last attempt at completing the task. Invoked +with (err, results).

+ + + + + + +
Example
+ +
// The `retry` function can be used as a stand-alone control flow by passing
+// a callback, as shown below:
+
+// try calling apiMethod 3 times
+async.retry(3, apiMethod, function(err, result) {
+    // do something with the result
+});
+
+// try calling apiMethod 3 times, waiting 200 ms between each retry
+async.retry({times: 3, interval: 200}, apiMethod, function(err, result) {
+    // do something with the result
+});
+
+// try calling apiMethod 10 times with exponential backoff
+// (i.e. intervals of 100, 200, 400, 800, 1600, ... milliseconds)
+async.retry({
+  times: 10,
+  interval: function(retryCount) {
+    return 50 * Math.pow(2, retryCount);
+  }
+}, apiMethod, function(err, result) {
+    // do something with the result
+});
+
+// try calling apiMethod the default 5 times no delay between each retry
+async.retry(apiMethod, function(err, result) {
+    // do something with the result
+});
+
+// try calling apiMethod only when error condition satisfies, all other
+// errors will abort the retry control flow and return to final callback
+async.retry({
+  errorFilter: function(err) {
+    return err.message === 'Temporary error'; // only retry on a specific error
+  }
+}, 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
+});
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + +

(static) retryable(optsopt, task) → {Functions}

+ + + + + +
+
import retryable from 'async/retryable';

A close relative of retry. This method wraps a task and makes it +retryable, rather than immediately calling it with retries.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDefaultDescription
opts + + +Object +| + +number + + + + + + <optional> + + + + {times: 5, interval: 0}| 5 + +

optional +options, exactly the same as from retry

task + + +function + + + + + + + +

the asynchronous function to wrap

+ + + + +
Returns:
+ + +
+

The wrapped function, which when invoked, will retry on +an error, based on the parameters specified in opts.

+
+ + + +
+
+ Type +
+
+ +Functions + + +
+
+ + + + +
Example
+ +
async.auto({
+    dep1: async.retryable(3, getFromFlakyService),
+    process: ["dep1", async.retryable(3, function (results, cb) {
+        maybeProcessData(results.dep1, cb);
+    })]
+}, callback);
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +

(static) seq(…functions) → {function}

+ + + + + +
+
import seq from 'async/seq';

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 with the arguments reversed.

+

Each function is executed with the this binding of the composed function.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
functions + + +function + + + + + +

the asynchronous functions to compose

+ + + + +
Returns:
+ + +
+

a function that composes the functions in order

+
+ + + +
+
+ Type +
+
+ +function + + +
+
+ + + + +
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 });
+        }
+    });
+});
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +

(static) series(tasks, callbackopt)

+ + + + + +
+
import series from 'async/series';

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 async.series.

+

Note that while many implementations preserve the order of object +properties, the ECMAScript Language Specification +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.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
tasks + + +Array +| + +Iterable +| + +Object + + + + + +

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.

callback + + +function + + + + + + <optional> + +

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}
+});
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + +

(static) times(n, iteratee, callback)

+ + + + + +
+
import times from 'async/times';

Calls the iteratee function n times, and accumulates results in the same +manner you would use with map.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
n + + +number + + + + + +

The number of times to run the function.

iteratee + + +function + + + + + +

The function to call n times. Invoked with the +iteration index and a callback (n, next).

callback + + +function + + + + + +

see 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
+});
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +

(static) timesLimit(count, limit, iteratee, callback)

+ + + + + +
+
import timesLimit from 'async/timesLimit';

The same as times but runs a maximum of limit async operations at a +time.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
count + + +number + + + + + +

The number of times to run the function.

limit + + +number + + + + + +

The maximum number of async operations at a time.

iteratee + + +function + + + + + +

The function to call n times. Invoked with the +iteration index and a callback (n, next).

callback + + +function + + + + + +

see async.map.

+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +

(static) timesSeries(n, iteratee, callback)

+ + + + + +
+
import timesSeries from 'async/timesSeries';

The same as times but runs only a single async operation at a time.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
n + + +number + + + + + +

The number of times to run the function.

iteratee + + +function + + + + + +

The function to call n times. Invoked with the +iteration index and a callback (n, next).

callback + + +function + + + + + +

see map.

+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +

(static) until(test, fn, callbackopt)

+ + + + + +
+
import until from 'async/until';

Repeatedly call fn until test returns true. Calls callback when +stopped, or an error occurs. callback will be passed an error and any +arguments passed to the final fn's callback.

+

The inverse of whilst.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
test + + +function + + + + + +

synchronous truth test to perform before each +execution of fn. Invoked with ().

fn + + +function + + + + + +

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).

callback + + +function + + + + + + <optional> + +

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]);

+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +

(static) waterfall(tasks, callbackopt)

+ + + + + +
+
import waterfall from 'async/waterfall';

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.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
tasks + + +Array + + + + + +

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.

callback + + +function + + + + + + <optional> + +

An optional callback to run once all the +functions have completed. This will be passed the results of the last task's +callback. Invoked with (err, [results]).

+ + + + +
Returns:
+ + +
+

undefined

+
+ + + + + + +
Example
+ +
async.waterfall([
+    function(callback) {
+        callback(null, 'one', 'two');
+    },
+    function(arg1, arg2, callback) {
+        // arg1 now equals 'one' and arg2 now equals 'two'
+        callback(null, 'three');
+    },
+    function(arg1, callback) {
+        // arg1 now equals 'three'
+        callback(null, 'done');
+    }
+], function (err, result) {
+    // result now equals 'done'
+});
+
+// Or, with named functions:
+async.waterfall([
+    myFirstFunction,
+    mySecondFunction,
+    myLastFunction,
+], function (err, result) {
+    // result now equals 'done'
+});
+function myFirstFunction(callback) {
+    callback(null, 'one', 'two');
+}
+function mySecondFunction(arg1, arg2, callback) {
+    // arg1 now equals 'one' and arg2 now equals 'two'
+    callback(null, 'three');
+}
+function myLastFunction(arg1, callback) {
+    // arg1 now equals 'three'
+    callback(null, 'done');
+}
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + +

(static) whilst(test, iteratee, callbackopt)

+ + + + + +
+
import whilst from 'async/whilst';

Repeatedly call iteratee, while test returns true. Calls callback when +stopped, or an error occurs.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
test + + +function + + + + + +

synchronous truth test to perform before each +execution of iteratee. Invoked with ().

iteratee + + +function + + + + + +

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).

callback + + +function + + + + + + <optional> + +

A callback which is called after the test +function has failed and repeated execution of iteratee has stopped. callback +will be passed an error and any arguments passed to the final iteratee's +callback. Invoked with (err, [results]);

+ + + + +
Returns:
+ + +
+

undefined

+
+ + + + + + +
Example
+ +
var count = 0;
+async.whilst(
+    function() { return count < 5; },
+    function(callback) {
+        count++;
+        setTimeout(function() {
+            callback(null, count);
+        }, 1000);
+    },
+    function (err, n) {
+        // 5 seconds have passed, n = 5
+    }
+);
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + +

Type Definitions

+ + + +

CargoObject

+ + + + +
+
import cargo from 'async/cargo';

A cargo of tasks for the worker function to complete. Cargo inherits all of +the same methods and event callbacks as queue.

+
+ + + +
Type:
+
    +
  • + +Object + + +
  • +
+ + + + + +
Properties:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
length + + +function + + + +

A function returning the number of items +waiting to be processed. Invoke like cargo.length().

payload + + +number + + + +

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.

push + + +function + + + +

Adds task to the queue. The callback is +called once the worker has finished processing the task. Instead of a +single task, an array of tasks can be submitted. The respective callback is +used for every task in the list. Invoke like cargo.push(task, [callback]).

saturated + + +function + + + +

A callback that is called when the +queue.length() hits the concurrency and further tasks will be queued.

empty + + +function + + + +

A callback that is called when the last item +from the queue is given to a worker.

drain + + +function + + + +

A callback that is called when the last item +from the queue has returned from the worker.

idle + + +function + + + +

a function returning false if there are items +waiting or being processed, or true if not. Invoke like cargo.idle().

pause + + +function + + + +

a function that pauses the processing of tasks +until resume() is called. Invoke like cargo.pause().

resume + + +function + + + +

a function that resumes the processing of +queued tasks when the queue is paused. Invoke like cargo.resume().

kill + + +function + + + +

a function that removes the drain callback and +empties remaining tasks from the queue forcing it to go idle. Invoke like cargo.kill().

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + +

QueueObject

+ + + + +
+
import queue from 'async/queue';

A queue of tasks for the worker function to complete.

+
+ + + +
Type:
+
    +
  • + +Object + + +
  • +
+ + + + + +
Properties:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
length + + +function + + + +

a function returning the number of items +waiting to be processed. Invoke with queue.length().

started + + +boolean + + + +

a boolean indicating whether or not any +items have been pushed and processed by the queue.

running + + +function + + + +

a function returning the number of items +currently being processed. Invoke with queue.running().

workersList + + +function + + + +

a function returning the array of items +currently being processed. Invoke with queue.workersList().

idle + + +function + + + +

a function returning false if there are items +waiting or being processed, or true if not. Invoke with queue.idle().

concurrency + + +number + + + +

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.

push + + +function + + + +

add a new task to the queue. Calls callback +once the worker has finished processing the task. Instead of a single task, +a tasks array can be submitted. The respective callback is used for every +task in the list. Invoke with queue.push(task, [callback]),

unshift + + +function + + + +

add a new task to the front of the queue. +Invoke with queue.unshift(task, [callback]).

saturated + + +function + + + +

a callback that is called when the number of +running workers hits the concurrency limit, and further tasks will be +queued.

unsaturated + + +function + + + +

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.

buffer + + +number + + + +

A minimum threshold buffer in order to say that +the queue is unsaturated.

empty + + +function + + + +

a callback that is called when the last item +from the queue is given to a worker.

drain + + +function + + + +

a callback that is called when the last item +from the queue has returned from the worker.

error + + +function + + + +

a callback that is called when a task errors. +Has the signature function(error, task).

paused + + +boolean + + + +

a boolean for determining whether the queue is +in a paused state.

pause + + +function + + + +

a function that pauses the processing of tasks +until resume() is called. Invoke with queue.pause().

resume + + +function + + + +

a function that resumes the processing of +queued tasks when the queue is paused. Invoke with queue.resume().

kill + + +function + + + +

a function that removes the drain callback and +empties remaining tasks from the queue forcing it to go idle. Invoke with queue.kill().

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + +
+ +
+ + + + +
+
+ + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/module-Utils.html b/module-Utils.html new file mode 100644 index 000000000..8ae3002da --- /dev/null +++ b/module-Utils.html @@ -0,0 +1,2684 @@ + + + + + + + Utils - Documentation + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +

Utils

+ + + + + + + +
+ +
+ + + + + +
+ +
+
+ + +

A collection of async utility functions.

+ + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + +

Methods

+ + + + + + +

(static) apply(function)

+ + + + + +
+
import apply from 'async/apply';

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.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
function + + +function + + + + + +

The function you want to eventually apply all +arguments to. Invokes with (arguments...).

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
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + +

(static) asyncify(func) → {function}

+ + + + + +
+
import asyncify from 'async/asyncify';

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.

+
+ + + +
+
Alias:
+
  • wrapSync
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
func + + +function + + + + + +

The synchronous function to convert to an +asynchronous function.

+ + + + +
Returns:
+ + +
+

An asynchronous wrapper of the func. To be invoked with +(callback).

+
+ + + +
+
+ Type +
+
+ +function + + +
+
+ + + + +
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);
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + +

(static) constant() → {function}

+ + + + + +
+
import constant from 'async/constant';

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.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
arguments... + + +* + + + + + +

Any number of arguments to automatically invoke +callback with.

+ + + + +
Returns:
+ + +
+

Returns a function that when invoked, automatically +invokes the callback with the previous given arguments.

+
+ + + +
+
+ Type +
+
+ +function + + +
+
+ + + + +
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);
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + +

(static) dir(function)

+ + + + + +
+
import dir from 'async/dir';

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.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
function + + +function + + + + + +

The function you want to eventually apply all +arguments to.

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'}
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + +

(static) ensureAsync(fn) → {function}

+ + + + + +
+
import ensureAsync from 'async/ensureAsync';

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 +contained.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
fn + + +function + + + + + +

an async function, one that expects a node-style +callback as its last argument.

+ + + + +
Returns:
+ + +
+

Returns a wrapped function with the exact same call +signature as the function passed in.

+
+ + + +
+
+ Type +
+
+ +function + + +
+
+ + + + +
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);
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + +

(static) log(function)

+ + + + + +
+
import log from 'async/log';

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.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
function + + +function + + + + + +

The function you want to eventually apply all +arguments to.

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'
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + +

(static) memoize(fn, hasher) → {function}

+ + + + + +
+
import memoize from 'async/memoize';

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.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
fn + + +function + + + + + +

The function to proxy and cache results from.

hasher + + +function + + + + + +

An optional function for generating a custom hash +for storing results. It has all the arguments applied to it apart from the +callback, and must be synchronous.

+ + + + +
Returns:
+ + +
+

a memoized version of fn

+
+ + + +
+
+ Type +
+
+ +function + + +
+
+ + + + +
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
+});
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + +

(static) nextTick(callback)

+ + + + + +
+
import nextTick from 'async/nextTick';

Calls callback on a later loop around the event loop. In Node.js this just +calls setImmediate. In the browser it will use setImmediate if +available, otherwise setTimeout(callback, 0), which means other higher +priority events may precede the execution of callback.

+

This is used internally for browser-compatibility purposes.

+
+ + + +
+
Alias:
+
  • setImmediate
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
callback + + +function + + + + + +

The function to call on a later loop around +the event loop. Invoked with (args...).

args... + + +* + + + + + +

any number of additional arguments to pass to the +callback on the next tick.

+ + + + + + +
Example
+ +
var call_order = [];
+async.nextTick(function() {
+    call_order.push('two');
+    // call_order now equals ['one','two']
+});
+call_order.push('one');
+
+async.setImmediate(function (a, b, c) {
+    // a, b, and c equal 1, 2, and 3
+}, 1, 2, 3);
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + +

(static) reflect(fn) → {function}

+ + + + + +
+
import reflect from 'async/reflect';

Wraps the function in another function that always returns data even when it +errors.

+

The object returned has either the property error or value.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
fn + + +function + + + + + +

The function you want to wrap

+ + + + +
Returns:
+ + +
+
    +
  • 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.
  • +
+
+ + + +
+
+ Type +
+
+ +function + + +
+
+ + + + +
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'
+});
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + +

(static) reflectAll(tasks) → {Array}

+ + + + + +
+
import reflectAll from 'async/reflectAll';

A helper function that wraps an array or an object of functions with reflect.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
tasks + + +Array + + + + + +

The array of functions to wrap in async.reflect.

+ + + + +
Returns:
+ + +
+

Returns an array of functions, each function wrapped in +async.reflect

+
+ + + +
+
+ Type +
+
+ +Array + + +
+
+ + + + +
Example
+ +
let tasks = [
+    function(callback) {
+        setTimeout(function() {
+            callback(null, 'one');
+        }, 200);
+    },
+    function(callback) {
+        // do some more stuff but error ...
+        callback(new Error('bad stuff happened'));
+    },
+    function(callback) {
+        setTimeout(function() {
+            callback(null, 'two');
+        }, 100);
+    }
+];
+
+async.parallel(async.reflectAll(tasks),
+// optional callback
+function(err, results) {
+    // values
+    // results[0].value = 'one'
+    // results[1].error = Error('bad stuff happened')
+    // results[2].value = 'two'
+});
+
+// an example using an object instead of an array
+let tasks = {
+    one: function(callback) {
+        setTimeout(function() {
+            callback(null, 'one');
+        }, 200);
+    },
+    two: function(callback) {
+        callback('two');
+    },
+    three: function(callback) {
+        setTimeout(function() {
+            callback(null, 'three');
+        }, 100);
+    }
+};
+
+async.parallel(async.reflectAll(tasks),
+// optional callback
+function(err, results) {
+    // values
+    // results.one.value = 'one'
+    // results.two.error = 'two'
+    // results.three.value = 'three'
+});
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +

(static) setImmediate(callback)

+ + + + + +
+
import setImmediate from 'async/setImmediate';

Calls callback on a later loop around the event loop. In Node.js this just +calls setImmediate. In the browser it will use setImmediate if +available, otherwise setTimeout(callback, 0), which means other higher +priority events may precede the execution of callback.

+

This is used internally for browser-compatibility purposes.

+
+ + + +
+
Alias:
+
  • nextTick
+
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
callback + + +function + + + + + +

The function to call on a later loop around +the event loop. Invoked with (args...).

args... + + +* + + + + + +

any number of additional arguments to pass to the +callback on the next tick.

+ + + + + + +
Example
+ +
var call_order = [];
+async.nextTick(function() {
+    call_order.push('two');
+    // call_order now equals ['one','two']
+});
+call_order.push('one');
+
+async.setImmediate(function (a, b, c) {
+    // a, b, and c equal 1, 2, and 3
+}, 1, 2, 3);
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + +

(static) timeout(asyncFn, milliseconds, infoopt) → {function}

+ + + + + +
+
import timeout from 'async/timeout';

Sets a time limit on an asynchronous function. If the function does not call +its callback within the specified milliseconds, it will be called with a +timeout error. The code property for the error object will be 'ETIMEDOUT'.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
asyncFn + + +function + + + + + +

The asynchronous function you want to set the +time limit.

milliseconds + + +number + + + + + +

The specified time limit.

info + + +* + + + + + + <optional> + +

Any variable you want attached (string, object, etc) +to timeout Error for more information..

+ + + + +
Returns:
+ + +
+

Returns a wrapped function that can be used with any of +the control flow functions. Invoke this function with the same +parameters as you would asyncFunc.

+
+ + + +
+
+ Type +
+
+ +function + + +
+
+ + + + +
Example
+ +
function myFunction(foo, callback) {
+    doAsyncTask(foo, function(err, data) {
+        // handle errors
+        if (err) return callback(err);
+
+        // do some stuff ...
+
+        // return processed data
+        return callback(null, data);
+    });
+}
+
+var wrapped = async.timeout(myFunction, 1000);
+
+// call `wrapped` as you would `myFunction`
+wrapped({ bar: 'bar' }, function(err, data) {
+    // if `myFunction` takes < 1000 ms to execute, `err`
+    // and `data` will have their expected values
+
+    // else `err` will be an Error with the code 'ETIMEDOUT'
+});
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + +

(static) unmemoize(fn) → {function}

+ + + + + +
+
import unmemoize from 'async/unmemoize';

Undoes a memoized function, reverting it to the original, +unmemoized form. Handy for testing.

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
fn + + +function + + + + + +

the memoized function

+ + + + +
Returns:
+ + +
+

a function that calls the original unmemoized function

+
+ + + +
+
+ Type +
+
+ +function + + +
+
+ + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + + + + + + + + +
+ +
+ + + + +
+
+ + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/module-async.html b/module-async.html new file mode 100644 index 000000000..983597239 --- /dev/null +++ b/module-async.html @@ -0,0 +1,220 @@ + + + + + + + async - Documentation + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +

async

+ + + + + + + +
+ +
+ + + + + +
+ +
+
+ + +

Async is a utility module which provides straight-forward, powerful functions +for working with asynchronous JavaScript. Although originally designed for +use with Node.js and installable via +npm install --save async, it can also be used directly in the browser.

+ + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + +
+ +
+ + + + +
+
+ + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/nextTick.js.html b/nextTick.js.html new file mode 100644 index 000000000..ac68b2f8f --- /dev/null +++ b/nextTick.js.html @@ -0,0 +1,153 @@ + + + + + + + nextTick.js - Documentation + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +

nextTick.js

+ + + + + + + +
+
+
'use strict';
+
+import { hasNextTick, hasSetImmediate, fallback, wrap }  from './internal/setImmediate';
+
+/**
+ * Calls `callback` on a later loop around the event loop. In Node.js this just
+ * calls `setImmediate`.  In the browser it will use `setImmediate` if
+ * available, otherwise `setTimeout(callback, 0)`, which means other higher
+ * priority events may precede the execution of `callback`.
+ *
+ * This is used internally for browser-compatibility purposes.
+ *
+ * @name nextTick
+ * @static
+ * @memberOf module:Utils
+ * @method
+ * @alias setImmediate
+ * @category Util
+ * @param {Function} callback - The function to call on a later loop around
+ * the event loop. Invoked with (args...).
+ * @param {...*} args... - any number of additional arguments to pass to the
+ * callback on the next tick.
+ * @example
+ *
+ * var call_order = [];
+ * async.nextTick(function() {
+ *     call_order.push('two');
+ *     // call_order now equals ['one','two']
+ * });
+ * call_order.push('one');
+ *
+ * async.setImmediate(function (a, b, c) {
+ *     // a, b, and c equal 1, 2, and 3
+ * }, 1, 2, 3);
+ */
+var _defer;
+
+if (hasNextTick) {
+    _defer = process.nextTick;
+} else if (hasSetImmediate) {
+    _defer = setImmediate;
+} else {
+    _defer = fallback;
+}
+
+export default wrap(_defer);
+
+
+
+ + + + +
+
+ + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/parallel.js.html b/parallel.js.html new file mode 100644 index 000000000..03f05da5d --- /dev/null +++ b/parallel.js.html @@ -0,0 +1,179 @@ + + + + + + + parallel.js - Documentation + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +

parallel.js

+ + + + + + + +
+
+
import eachOf from './eachOf';
+import parallel from './internal/parallel';
+
+/**
+ * Run the `tasks` collection of functions in parallel, without waiting until
+ * the previous function has completed. If any of the functions pass an error to
+ * its callback, the main `callback` is immediately called with the value of the
+ * error. Once the `tasks` have completed, the results are passed to the final
+ * `callback` as an array.
+ *
+ * **Note:** `parallel` is about kicking-off I/O tasks in parallel, not about
+ * parallel execution of code.  If your tasks do not use any timers or perform
+ * any I/O, they will actually be executed in series.  Any synchronous setup
+ * sections for each task will happen one after the other.  JavaScript remains
+ * single-threaded.
+ *
+ * It is also possible to use an object instead of an array. Each property will
+ * be run as a function and the results will be passed to the final `callback`
+ * as an object instead of an array. This can be a more readable way of handling
+ * results from {@link async.parallel}.
+ *
+ * @name parallel
+ * @static
+ * @memberOf module:ControlFlow
+ * @method
+ * @category Control Flow
+ * @param {Array|Iterable|Object} tasks - A collection containing functions to run.
+ * Each function is passed a `callback(err, result)` which it must call on
+ * completion with an error `err` (which can be `null`) and an optional `result`
+ * value.
+ * @param {Function} [callback] - An optional callback to run once all the
+ * functions have completed successfully. This function gets a results array
+ * (or object) containing all the result arguments passed to the task callbacks.
+ * Invoked with (err, results).
+ * @example
+ * async.parallel([
+ *     function(callback) {
+ *         setTimeout(function() {
+ *             callback(null, 'one');
+ *         }, 200);
+ *     },
+ *     function(callback) {
+ *         setTimeout(function() {
+ *             callback(null, 'two');
+ *         }, 100);
+ *     }
+ * ],
+ * // optional callback
+ * function(err, results) {
+ *     // the results array will equal ['one','two'] even though
+ *     // the second function had a shorter timeout.
+ * });
+ *
+ * // an example using an object instead of an array
+ * async.parallel({
+ *     one: function(callback) {
+ *         setTimeout(function() {
+ *             callback(null, 1);
+ *         }, 200);
+ *     },
+ *     two: function(callback) {
+ *         setTimeout(function() {
+ *             callback(null, 2);
+ *         }, 100);
+ *     }
+ * }, function(err, results) {
+ *     // results is now equals to: {one: 1, two: 2}
+ * });
+ */
+export default function parallelLimit(tasks, callback) {
+    parallel(eachOf, tasks, callback);
+}
+
+
+
+ + + + +
+
+ + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/parallelLimit.js.html b/parallelLimit.js.html new file mode 100644 index 000000000..d20adcf9a --- /dev/null +++ b/parallelLimit.js.html @@ -0,0 +1,133 @@ + + + + + + + parallelLimit.js - Documentation + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +

parallelLimit.js

+ + + + + + + +
+
+
import eachOfLimit from './internal/eachOfLimit';
+import parallel from './internal/parallel';
+
+/**
+ * The same as [`parallel`]{@link module:ControlFlow.parallel} but runs a maximum of `limit` async operations at a
+ * time.
+ *
+ * @name parallelLimit
+ * @static
+ * @memberOf module:ControlFlow
+ * @method
+ * @see [async.parallel]{@link module:ControlFlow.parallel}
+ * @category Control Flow
+ * @param {Array|Collection} tasks - A collection containing functions to run.
+ * Each function is passed a `callback(err, result)` which it must call on
+ * completion with an error `err` (which can be `null`) and an optional `result`
+ * value.
+ * @param {number} limit - The maximum number of async operations at a time.
+ * @param {Function} [callback] - An optional callback to run once all the
+ * functions have completed successfully. This function gets a results array
+ * (or object) containing all the result arguments passed to the task callbacks.
+ * Invoked with (err, results).
+ */
+export default function parallelLimit(tasks, limit, callback) {
+    parallel(eachOfLimit(limit), tasks, callback);
+}
+
+
+
+ + + + +
+
+ + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/priorityQueue.js.html b/priorityQueue.js.html new file mode 100644 index 000000000..1987844e9 --- /dev/null +++ b/priorityQueue.js.html @@ -0,0 +1,186 @@ + + + + + + + priorityQueue.js - Documentation + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +

priorityQueue.js

+ + + + + + + +
+
+
import isArray from 'lodash/isArray';
+import noop from 'lodash/noop';
+
+import setImmediate from './setImmediate';
+
+import queue from './queue';
+
+/**
+ * The same as [async.queue]{@link module:ControlFlow.queue} only tasks are assigned a priority and
+ * completed in ascending priority order.
+ *
+ * @name priorityQueue
+ * @static
+ * @memberOf module:ControlFlow
+ * @method
+ * @see [async.queue]{@link module:ControlFlow.queue}
+ * @category Control Flow
+ * @param {Function} worker - An asynchronous function for processing a queued
+ * task, which must call its `callback(err)` argument when finished, with an
+ * optional `error` as an argument.  If you want to handle errors from an
+ * individual task, pass a callback to `q.push()`. Invoked with
+ * (task, callback).
+ * @param {number} concurrency - An `integer` for determining how many `worker`
+ * functions should be run in parallel.  If omitted, the concurrency defaults to
+ * `1`.  If the concurrency is `0`, an error is thrown.
+ * @returns {module:ControlFlow.QueueObject} A priorityQueue object to manage the tasks. There are two
+ * differences between `queue` and `priorityQueue` objects:
+ * * `push(task, priority, [callback])` - `priority` should be a number. If an
+ *   array of `tasks` is given, all tasks will be assigned the same priority.
+ * * The `unshift` method was removed.
+ */
+export default function(worker, concurrency) {
+    // Start with a normal queue
+    var q = queue(worker, concurrency);
+
+    // Override push to accept second parameter representing priority
+    q.push = function(data, priority, callback) {
+        if (callback == null) callback = noop;
+        if (typeof callback !== 'function') {
+            throw new Error('task callback must be a function');
+        }
+        q.started = true;
+        if (!isArray(data)) {
+            data = [data];
+        }
+        if (data.length === 0) {
+            // call drain immediately if there are no tasks
+            return setImmediate(function() {
+                q.drain();
+            });
+        }
+
+        priority = priority || 0;
+        var nextNode = q._tasks.head;
+        while (nextNode && priority >= nextNode.priority) {
+            nextNode = nextNode.next;
+        }
+
+        for (var i = 0, l = data.length; i < l; i++) {
+            var item = {
+                data: data[i],
+                priority: priority,
+                callback: callback
+            };
+
+            if (nextNode) {
+                q._tasks.insertBefore(nextNode, item);
+            } else {
+                q._tasks.push(item);
+            }
+        }
+        setImmediate(q.process);
+    };
+
+    // Remove unshift function
+    delete q.unshift;
+
+    return q;
+}
+
+
+
+ + + + +
+
+ + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/queue.js.html b/queue.js.html new file mode 100644 index 000000000..f826d10fb --- /dev/null +++ b/queue.js.html @@ -0,0 +1,214 @@ + + + + + + + queue.js - Documentation + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +

queue.js

+ + + + + + + +
+
+
import queue from './internal/queue';
+
+/**
+ * A queue of tasks for the worker function to complete.
+ * @typedef {Object} QueueObject
+ * @memberOf module:ControlFlow
+ * @property {Function} length - a function returning the number of items
+ * waiting to be processed. Invoke with `queue.length()`.
+ * @property {boolean} started - a boolean indicating whether or not any
+ * items have been pushed and processed by the queue.
+ * @property {Function} running - a function returning the number of items
+ * currently being processed. Invoke with `queue.running()`.
+ * @property {Function} workersList - a function returning the array of items
+ * currently being processed. Invoke with `queue.workersList()`.
+ * @property {Function} idle - a function returning false if there are items
+ * waiting or being processed, or true if not. Invoke with `queue.idle()`.
+ * @property {number} concurrency - an integer for determining how many `worker`
+ * functions should be run in parallel. This property can be changed after a
+ * `queue` is created to alter the concurrency on-the-fly.
+ * @property {Function} push - add a new task to the `queue`. Calls `callback`
+ * once the `worker` has finished processing the task. Instead of a single task,
+ * a `tasks` array can be submitted. The respective callback is used for every
+ * task in the list. Invoke with `queue.push(task, [callback])`,
+ * @property {Function} unshift - add a new task to the front of the `queue`.
+ * Invoke with `queue.unshift(task, [callback])`.
+ * @property {Function} saturated - a callback that is called when the number of
+ * running workers hits the `concurrency` limit, and further tasks will be
+ * queued.
+ * @property {Function} unsaturated - a callback that is called when the number
+ * of running workers is less than the `concurrency` & `buffer` limits, and
+ * further tasks will not be queued.
+ * @property {number} buffer - A minimum threshold buffer in order to say that
+ * the `queue` is `unsaturated`.
+ * @property {Function} empty - a callback that is called when the last item
+ * from the `queue` is given to a `worker`.
+ * @property {Function} drain - a callback that is called when the last item
+ * from the `queue` has returned from the `worker`.
+ * @property {Function} error - a callback that is called when a task errors.
+ * Has the signature `function(error, task)`.
+ * @property {boolean} paused - a boolean for determining whether the queue is
+ * in a paused state.
+ * @property {Function} pause - a function that pauses the processing of tasks
+ * until `resume()` is called. Invoke with `queue.pause()`.
+ * @property {Function} resume - a function that resumes the processing of
+ * queued tasks when the queue is paused. Invoke with `queue.resume()`.
+ * @property {Function} kill - a function that removes the `drain` callback and
+ * empties remaining tasks from the queue forcing it to go idle. Invoke with `queue.kill()`.
+ */
+
+/**
+ * Creates a `queue` object with the specified `concurrency`. Tasks added to the
+ * `queue` are processed in parallel (up to the `concurrency` limit). If all
+ * `worker`s are in progress, the task is queued until one becomes available.
+ * Once a `worker` completes a `task`, that `task`'s callback is called.
+ *
+ * @name queue
+ * @static
+ * @memberOf module:ControlFlow
+ * @method
+ * @category Control Flow
+ * @param {Function} worker - An asynchronous function for processing a queued
+ * task, which must call its `callback(err)` argument when finished, with an
+ * optional `error` as an argument.  If you want to handle errors from an
+ * individual task, pass a callback to `q.push()`. Invoked with
+ * (task, callback).
+ * @param {number} [concurrency=1] - An `integer` for determining how many
+ * `worker` functions should be run in parallel.  If omitted, the concurrency
+ * defaults to `1`.  If the concurrency is `0`, an error is thrown.
+ * @returns {module:ControlFlow.QueueObject} A queue object to manage the tasks. Callbacks can
+ * attached as certain properties to listen for specific events during the
+ * lifecycle of the queue.
+ * @example
+ *
+ * // create a queue object with concurrency 2
+ * var q = async.queue(function(task, callback) {
+ *     console.log('hello ' + task.name);
+ *     callback();
+ * }, 2);
+ *
+ * // assign a callback
+ * q.drain = function() {
+ *     console.log('all items have been processed');
+ * };
+ *
+ * // add some items to the queue
+ * q.push({name: 'foo'}, function(err) {
+ *     console.log('finished processing foo');
+ * });
+ * q.push({name: 'bar'}, function (err) {
+ *     console.log('finished processing bar');
+ * });
+ *
+ * // add some items to the queue (batch-wise)
+ * q.push([{name: 'baz'},{name: 'bay'},{name: 'bax'}], function(err) {
+ *     console.log('finished processing item');
+ * });
+ *
+ * // add some items to the front of the queue
+ * q.unshift({name: 'bar'}, function (err) {
+ *     console.log('finished processing bar');
+ * });
+ */
+export default function (worker, concurrency) {
+    return queue(function (items, cb) {
+        worker(items[0], cb);
+    }, concurrency, 1);
+}
+
+
+
+ + + + +
+
+ + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/race.js.html b/race.js.html new file mode 100644 index 000000000..a4212f4d3 --- /dev/null +++ b/race.js.html @@ -0,0 +1,156 @@ + + + + + + + race.js - Documentation + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +

race.js

+ + + + + + + +
+
+
import isArray from 'lodash/isArray';
+import noop from 'lodash/noop';
+import once from './internal/once';
+
+/**
+ * Runs the `tasks` array of functions in parallel, without waiting until the
+ * previous function has completed. Once any of the `tasks` complete or pass an
+ * error to its callback, the main `callback` is immediately called. It's
+ * equivalent to `Promise.race()`.
+ *
+ * @name race
+ * @static
+ * @memberOf module:ControlFlow
+ * @method
+ * @category Control Flow
+ * @param {Array} tasks - An array containing functions to run. Each function
+ * is passed a `callback(err, result)` which it must call on completion with an
+ * error `err` (which can be `null`) and an optional `result` value.
+ * @param {Function} callback - A callback to run once any of the functions have
+ * completed. This function gets an error or result from the first function that
+ * completed. Invoked with (err, result).
+ * @returns undefined
+ * @example
+ *
+ * async.race([
+ *     function(callback) {
+ *         setTimeout(function() {
+ *             callback(null, 'one');
+ *         }, 200);
+ *     },
+ *     function(callback) {
+ *         setTimeout(function() {
+ *             callback(null, 'two');
+ *         }, 100);
+ *     }
+ * ],
+ * // main callback
+ * function(err, result) {
+ *     // the result will be equal to 'two' as it finishes earlier
+ * });
+ */
+export default function race(tasks, callback) {
+    callback = once(callback || noop);
+    if (!isArray(tasks)) return callback(new TypeError('First argument to race must be an array of functions'));
+    if (!tasks.length) return callback();
+    for (var i = 0, l = tasks.length; i < l; i++) {
+        tasks[i](callback);
+    }
+}
+
+
+
+ + + + +
+
+ + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/reduce.js.html b/reduce.js.html new file mode 100644 index 000000000..0b5cb017e --- /dev/null +++ b/reduce.js.html @@ -0,0 +1,162 @@ + + + + + + + reduce.js - Documentation + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +

reduce.js

+ + + + + + + +
+
+
import eachOfSeries from './eachOfSeries';
+import noop from 'lodash/noop';
+import once from './internal/once';
+
+/**
+ * Reduces `coll` into a single value using an async `iteratee` to return each
+ * successive step. `memo` is the initial state of the reduction. This function
+ * only operates in series.
+ *
+ * For performance reasons, it may make sense to split a call to this function
+ * into a parallel map, and then use the normal `Array.prototype.reduce` on the
+ * results. This function is for situations where each step in the reduction
+ * needs to be async; if you can get the data before reducing it, then it's
+ * probably a good idea to do so.
+ *
+ * @name reduce
+ * @static
+ * @memberOf module:Collections
+ * @method
+ * @alias inject
+ * @alias foldl
+ * @category Collection
+ * @param {Array|Iterable|Object} coll - A collection to iterate over.
+ * @param {*} memo - The initial state of the reduction.
+ * @param {Function} iteratee - A function applied to each item in the
+ * array to produce the next step in the reduction. The `iteratee` is passed a
+ * `callback(err, reduction)` which accepts an optional error as its first
+ * argument, and the state of the reduction as the second. If an error is
+ * passed to the callback, the reduction is stopped and the main `callback` is
+ * immediately called with the error. Invoked with (memo, item, callback).
+ * @param {Function} [callback] - A callback which is called after all the
+ * `iteratee` functions have finished. Result is the reduced value. Invoked with
+ * (err, result).
+ * @example
+ *
+ * async.reduce([1,2,3], 0, function(memo, item, callback) {
+ *     // pointless async:
+ *     process.nextTick(function() {
+ *         callback(null, memo + item)
+ *     });
+ * }, function(err, result) {
+ *     // result is now equal to the last value of memo, which is 6
+ * });
+ */
+export default function reduce(coll, memo, iteratee, callback) {
+    callback = once(callback || noop);
+    eachOfSeries(coll, function(x, i, callback) {
+        iteratee(memo, x, function(err, v) {
+            memo = v;
+            callback(err);
+        });
+    }, function(err) {
+        callback(err, memo);
+    });
+}
+
+
+
+ + + + +
+
+ + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/reduceRight.js.html b/reduceRight.js.html new file mode 100644 index 000000000..15b9ab05d --- /dev/null +++ b/reduceRight.js.html @@ -0,0 +1,137 @@ + + + + + + + reduceRight.js - Documentation + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +

reduceRight.js

+ + + + + + + +
+
+
import reduce from './reduce';
+
+var slice = Array.prototype.slice;
+
+/**
+ * Same as [`reduce`]{@link module:Collections.reduce}, only operates on `array` in reverse order.
+ *
+ * @name reduceRight
+ * @static
+ * @memberOf module:Collections
+ * @method
+ * @see [async.reduce]{@link module:Collections.reduce}
+ * @alias foldr
+ * @category Collection
+ * @param {Array} array - A collection to iterate over.
+ * @param {*} memo - The initial state of the reduction.
+ * @param {Function} iteratee - A function applied to each item in the
+ * array to produce the next step in the reduction. The `iteratee` is passed a
+ * `callback(err, reduction)` which accepts an optional error as its first
+ * argument, and the state of the reduction as the second. If an error is
+ * passed to the callback, the reduction is stopped and the main `callback` is
+ * immediately called with the error. Invoked with (memo, item, callback).
+ * @param {Function} [callback] - A callback which is called after all the
+ * `iteratee` functions have finished. Result is the reduced value. Invoked with
+ * (err, result).
+ */
+export default function reduceRight (array, memo, iteratee, callback) {
+    var reversed = slice.call(array).reverse();
+    reduce(reversed, memo, iteratee, callback);
+}
+
+
+
+ + + + +
+
+ + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/reflect.js.html b/reflect.js.html new file mode 100644 index 000000000..ffd21d4c4 --- /dev/null +++ b/reflect.js.html @@ -0,0 +1,172 @@ + + + + + + + reflect.js - Documentation + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +

reflect.js

+ + + + + + + +
+
+
import initialParams from './internal/initialParams';
+import rest from './internal/rest';
+
+/**
+ * Wraps the function in another function that always returns data even when it
+ * errors.
+ *
+ * The object returned has either the property `error` or `value`.
+ *
+ * @name reflect
+ * @static
+ * @memberOf module:Utils
+ * @method
+ * @category Util
+ * @param {Function} fn - The function you want to wrap
+ * @returns {Function} - A function that always passes null to it's callback as
+ * the error. The second argument to the callback will be an `object` with
+ * either an `error` or a `value` property.
+ * @example
+ *
+ * async.parallel([
+ *     async.reflect(function(callback) {
+ *         // do some stuff ...
+ *         callback(null, 'one');
+ *     }),
+ *     async.reflect(function(callback) {
+ *         // do some more stuff but error ...
+ *         callback('bad stuff happened');
+ *     }),
+ *     async.reflect(function(callback) {
+ *         // do some more stuff ...
+ *         callback(null, 'two');
+ *     })
+ * ],
+ * // optional callback
+ * function(err, results) {
+ *     // values
+ *     // results[0].value = 'one'
+ *     // results[1].error = 'bad stuff happened'
+ *     // results[2].value = 'two'
+ * });
+ */
+export default function reflect(fn) {
+    return initialParams(function reflectOn(args, reflectCallback) {
+        args.push(rest(function callback(err, cbArgs) {
+            if (err) {
+                reflectCallback(null, {
+                    error: err
+                });
+            } else {
+                var value = null;
+                if (cbArgs.length === 1) {
+                    value = cbArgs[0];
+                } else if (cbArgs.length > 1) {
+                    value = cbArgs;
+                }
+                reflectCallback(null, {
+                    value: value
+                });
+            }
+        }));
+
+        return fn.apply(this, args);
+    });
+}
+
+
+
+ + + + +
+
+ + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/reflectAll.js.html b/reflectAll.js.html new file mode 100644 index 000000000..58089e1a7 --- /dev/null +++ b/reflectAll.js.html @@ -0,0 +1,190 @@ + + + + + + + reflectAll.js - Documentation + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +

reflectAll.js

+ + + + + + + +
+
+
import reflect from './reflect';
+import isArray from 'lodash/isArray';
+import _arrayMap from 'lodash/_arrayMap';
+import forOwn from 'lodash/_baseForOwn';
+
+/**
+ * A helper function that wraps an array or an object of functions with reflect.
+ *
+ * @name reflectAll
+ * @static
+ * @memberOf module:Utils
+ * @method
+ * @see [async.reflect]{@link module:Utils.reflect}
+ * @category Util
+ * @param {Array} tasks - The array of functions to wrap in `async.reflect`.
+ * @returns {Array} Returns an array of functions, each function wrapped in
+ * `async.reflect`
+ * @example
+ *
+ * let tasks = [
+ *     function(callback) {
+ *         setTimeout(function() {
+ *             callback(null, 'one');
+ *         }, 200);
+ *     },
+ *     function(callback) {
+ *         // do some more stuff but error ...
+ *         callback(new Error('bad stuff happened'));
+ *     },
+ *     function(callback) {
+ *         setTimeout(function() {
+ *             callback(null, 'two');
+ *         }, 100);
+ *     }
+ * ];
+ *
+ * async.parallel(async.reflectAll(tasks),
+ * // optional callback
+ * function(err, results) {
+ *     // values
+ *     // results[0].value = 'one'
+ *     // results[1].error = Error('bad stuff happened')
+ *     // results[2].value = 'two'
+ * });
+ *
+ * // an example using an object instead of an array
+ * let tasks = {
+ *     one: function(callback) {
+ *         setTimeout(function() {
+ *             callback(null, 'one');
+ *         }, 200);
+ *     },
+ *     two: function(callback) {
+ *         callback('two');
+ *     },
+ *     three: function(callback) {
+ *         setTimeout(function() {
+ *             callback(null, 'three');
+ *         }, 100);
+ *     }
+ * };
+ *
+ * async.parallel(async.reflectAll(tasks),
+ * // optional callback
+ * function(err, results) {
+ *     // values
+ *     // results.one.value = 'one'
+ *     // results.two.error = 'two'
+ *     // results.three.value = 'three'
+ * });
+ */
+export default function reflectAll(tasks) {
+    var results;
+    if (isArray(tasks)) {
+        results = _arrayMap(tasks, reflect);
+    } else {
+        results = {};
+        forOwn(tasks, function(task, key) {
+            results[key] = reflect.call(this, task);
+        });
+    }
+    return results;
+}
+
+
+
+ + + + +
+
+ + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/reject.js.html b/reject.js.html new file mode 100644 index 000000000..44fc53f98 --- /dev/null +++ b/reject.js.html @@ -0,0 +1,137 @@ + + + + + + + reject.js - Documentation + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +

reject.js

+ + + + + + + +
+
+
import reject from './internal/reject';
+import doParallel from './internal/doParallel';
+
+/**
+ * The opposite of [`filter`]{@link module:Collections.filter}. Removes values that pass an `async` truth test.
+ *
+ * @name reject
+ * @static
+ * @memberOf module:Collections
+ * @method
+ * @see [async.filter]{@link module:Collections.filter}
+ * @category Collection
+ * @param {Array|Iterable|Object} coll - A collection to iterate over.
+ * @param {Function} iteratee - A truth test to apply to each item in `coll`.
+ * The `iteratee` is passed a `callback(err, truthValue)`, which must be called
+ * with a boolean argument once it has completed. Invoked with (item, callback).
+ * @param {Function} [callback] - A callback which is called after all the
+ * `iteratee` functions have finished. Invoked with (err, results).
+ * @example
+ *
+ * async.reject(['file1','file2','file3'], function(filePath, callback) {
+ *     fs.access(filePath, function(err) {
+ *         callback(null, !err)
+ *     });
+ * }, function(err, results) {
+ *     // results now equals an array of missing files
+ *     createFiles(results);
+ * });
+ */
+export default doParallel(reject);
+
+
+
+ + + + +
+
+ + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/rejectLimit.js.html b/rejectLimit.js.html new file mode 100644 index 000000000..dc514500c --- /dev/null +++ b/rejectLimit.js.html @@ -0,0 +1,129 @@ + + + + + + + rejectLimit.js - Documentation + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +

rejectLimit.js

+ + + + + + + +
+
+
import reject from './internal/reject';
+import doParallelLimit from './internal/doParallelLimit';
+
+/**
+ * The same as [`reject`]{@link module:Collections.reject} but runs a maximum of `limit` async operations at a
+ * time.
+ *
+ * @name rejectLimit
+ * @static
+ * @memberOf module:Collections
+ * @method
+ * @see [async.reject]{@link module:Collections.reject}
+ * @category Collection
+ * @param {Array|Iterable|Object} coll - A collection to iterate over.
+ * @param {number} limit - The maximum number of async operations at a time.
+ * @param {Function} iteratee - A truth test to apply to each item in `coll`.
+ * The `iteratee` is passed a `callback(err, truthValue)`, which must be called
+ * with a boolean argument once it has completed. Invoked with (item, callback).
+ * @param {Function} [callback] - A callback which is called after all the
+ * `iteratee` functions have finished. Invoked with (err, results).
+ */
+export default doParallelLimit(reject);
+
+
+
+ + + + +
+
+ + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/rejectSeries.js.html b/rejectSeries.js.html new file mode 100644 index 000000000..1d931759b --- /dev/null +++ b/rejectSeries.js.html @@ -0,0 +1,127 @@ + + + + + + + rejectSeries.js - Documentation + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +

rejectSeries.js

+ + + + + + + +
+
+
import rejectLimit from './rejectLimit';
+import doLimit from './internal/doLimit';
+
+/**
+ * The same as [`reject`]{@link module:Collections.reject} but runs only a single async operation at a time.
+ *
+ * @name rejectSeries
+ * @static
+ * @memberOf module:Collections
+ * @method
+ * @see [async.reject]{@link module:Collections.reject}
+ * @category Collection
+ * @param {Array|Iterable|Object} coll - A collection to iterate over.
+ * @param {Function} iteratee - A truth test to apply to each item in `coll`.
+ * The `iteratee` is passed a `callback(err, truthValue)`, which must be called
+ * with a boolean argument once it has completed. Invoked with (item, callback).
+ * @param {Function} [callback] - A callback which is called after all the
+ * `iteratee` functions have finished. Invoked with (err, results).
+ */
+export default doLimit(rejectLimit, 1);
+
+
+
+ + + + +
+
+ + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/retry.js.html b/retry.js.html new file mode 100644 index 000000000..c3598295e --- /dev/null +++ b/retry.js.html @@ -0,0 +1,248 @@ + + + + + + + retry.js - Documentation + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +

retry.js

+ + + + + + + +
+
+
import noop from 'lodash/noop';
+import constant from 'lodash/constant';
+
+/**
+ * Attempts to get a successful response from `task` no more than `times` times
+ * before returning an error. If the task is successful, the `callback` will be
+ * passed the result of the successful task. If all attempts fail, the callback
+ * will be passed the error and result (if any) of the final attempt.
+ *
+ * @name retry
+ * @static
+ * @memberOf module:ControlFlow
+ * @method
+ * @category Control Flow
+ * @param {Object|number} [opts = {times: 5, interval: 0}| 5] - Can be either an
+ * object with `times` and `interval` or a number.
+ * * `times` - The number of attempts to make before giving up.  The default
+ *   is `5`.
+ * * `interval` - The time to wait between retries, in milliseconds.  The
+ *   default is `0`. The interval may also be specified as a function of the
+ *   retry count (see example).
+ * * `errorFilter` - An optional synchronous function that is invoked on
+ *   erroneous result. If it returns `true` the retry attempts will continue;
+ *   if the function returns `false` the retry flow is aborted with the current
+ *   attempt's error and result being returned to the final callback.
+ *   Invoked with (err).
+ * * If `opts` is a number, the number specifies the number of times to retry,
+ *   with the default interval of `0`.
+ * @param {Function} task - A function which receives two arguments: (1) a
+ * `callback(err, result)` which must be called when finished, passing `err`
+ * (which can be `null`) and the `result` of the function's execution, and (2)
+ * a `results` object, containing the results of the previously executed
+ * functions (if nested inside another control flow). Invoked with
+ * (callback, results).
+ * @param {Function} [callback] - An optional callback which is called when the
+ * task has succeeded, or after the final failed attempt. It receives the `err`
+ * and `result` arguments of the last attempt at completing the `task`. Invoked
+ * with (err, results).
+ * @example
+ *
+ * // The `retry` function can be used as a stand-alone control flow by passing
+ * // a callback, as shown below:
+ *
+ * // try calling apiMethod 3 times
+ * async.retry(3, apiMethod, function(err, result) {
+ *     // do something with the result
+ * });
+ *
+ * // try calling apiMethod 3 times, waiting 200 ms between each retry
+ * async.retry({times: 3, interval: 200}, apiMethod, function(err, result) {
+ *     // do something with the result
+ * });
+ *
+ * // try calling apiMethod 10 times with exponential backoff
+ * // (i.e. intervals of 100, 200, 400, 800, 1600, ... milliseconds)
+ * async.retry({
+ *   times: 10,
+ *   interval: function(retryCount) {
+ *     return 50 * Math.pow(2, retryCount);
+ *   }
+ * }, apiMethod, function(err, result) {
+ *     // do something with the result
+ * });
+ *
+ * // try calling apiMethod the default 5 times no delay between each retry
+ * async.retry(apiMethod, function(err, result) {
+ *     // do something with the result
+ * });
+ *
+ * // try calling apiMethod only when error condition satisfies, all other
+ * // errors will abort the retry control flow and return to final callback
+ * async.retry({
+ *   errorFilter: function(err) {
+ *     return err.message === 'Temporary error'; // only retry on a specific error
+ *   }
+ * }, 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
+ * });
+ *
+ */
+export default function retry(opts, task, callback) {
+    var DEFAULT_TIMES = 5;
+    var DEFAULT_INTERVAL = 0;
+
+    var options = {
+        times: DEFAULT_TIMES,
+        intervalFunc: constant(DEFAULT_INTERVAL)
+    };
+
+    function parseTimes(acc, t) {
+        if (typeof t === 'object') {
+            acc.times = +t.times || DEFAULT_TIMES;
+
+            acc.intervalFunc = typeof t.interval === 'function' ?
+                t.interval :
+                constant(+t.interval || DEFAULT_INTERVAL);
+
+            acc.errorFilter = t.errorFilter;
+        } else if (typeof t === 'number' || typeof t === 'string') {
+            acc.times = +t || DEFAULT_TIMES;
+        } else {
+            throw new Error("Invalid arguments for async.retry");
+        }
+    }
+
+    if (arguments.length < 3 && typeof opts === 'function') {
+        callback = task || noop;
+        task = opts;
+    } else {
+        parseTimes(options, opts);
+        callback = callback || noop;
+    }
+
+    if (typeof task !== 'function') {
+        throw new Error("Invalid arguments for async.retry");
+    }
+
+    var attempt = 1;
+    function retryAttempt() {
+        task(function(err) {
+            if (err && attempt++ < options.times &&
+                (typeof options.errorFilter != 'function' ||
+                    options.errorFilter(err))) {
+                setTimeout(retryAttempt, options.intervalFunc(attempt));
+            } else {
+                callback.apply(null, arguments);
+            }
+        });
+    }
+
+    retryAttempt();
+}
+
+
+
+ + + + +
+
+ + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/retryable.js.html b/retryable.js.html new file mode 100644 index 000000000..8df34b2bf --- /dev/null +++ b/retryable.js.html @@ -0,0 +1,149 @@ + + + + + + + retryable.js - Documentation + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +

retryable.js

+ + + + + + + +
+
+
import retry from './retry';
+import initialParams from './internal/initialParams';
+
+/**
+ * A close relative of [`retry`]{@link module:ControlFlow.retry}.  This method wraps a task and makes it
+ * retryable, rather than immediately calling it with retries.
+ *
+ * @name retryable
+ * @static
+ * @memberOf module:ControlFlow
+ * @method
+ * @see [async.retry]{@link module:ControlFlow.retry}
+ * @category Control Flow
+ * @param {Object|number} [opts = {times: 5, interval: 0}| 5] - optional
+ * options, exactly the same as from `retry`
+ * @param {Function} task - the asynchronous function to wrap
+ * @returns {Functions} The wrapped function, which when invoked, will retry on
+ * an error, based on the parameters specified in `opts`.
+ * @example
+ *
+ * async.auto({
+ *     dep1: async.retryable(3, getFromFlakyService),
+ *     process: ["dep1", async.retryable(3, function (results, cb) {
+ *         maybeProcessData(results.dep1, cb);
+ *     })]
+ * }, callback);
+ */
+export default function (opts, task) {
+    if (!task) {
+        task = opts;
+        opts = null;
+    }
+    return initialParams(function (args, callback) {
+        function taskFn(cb) {
+            task.apply(null, args.concat(cb));
+        }
+
+        if (opts) retry(opts, taskFn, callback);
+        else retry(taskFn, callback);
+
+    });
+}
+
+
+
+ + + + +
+
+ + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/scripts/async.js b/scripts/async.js new file mode 100644 index 000000000..282ff437b --- /dev/null +++ b/scripts/async.js @@ -0,0 +1,5289 @@ +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : + typeof define === 'function' && define.amd ? define(['exports'], factory) : + (factory((global.async = global.async || {}))); +}(this, (function (exports) { 'use strict'; + +/** + * A faster alternative to `Function#apply`, this function invokes `func` + * with the `this` binding of `thisArg` and the arguments of `args`. + * + * @private + * @param {Function} func The function to invoke. + * @param {*} thisArg The `this` binding of `func`. + * @param {Array} args The arguments to invoke `func` with. + * @returns {*} Returns the result of `func`. + */ +function apply(func, thisArg, args) { + switch (args.length) { + case 0: return func.call(thisArg); + case 1: return func.call(thisArg, args[0]); + case 2: return func.call(thisArg, args[0], args[1]); + case 3: return func.call(thisArg, args[0], args[1], args[2]); + } + return func.apply(thisArg, args); +} + +/* Built-in method references for those with the same name as other `lodash` methods. */ +var nativeMax = Math.max; + +/** + * A specialized version of `baseRest` which transforms the rest array. + * + * @private + * @param {Function} func The function to apply a rest parameter to. + * @param {number} [start=func.length-1] The start position of the rest parameter. + * @param {Function} transform The rest array transform. + * @returns {Function} Returns the new function. + */ +function overRest$1(func, start, transform) { + start = nativeMax(start === undefined ? (func.length - 1) : start, 0); + return function() { + var args = arguments, + index = -1, + length = nativeMax(args.length - start, 0), + array = Array(length); + + while (++index < length) { + array[index] = args[start + index]; + } + index = -1; + var otherArgs = Array(start + 1); + while (++index < start) { + otherArgs[index] = args[index]; + } + otherArgs[start] = transform(array); + return apply(func, this, otherArgs); + }; +} + +/** + * This method returns the first argument it receives. + * + * @static + * @since 0.1.0 + * @memberOf _ + * @category Util + * @param {*} value Any value. + * @returns {*} Returns `value`. + * @example + * + * var object = { 'a': 1 }; + * + * console.log(_.identity(object) === object); + * // => true + */ +function identity(value) { + return value; +} + +// Lodash rest function without function.toString() +// remappings +function rest(func, start) { + return overRest$1(func, start, identity); +} + +var initialParams = function (fn) { + return rest(function (args /*..., callback*/) { + var callback = args.pop(); + fn.call(this, args, callback); + }); +}; + +function applyEach$1(eachfn) { + return rest(function (fns, args) { + var go = initialParams(function (args, callback) { + var that = this; + return eachfn(fns, function (fn, cb) { + fn.apply(that, args.concat(cb)); + }, callback); + }); + if (args.length) { + return go.apply(this, args); + } else { + return go; + } + }); +} + +/** Detect free variable `global` from Node.js. */ +var freeGlobal = typeof global == 'object' && global && global.Object === Object && global; + +/** Detect free variable `self`. */ +var freeSelf = typeof self == 'object' && self && self.Object === Object && self; + +/** Used as a reference to the global object. */ +var root = freeGlobal || freeSelf || Function('return this')(); + +/** Built-in value references. */ +var Symbol$1 = root.Symbol; + +/** Used for built-in method references. */ +var objectProto = Object.prototype; + +/** Used to check objects for own properties. */ +var hasOwnProperty = objectProto.hasOwnProperty; + +/** + * Used to resolve the + * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring) + * of values. + */ +var nativeObjectToString = objectProto.toString; + +/** Built-in value references. */ +var symToStringTag$1 = Symbol$1 ? Symbol$1.toStringTag : undefined; + +/** + * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values. + * + * @private + * @param {*} value The value to query. + * @returns {string} Returns the raw `toStringTag`. + */ +function getRawTag(value) { + var isOwn = hasOwnProperty.call(value, symToStringTag$1), + tag = value[symToStringTag$1]; + + try { + value[symToStringTag$1] = undefined; + var unmasked = true; + } catch (e) {} + + var result = nativeObjectToString.call(value); + if (unmasked) { + if (isOwn) { + value[symToStringTag$1] = tag; + } else { + delete value[symToStringTag$1]; + } + } + return result; +} + +/** Used for built-in method references. */ +var objectProto$1 = Object.prototype; + +/** + * Used to resolve the + * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring) + * of values. + */ +var nativeObjectToString$1 = objectProto$1.toString; + +/** + * Converts `value` to a string using `Object.prototype.toString`. + * + * @private + * @param {*} value The value to convert. + * @returns {string} Returns the converted string. + */ +function objectToString(value) { + return nativeObjectToString$1.call(value); +} + +/** `Object#toString` result references. */ +var nullTag = '[object Null]'; +var undefinedTag = '[object Undefined]'; + +/** Built-in value references. */ +var symToStringTag = Symbol$1 ? Symbol$1.toStringTag : undefined; + +/** + * The base implementation of `getTag` without fallbacks for buggy environments. + * + * @private + * @param {*} value The value to query. + * @returns {string} Returns the `toStringTag`. + */ +function baseGetTag(value) { + if (value == null) { + return value === undefined ? undefinedTag : nullTag; + } + value = Object(value); + return (symToStringTag && symToStringTag in value) + ? getRawTag(value) + : objectToString(value); +} + +/** + * Checks if `value` is the + * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types) + * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`) + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is an object, else `false`. + * @example + * + * _.isObject({}); + * // => true + * + * _.isObject([1, 2, 3]); + * // => true + * + * _.isObject(_.noop); + * // => true + * + * _.isObject(null); + * // => false + */ +function isObject(value) { + var type = typeof value; + return value != null && (type == 'object' || type == 'function'); +} + +/** `Object#toString` result references. */ +var asyncTag = '[object AsyncFunction]'; +var funcTag = '[object Function]'; +var genTag = '[object GeneratorFunction]'; +var proxyTag = '[object Proxy]'; + +/** + * Checks if `value` is classified as a `Function` object. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a function, else `false`. + * @example + * + * _.isFunction(_); + * // => true + * + * _.isFunction(/abc/); + * // => false + */ +function isFunction(value) { + if (!isObject(value)) { + return false; + } + // The use of `Object#toString` avoids issues with the `typeof` operator + // in Safari 9 which returns 'object' for typed arrays and other constructors. + var tag = baseGetTag(value); + return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag; +} + +/** Used as references for various `Number` constants. */ +var MAX_SAFE_INTEGER = 9007199254740991; + +/** + * Checks if `value` is a valid array-like length. + * + * **Note:** This method is loosely based on + * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength). + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a valid length, else `false`. + * @example + * + * _.isLength(3); + * // => true + * + * _.isLength(Number.MIN_VALUE); + * // => false + * + * _.isLength(Infinity); + * // => false + * + * _.isLength('3'); + * // => false + */ +function isLength(value) { + return typeof value == 'number' && + value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER; +} + +/** + * Checks if `value` is array-like. A value is considered array-like if it's + * not a function and has a `value.length` that's an integer greater than or + * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is array-like, else `false`. + * @example + * + * _.isArrayLike([1, 2, 3]); + * // => true + * + * _.isArrayLike(document.body.children); + * // => true + * + * _.isArrayLike('abc'); + * // => true + * + * _.isArrayLike(_.noop); + * // => false + */ +function isArrayLike(value) { + return value != null && isLength(value.length) && !isFunction(value); +} + +/** + * This method returns `undefined`. + * + * @static + * @memberOf _ + * @since 2.3.0 + * @category Util + * @example + * + * _.times(2, _.noop); + * // => [undefined, undefined] + */ +function noop() { + // No operation performed. +} + +function once(fn) { + return function () { + if (fn === null) return; + var callFn = fn; + fn = null; + callFn.apply(this, arguments); + }; +} + +var iteratorSymbol = typeof Symbol === 'function' && Symbol.iterator; + +var getIterator = function (coll) { + return iteratorSymbol && coll[iteratorSymbol] && coll[iteratorSymbol](); +}; + +/** + * The base implementation of `_.times` without support for iteratee shorthands + * or max array length checks. + * + * @private + * @param {number} n The number of times to invoke `iteratee`. + * @param {Function} iteratee The function invoked per iteration. + * @returns {Array} Returns the array of results. + */ +function baseTimes(n, iteratee) { + var index = -1, + result = Array(n); + + while (++index < n) { + result[index] = iteratee(index); + } + return result; +} + +/** + * Checks if `value` is object-like. A value is object-like if it's not `null` + * and has a `typeof` result of "object". + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is object-like, else `false`. + * @example + * + * _.isObjectLike({}); + * // => true + * + * _.isObjectLike([1, 2, 3]); + * // => true + * + * _.isObjectLike(_.noop); + * // => false + * + * _.isObjectLike(null); + * // => false + */ +function isObjectLike(value) { + return value != null && typeof value == 'object'; +} + +/** `Object#toString` result references. */ +var argsTag = '[object Arguments]'; + +/** + * The base implementation of `_.isArguments`. + * + * @private + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is an `arguments` object, + */ +function baseIsArguments(value) { + return isObjectLike(value) && baseGetTag(value) == argsTag; +} + +/** Used for built-in method references. */ +var objectProto$3 = Object.prototype; + +/** Used to check objects for own properties. */ +var hasOwnProperty$2 = objectProto$3.hasOwnProperty; + +/** Built-in value references. */ +var propertyIsEnumerable = objectProto$3.propertyIsEnumerable; + +/** + * Checks if `value` is likely an `arguments` object. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is an `arguments` object, + * else `false`. + * @example + * + * _.isArguments(function() { return arguments; }()); + * // => true + * + * _.isArguments([1, 2, 3]); + * // => false + */ +var isArguments = baseIsArguments(function() { return arguments; }()) ? baseIsArguments : function(value) { + return isObjectLike(value) && hasOwnProperty$2.call(value, 'callee') && + !propertyIsEnumerable.call(value, 'callee'); +}; + +/** + * Checks if `value` is classified as an `Array` object. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is an array, else `false`. + * @example + * + * _.isArray([1, 2, 3]); + * // => true + * + * _.isArray(document.body.children); + * // => false + * + * _.isArray('abc'); + * // => false + * + * _.isArray(_.noop); + * // => false + */ +var isArray = Array.isArray; + +/** + * This method returns `false`. + * + * @static + * @memberOf _ + * @since 4.13.0 + * @category Util + * @returns {boolean} Returns `false`. + * @example + * + * _.times(2, _.stubFalse); + * // => [false, false] + */ +function stubFalse() { + return false; +} + +/** Detect free variable `exports`. */ +var freeExports = typeof exports == 'object' && exports && !exports.nodeType && exports; + +/** Detect free variable `module`. */ +var freeModule = freeExports && typeof module == 'object' && module && !module.nodeType && module; + +/** Detect the popular CommonJS extension `module.exports`. */ +var moduleExports = freeModule && freeModule.exports === freeExports; + +/** Built-in value references. */ +var Buffer = moduleExports ? root.Buffer : undefined; + +/* Built-in method references for those with the same name as other `lodash` methods. */ +var nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined; + +/** + * Checks if `value` is a buffer. + * + * @static + * @memberOf _ + * @since 4.3.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a buffer, else `false`. + * @example + * + * _.isBuffer(new Buffer(2)); + * // => true + * + * _.isBuffer(new Uint8Array(2)); + * // => false + */ +var isBuffer = nativeIsBuffer || stubFalse; + +/** Used as references for various `Number` constants. */ +var MAX_SAFE_INTEGER$1 = 9007199254740991; + +/** Used to detect unsigned integer values. */ +var reIsUint = /^(?:0|[1-9]\d*)$/; + +/** + * Checks if `value` is a valid array-like index. + * + * @private + * @param {*} value The value to check. + * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index. + * @returns {boolean} Returns `true` if `value` is a valid index, else `false`. + */ +function isIndex(value, length) { + length = length == null ? MAX_SAFE_INTEGER$1 : length; + return !!length && + (typeof value == 'number' || reIsUint.test(value)) && + (value > -1 && value % 1 == 0 && value < length); +} + +/** `Object#toString` result references. */ +var argsTag$1 = '[object Arguments]'; +var arrayTag = '[object Array]'; +var boolTag = '[object Boolean]'; +var dateTag = '[object Date]'; +var errorTag = '[object Error]'; +var funcTag$1 = '[object Function]'; +var mapTag = '[object Map]'; +var numberTag = '[object Number]'; +var objectTag = '[object Object]'; +var regexpTag = '[object RegExp]'; +var setTag = '[object Set]'; +var stringTag = '[object String]'; +var weakMapTag = '[object WeakMap]'; + +var arrayBufferTag = '[object ArrayBuffer]'; +var dataViewTag = '[object DataView]'; +var float32Tag = '[object Float32Array]'; +var float64Tag = '[object Float64Array]'; +var int8Tag = '[object Int8Array]'; +var int16Tag = '[object Int16Array]'; +var int32Tag = '[object Int32Array]'; +var uint8Tag = '[object Uint8Array]'; +var uint8ClampedTag = '[object Uint8ClampedArray]'; +var uint16Tag = '[object Uint16Array]'; +var uint32Tag = '[object Uint32Array]'; + +/** Used to identify `toStringTag` values of typed arrays. */ +var typedArrayTags = {}; +typedArrayTags[float32Tag] = typedArrayTags[float64Tag] = +typedArrayTags[int8Tag] = typedArrayTags[int16Tag] = +typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] = +typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] = +typedArrayTags[uint32Tag] = true; +typedArrayTags[argsTag$1] = typedArrayTags[arrayTag] = +typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] = +typedArrayTags[dataViewTag] = typedArrayTags[dateTag] = +typedArrayTags[errorTag] = typedArrayTags[funcTag$1] = +typedArrayTags[mapTag] = typedArrayTags[numberTag] = +typedArrayTags[objectTag] = typedArrayTags[regexpTag] = +typedArrayTags[setTag] = typedArrayTags[stringTag] = +typedArrayTags[weakMapTag] = false; + +/** + * The base implementation of `_.isTypedArray` without Node.js optimizations. + * + * @private + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a typed array, else `false`. + */ +function baseIsTypedArray(value) { + return isObjectLike(value) && + isLength(value.length) && !!typedArrayTags[baseGetTag(value)]; +} + +/** + * The base implementation of `_.unary` without support for storing metadata. + * + * @private + * @param {Function} func The function to cap arguments for. + * @returns {Function} Returns the new capped function. + */ +function baseUnary(func) { + return function(value) { + return func(value); + }; +} + +/** Detect free variable `exports`. */ +var freeExports$1 = typeof exports == 'object' && exports && !exports.nodeType && exports; + +/** Detect free variable `module`. */ +var freeModule$1 = freeExports$1 && typeof module == 'object' && module && !module.nodeType && module; + +/** Detect the popular CommonJS extension `module.exports`. */ +var moduleExports$1 = freeModule$1 && freeModule$1.exports === freeExports$1; + +/** Detect free variable `process` from Node.js. */ +var freeProcess = moduleExports$1 && freeGlobal.process; + +/** Used to access faster Node.js helpers. */ +var nodeUtil = (function() { + try { + return freeProcess && freeProcess.binding('util'); + } catch (e) {} +}()); + +/* Node.js helper references. */ +var nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray; + +/** + * Checks if `value` is classified as a typed array. + * + * @static + * @memberOf _ + * @since 3.0.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a typed array, else `false`. + * @example + * + * _.isTypedArray(new Uint8Array); + * // => true + * + * _.isTypedArray([]); + * // => false + */ +var isTypedArray = nodeIsTypedArray ? baseUnary(nodeIsTypedArray) : baseIsTypedArray; + +/** Used for built-in method references. */ +var objectProto$2 = Object.prototype; + +/** Used to check objects for own properties. */ +var hasOwnProperty$1 = objectProto$2.hasOwnProperty; + +/** + * Creates an array of the enumerable property names of the array-like `value`. + * + * @private + * @param {*} value The value to query. + * @param {boolean} inherited Specify returning inherited property names. + * @returns {Array} Returns the array of property names. + */ +function arrayLikeKeys(value, inherited) { + var isArr = isArray(value), + isArg = !isArr && isArguments(value), + isBuff = !isArr && !isArg && isBuffer(value), + isType = !isArr && !isArg && !isBuff && isTypedArray(value), + skipIndexes = isArr || isArg || isBuff || isType, + result = skipIndexes ? baseTimes(value.length, String) : [], + length = result.length; + + for (var key in value) { + if ((inherited || hasOwnProperty$1.call(value, key)) && + !(skipIndexes && ( + // Safari 9 has enumerable `arguments.length` in strict mode. + key == 'length' || + // Node.js 0.10 has enumerable non-index properties on buffers. + (isBuff && (key == 'offset' || key == 'parent')) || + // PhantomJS 2 has enumerable non-index properties on typed arrays. + (isType && (key == 'buffer' || key == 'byteLength' || key == 'byteOffset')) || + // Skip index properties. + isIndex(key, length) + ))) { + result.push(key); + } + } + return result; +} + +/** Used for built-in method references. */ +var objectProto$5 = Object.prototype; + +/** + * Checks if `value` is likely a prototype object. + * + * @private + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a prototype, else `false`. + */ +function isPrototype(value) { + var Ctor = value && value.constructor, + proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto$5; + + return value === proto; +} + +/** + * Creates a unary function that invokes `func` with its argument transformed. + * + * @private + * @param {Function} func The function to wrap. + * @param {Function} transform The argument transform. + * @returns {Function} Returns the new function. + */ +function overArg(func, transform) { + return function(arg) { + return func(transform(arg)); + }; +} + +/* Built-in method references for those with the same name as other `lodash` methods. */ +var nativeKeys = overArg(Object.keys, Object); + +/** Used for built-in method references. */ +var objectProto$4 = Object.prototype; + +/** Used to check objects for own properties. */ +var hasOwnProperty$3 = objectProto$4.hasOwnProperty; + +/** + * The base implementation of `_.keys` which doesn't treat sparse arrays as dense. + * + * @private + * @param {Object} object The object to query. + * @returns {Array} Returns the array of property names. + */ +function baseKeys(object) { + if (!isPrototype(object)) { + return nativeKeys(object); + } + var result = []; + for (var key in Object(object)) { + if (hasOwnProperty$3.call(object, key) && key != 'constructor') { + result.push(key); + } + } + return result; +} + +/** + * Creates an array of the own enumerable property names of `object`. + * + * **Note:** Non-object values are coerced to objects. See the + * [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys) + * for more details. + * + * @static + * @since 0.1.0 + * @memberOf _ + * @category Object + * @param {Object} object The object to query. + * @returns {Array} Returns the array of property names. + * @example + * + * function Foo() { + * this.a = 1; + * this.b = 2; + * } + * + * Foo.prototype.c = 3; + * + * _.keys(new Foo); + * // => ['a', 'b'] (iteration order is not guaranteed) + * + * _.keys('hi'); + * // => ['0', '1'] + */ +function keys(object) { + return isArrayLike(object) ? arrayLikeKeys(object) : baseKeys(object); +} + +function createArrayIterator(coll) { + var i = -1; + var len = coll.length; + return function next() { + return ++i < len ? { value: coll[i], key: i } : null; + }; +} + +function createES2015Iterator(iterator) { + var i = -1; + return function next() { + var item = iterator.next(); + if (item.done) return null; + i++; + return { value: item.value, key: i }; + }; +} + +function createObjectIterator(obj) { + var okeys = keys(obj); + var i = -1; + var len = okeys.length; + return function next() { + var key = okeys[++i]; + return i < len ? { value: obj[key], key: key } : null; + }; +} + +function iterator(coll) { + if (isArrayLike(coll)) { + return createArrayIterator(coll); + } + + var iterator = getIterator(coll); + return iterator ? createES2015Iterator(iterator) : createObjectIterator(coll); +} + +function onlyOnce(fn) { + return function () { + if (fn === null) throw new Error("Callback was already called."); + var callFn = fn; + fn = null; + callFn.apply(this, arguments); + }; +} + +// A temporary value used to identify if the loop should be broken. +// See #1064, #1293 +var breakLoop = {}; + +function _eachOfLimit(limit) { + return function (obj, iteratee, callback) { + callback = once(callback || noop); + if (limit <= 0 || !obj) { + return callback(null); + } + var nextElem = iterator(obj); + var done = false; + var running = 0; + + function iterateeCallback(err, value) { + running -= 1; + if (err) { + done = true; + callback(err); + } else if (value === breakLoop || done && running <= 0) { + done = true; + return callback(null); + } else { + replenish(); + } + } + + function replenish() { + while (running < limit && !done) { + var elem = nextElem(); + if (elem === null) { + done = true; + if (running <= 0) { + callback(null); + } + return; + } + running += 1; + iteratee(elem.value, elem.key, onlyOnce(iterateeCallback)); + } + } + + replenish(); + }; +} + +/** + * The same as [`eachOf`]{@link module:Collections.eachOf} but runs a maximum of `limit` async operations at a + * time. + * + * @name eachOfLimit + * @static + * @memberOf module:Collections + * @method + * @see [async.eachOf]{@link module:Collections.eachOf} + * @alias forEachOfLimit + * @category Collection + * @param {Array|Iterable|Object} coll - A collection to iterate over. + * @param {number} limit - The maximum number of async operations at a time. + * @param {Function} iteratee - A function to apply to each + * item in `coll`. The `key` is the item's key, or index in the case of an + * array. The iteratee is passed a `callback(err)` which must be called once it + * has completed. If no error has occurred, the callback should be run without + * arguments or with an explicit `null` argument. Invoked with + * (item, key, callback). + * @param {Function} [callback] - A callback which is called when all + * `iteratee` functions have finished, or an error occurs. Invoked with (err). + */ +function eachOfLimit(coll, limit, iteratee, callback) { + _eachOfLimit(limit)(coll, iteratee, callback); +} + +function doLimit(fn, limit) { + return function (iterable, iteratee, callback) { + return fn(iterable, limit, iteratee, callback); + }; +} + +// eachOf implementation optimized for array-likes +function eachOfArrayLike(coll, iteratee, callback) { + callback = once(callback || noop); + var index = 0, + completed = 0, + length = coll.length; + if (length === 0) { + callback(null); + } + + function iteratorCallback(err) { + if (err) { + callback(err); + } else if (++completed === length) { + callback(null); + } + } + + for (; index < length; index++) { + iteratee(coll[index], index, onlyOnce(iteratorCallback)); + } +} + +// a generic version of eachOf which can handle array, object, and iterator cases. +var eachOfGeneric = doLimit(eachOfLimit, Infinity); + +/** + * Like [`each`]{@link module:Collections.each}, except that it passes the key (or index) as the second argument + * to the iteratee. + * + * @name eachOf + * @static + * @memberOf module:Collections + * @method + * @alias forEachOf + * @category Collection + * @see [async.each]{@link module:Collections.each} + * @param {Array|Iterable|Object} coll - A collection to iterate over. + * @param {Function} iteratee - A function to apply to each + * item in `coll`. The `key` is the item's key, or index in the case of an + * array. The iteratee is passed a `callback(err)` which must be called once it + * has completed. If no error has occurred, the callback should be run without + * arguments or with an explicit `null` argument. Invoked with + * (item, key, callback). + * @param {Function} [callback] - A callback which is called when all + * `iteratee` functions have finished, or an error occurs. Invoked with (err). + * @example + * + * var obj = {dev: "/dev.json", test: "/test.json", prod: "/prod.json"}; + * var configs = {}; + * + * async.forEachOf(obj, function (value, key, callback) { + * fs.readFile(__dirname + value, "utf8", function (err, data) { + * if (err) return callback(err); + * try { + * configs[key] = JSON.parse(data); + * } catch (e) { + * return callback(e); + * } + * callback(); + * }); + * }, function (err) { + * if (err) console.error(err.message); + * // configs is now a map of JSON data + * doSomethingWith(configs); + * }); + */ +var eachOf = function (coll, iteratee, callback) { + var eachOfImplementation = isArrayLike(coll) ? eachOfArrayLike : eachOfGeneric; + eachOfImplementation(coll, iteratee, callback); +}; + +function doParallel(fn) { + return function (obj, iteratee, callback) { + return fn(eachOf, obj, iteratee, callback); + }; +} + +function _asyncMap(eachfn, arr, iteratee, callback) { + callback = callback || noop; + arr = arr || []; + var results = []; + var counter = 0; + + eachfn(arr, function (value, _, callback) { + var index = counter++; + iteratee(value, function (err, v) { + results[index] = v; + callback(err); + }); + }, function (err) { + callback(err, results); + }); +} + +/** + * Produces a new collection of values by mapping each value in `coll` through + * the `iteratee` function. The `iteratee` is called with an item from `coll` + * and a callback for when it has finished processing. Each of these callback + * takes 2 arguments: an `error`, and the transformed item from `coll`. If + * `iteratee` passes an error to its callback, the main `callback` (for the + * `map` function) is immediately called with the error. + * + * Note, that since this function applies the `iteratee` to each item in + * parallel, there is no guarantee that the `iteratee` functions will complete + * in order. However, the results array will be in the same order as the + * original `coll`. + * + * If `map` is passed an Object, the results will be an Array. The results + * will roughly be in the order of the original Objects' keys (but this can + * vary across JavaScript engines) + * + * @name map + * @static + * @memberOf module:Collections + * @method + * @category Collection + * @param {Array|Iterable|Object} coll - A collection to iterate over. + * @param {Function} iteratee - A function to apply to each item in `coll`. + * The iteratee is passed a `callback(err, transformed)` which must be called + * once it has completed with an error (which can be `null`) and a + * transformed item. Invoked with (item, callback). + * @param {Function} [callback] - A callback which is called when all `iteratee` + * functions have finished, or an error occurs. Results is an Array of the + * transformed items from the `coll`. Invoked with (err, results). + * @example + * + * async.map(['file1','file2','file3'], fs.stat, function(err, results) { + * // results is now an array of stats for each file + * }); + */ +var map = doParallel(_asyncMap); + +/** + * Applies the provided arguments to each function in the array, calling + * `callback` after all functions have completed. If you only provide the first + * argument, `fns`, then it will return a function which lets you pass in the + * arguments as if it were a single function call. If more arguments are + * provided, `callback` is required while `args` is still optional. + * + * @name applyEach + * @static + * @memberOf module:ControlFlow + * @method + * @category Control Flow + * @param {Array|Iterable|Object} fns - A collection of asynchronous functions + * to all call with the same arguments + * @param {...*} [args] - any number of separate arguments to pass to the + * function. + * @param {Function} [callback] - the final argument should be the callback, + * called when all functions have completed processing. + * @returns {Function} - If only the first argument, `fns`, is provided, it will + * return a function which lets you pass in the arguments as if it were a single + * function call. The signature is `(..args, callback)`. If invoked with any + * arguments, `callback` is required. + * @example + * + * async.applyEach([enableSearch, updateSchema], 'bucket', callback); + * + * // partial application example: + * async.each( + * buckets, + * async.applyEach([enableSearch, updateSchema]), + * callback + * ); + */ +var applyEach = applyEach$1(map); + +function doParallelLimit(fn) { + return function (obj, limit, iteratee, callback) { + return fn(_eachOfLimit(limit), obj, iteratee, callback); + }; +} + +/** + * The same as [`map`]{@link module:Collections.map} but runs a maximum of `limit` async operations at a time. + * + * @name mapLimit + * @static + * @memberOf module:Collections + * @method + * @see [async.map]{@link module:Collections.map} + * @category Collection + * @param {Array|Iterable|Object} coll - A collection to iterate over. + * @param {number} limit - The maximum number of async operations at a time. + * @param {Function} iteratee - A function to apply to each item in `coll`. + * The iteratee is passed a `callback(err, transformed)` which must be called + * once it has completed with an error (which can be `null`) and a transformed + * item. Invoked with (item, callback). + * @param {Function} [callback] - A callback which is called when all `iteratee` + * functions have finished, or an error occurs. Results is an array of the + * transformed items from the `coll`. Invoked with (err, results). + */ +var mapLimit = doParallelLimit(_asyncMap); + +/** + * The same as [`map`]{@link module:Collections.map} but runs only a single async operation at a time. + * + * @name mapSeries + * @static + * @memberOf module:Collections + * @method + * @see [async.map]{@link module:Collections.map} + * @category Collection + * @param {Array|Iterable|Object} coll - A collection to iterate over. + * @param {Function} iteratee - A function to apply to each item in `coll`. + * The iteratee is passed a `callback(err, transformed)` which must be called + * once it has completed with an error (which can be `null`) and a + * transformed item. Invoked with (item, callback). + * @param {Function} [callback] - A callback which is called when all `iteratee` + * functions have finished, or an error occurs. Results is an array of the + * transformed items from the `coll`. Invoked with (err, results). + */ +var mapSeries = doLimit(mapLimit, 1); + +/** + * The same as [`applyEach`]{@link module:ControlFlow.applyEach} but runs only a single async operation at a time. + * + * @name applyEachSeries + * @static + * @memberOf module:ControlFlow + * @method + * @see [async.applyEach]{@link module:ControlFlow.applyEach} + * @category Control Flow + * @param {Array|Iterable|Object} fns - A collection of asynchronous functions to all + * call with the same arguments + * @param {...*} [args] - any number of separate arguments to pass to the + * function. + * @param {Function} [callback] - the final argument should be the callback, + * called when all functions have completed processing. + * @returns {Function} - If only the first argument is provided, it will return + * a function which lets you pass in the arguments as if it were a single + * function call. + */ +var applyEachSeries = applyEach$1(mapSeries); + +/** + * Creates a continuation function with some arguments already applied. + * + * Useful as a shorthand when combined with other control flow functions. Any + * arguments passed to the returned function are added to the arguments + * originally passed to apply. + * + * @name apply + * @static + * @memberOf module:Utils + * @method + * @category Util + * @param {Function} function - The function you want to eventually apply all + * arguments to. Invokes with (arguments...). + * @param {...*} arguments... - Any number of arguments to automatically apply + * when the continuation is called. + * @example + * + * // using apply + * async.parallel([ + * async.apply(fs.writeFile, 'testfile1', 'test1'), + * async.apply(fs.writeFile, 'testfile2', 'test2') + * ]); + * + * + * // the same process without using apply + * async.parallel([ + * function(callback) { + * fs.writeFile('testfile1', 'test1', callback); + * }, + * function(callback) { + * fs.writeFile('testfile2', 'test2', callback); + * } + * ]); + * + * // It's possible to pass any number of additional arguments when calling the + * // continuation: + * + * node> var fn = async.apply(sys.puts, 'one'); + * node> fn('two', 'three'); + * one + * two + * three + */ +var apply$2 = rest(function (fn, args) { + return rest(function (callArgs) { + return fn.apply(null, args.concat(callArgs)); + }); +}); + +/** + * Take a sync function and make it async, passing its return value to a + * callback. This is useful for plugging sync functions into a waterfall, + * series, or other async functions. Any arguments passed to the generated + * function will be passed to the wrapped function (except for the final + * callback argument). Errors thrown will be passed to the callback. + * + * If the function passed to `asyncify` returns a Promise, that promises's + * resolved/rejected state will be used to call the callback, rather than simply + * the synchronous return value. + * + * This also means you can asyncify ES2016 `async` functions. + * + * @name asyncify + * @static + * @memberOf module:Utils + * @method + * @alias wrapSync + * @category Util + * @param {Function} func - The synchronous function to convert to an + * asynchronous function. + * @returns {Function} An asynchronous wrapper of the `func`. To be invoked with + * (callback). + * @example + * + * // passing a regular synchronous function + * async.waterfall([ + * async.apply(fs.readFile, filename, "utf8"), + * async.asyncify(JSON.parse), + * function (data, next) { + * // data is the result of parsing the text. + * // If there was a parsing error, it would have been caught. + * } + * ], callback); + * + * // passing a function returning a promise + * async.waterfall([ + * async.apply(fs.readFile, filename, "utf8"), + * async.asyncify(function (contents) { + * return db.model.create(contents); + * }), + * function (model, next) { + * // `model` is the instantiated model object. + * // If there was an error, this function would be skipped. + * } + * ], callback); + * + * // es6 example + * var q = async.queue(async.asyncify(async function(file) { + * var intermediateStep = await processFile(file); + * return await somePromise(intermediateStep) + * })); + * + * q.push(files); + */ +function asyncify(func) { + return initialParams(function (args, callback) { + var result; + try { + result = func.apply(this, args); + } catch (e) { + return callback(e); + } + // if result is Promise object + if (isObject(result) && typeof result.then === 'function') { + result.then(function (value) { + callback(null, value); + }, function (err) { + callback(err.message ? err : new Error(err)); + }); + } else { + callback(null, result); + } + }); +} + +/** + * A specialized version of `_.forEach` for arrays without support for + * iteratee shorthands. + * + * @private + * @param {Array} [array] The array to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @returns {Array} Returns `array`. + */ +function arrayEach(array, iteratee) { + var index = -1, + length = array == null ? 0 : array.length; + + while (++index < length) { + if (iteratee(array[index], index, array) === false) { + break; + } + } + return array; +} + +/** + * Creates a base function for methods like `_.forIn` and `_.forOwn`. + * + * @private + * @param {boolean} [fromRight] Specify iterating from right to left. + * @returns {Function} Returns the new base function. + */ +function createBaseFor(fromRight) { + return function(object, iteratee, keysFunc) { + var index = -1, + iterable = Object(object), + props = keysFunc(object), + length = props.length; + + while (length--) { + var key = props[fromRight ? length : ++index]; + if (iteratee(iterable[key], key, iterable) === false) { + break; + } + } + return object; + }; +} + +/** + * The base implementation of `baseForOwn` which iterates over `object` + * properties returned by `keysFunc` and invokes `iteratee` for each property. + * Iteratee functions may exit iteration early by explicitly returning `false`. + * + * @private + * @param {Object} object The object to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @param {Function} keysFunc The function to get the keys of `object`. + * @returns {Object} Returns `object`. + */ +var baseFor = createBaseFor(); + +/** + * The base implementation of `_.forOwn` without support for iteratee shorthands. + * + * @private + * @param {Object} object The object to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @returns {Object} Returns `object`. + */ +function baseForOwn(object, iteratee) { + return object && baseFor(object, iteratee, keys); +} + +/** + * The base implementation of `_.findIndex` and `_.findLastIndex` without + * support for iteratee shorthands. + * + * @private + * @param {Array} array The array to inspect. + * @param {Function} predicate The function invoked per iteration. + * @param {number} fromIndex The index to search from. + * @param {boolean} [fromRight] Specify iterating from right to left. + * @returns {number} Returns the index of the matched value, else `-1`. + */ +function baseFindIndex(array, predicate, fromIndex, fromRight) { + var length = array.length, + index = fromIndex + (fromRight ? 1 : -1); + + while ((fromRight ? index-- : ++index < length)) { + if (predicate(array[index], index, array)) { + return index; + } + } + return -1; +} + +/** + * The base implementation of `_.isNaN` without support for number objects. + * + * @private + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`. + */ +function baseIsNaN(value) { + return value !== value; +} + +/** + * A specialized version of `_.indexOf` which performs strict equality + * comparisons of values, i.e. `===`. + * + * @private + * @param {Array} array The array to inspect. + * @param {*} value The value to search for. + * @param {number} fromIndex The index to search from. + * @returns {number} Returns the index of the matched value, else `-1`. + */ +function strictIndexOf(array, value, fromIndex) { + var index = fromIndex - 1, + length = array.length; + + while (++index < length) { + if (array[index] === value) { + return index; + } + } + return -1; +} + +/** + * The base implementation of `_.indexOf` without `fromIndex` bounds checks. + * + * @private + * @param {Array} array The array to inspect. + * @param {*} value The value to search for. + * @param {number} fromIndex The index to search from. + * @returns {number} Returns the index of the matched value, else `-1`. + */ +function baseIndexOf(array, value, fromIndex) { + return value === value + ? strictIndexOf(array, value, fromIndex) + : baseFindIndex(array, baseIsNaN, fromIndex); +} + +/** + * Determines the best order for running the functions in `tasks`, based on + * their requirements. Each function can optionally depend on other functions + * being completed first, and each function is run as soon as its requirements + * are satisfied. + * + * If any of the functions pass an error to their callback, the `auto` sequence + * will stop. Further tasks will not execute (so any other functions depending + * on it will not run), and the main `callback` is immediately called with the + * error. + * + * Functions also receive an object containing the results of functions which + * have completed so far as the first argument, if they have dependencies. If a + * task function has no dependencies, it will only be passed a callback. + * + * @name auto + * @static + * @memberOf module:ControlFlow + * @method + * @category Control Flow + * @param {Object} tasks - An object. Each of its properties is either a + * function or an array of requirements, with the function itself the last item + * in the array. The object's key of a property serves as the name of the task + * defined by that property, i.e. can be used when specifying requirements for + * other tasks. The function receives one or two arguments: + * * a `results` object, containing the results of the previously executed + * functions, only passed if the task has any dependencies, + * * a `callback(err, result)` function, which must be called when finished, + * passing an `error` (which can be `null`) and the result of the function's + * execution. + * @param {number} [concurrency=Infinity] - An optional `integer` for + * determining the maximum number of tasks that can be run in parallel. By + * default, as many as possible. + * @param {Function} [callback] - An optional callback which is called when all + * the tasks have been completed. It receives the `err` argument if any `tasks` + * pass an error to their callback. Results are always returned; however, if an + * error occurs, no further `tasks` will be performed, and the results object + * will only contain partial results. Invoked with (err, results). + * @returns undefined + * @example + * + * async.auto({ + * // this function will just be passed a callback + * readData: async.apply(fs.readFile, 'data.txt', 'utf-8'), + * showData: ['readData', function(results, cb) { + * // results.readData is the file's contents + * // ... + * }] + * }, callback); + * + * async.auto({ + * get_data: function(callback) { + * console.log('in get_data'); + * // async code to get some data + * callback(null, 'data', 'converted to array'); + * }, + * make_folder: function(callback) { + * console.log('in make_folder'); + * // async code to create a directory to store a file in + * // this is run at the same time as getting the data + * callback(null, 'folder'); + * }, + * write_file: ['get_data', 'make_folder', function(results, callback) { + * console.log('in write_file', JSON.stringify(results)); + * // once there is some data and the directory exists, + * // write the data to a file in the directory + * callback(null, 'filename'); + * }], + * email_link: ['write_file', function(results, callback) { + * console.log('in email_link', JSON.stringify(results)); + * // once the file is written let's email a link to it... + * // results.write_file contains the filename returned by write_file. + * callback(null, {'file':results.write_file, 'email':'user@example.com'}); + * }] + * }, function(err, results) { + * console.log('err = ', err); + * console.log('results = ', results); + * }); + */ +var auto = function (tasks, concurrency, callback) { + if (typeof concurrency === 'function') { + // concurrency is optional, shift the args. + callback = concurrency; + concurrency = null; + } + callback = once(callback || noop); + var keys$$1 = keys(tasks); + var numTasks = keys$$1.length; + if (!numTasks) { + return callback(null); + } + if (!concurrency) { + concurrency = numTasks; + } + + var results = {}; + var runningTasks = 0; + var hasError = false; + + var listeners = {}; + + var readyTasks = []; + + // for cycle detection: + var readyToCheck = []; // tasks that have been identified as reachable + // without the possibility of returning to an ancestor task + var uncheckedDependencies = {}; + + baseForOwn(tasks, function (task, key) { + if (!isArray(task)) { + // no dependencies + enqueueTask(key, [task]); + readyToCheck.push(key); + return; + } + + var dependencies = task.slice(0, task.length - 1); + var remainingDependencies = dependencies.length; + if (remainingDependencies === 0) { + enqueueTask(key, task); + readyToCheck.push(key); + return; + } + uncheckedDependencies[key] = remainingDependencies; + + arrayEach(dependencies, function (dependencyName) { + if (!tasks[dependencyName]) { + throw new Error('async.auto task `' + key + '` has a non-existent dependency in ' + dependencies.join(', ')); + } + addListener(dependencyName, function () { + remainingDependencies--; + if (remainingDependencies === 0) { + enqueueTask(key, task); + } + }); + }); + }); + + checkForDeadlocks(); + processQueue(); + + function enqueueTask(key, task) { + readyTasks.push(function () { + runTask(key, task); + }); + } + + function processQueue() { + if (readyTasks.length === 0 && runningTasks === 0) { + return callback(null, results); + } + while (readyTasks.length && runningTasks < concurrency) { + var run = readyTasks.shift(); + run(); + } + } + + function addListener(taskName, fn) { + var taskListeners = listeners[taskName]; + if (!taskListeners) { + taskListeners = listeners[taskName] = []; + } + + taskListeners.push(fn); + } + + function taskComplete(taskName) { + var taskListeners = listeners[taskName] || []; + arrayEach(taskListeners, function (fn) { + fn(); + }); + processQueue(); + } + + function runTask(key, task) { + if (hasError) return; + + var taskCallback = onlyOnce(rest(function (err, args) { + runningTasks--; + if (args.length <= 1) { + args = args[0]; + } + if (err) { + var safeResults = {}; + baseForOwn(results, function (val, rkey) { + safeResults[rkey] = val; + }); + safeResults[key] = args; + hasError = true; + listeners = []; + + callback(err, safeResults); + } else { + results[key] = args; + taskComplete(key); + } + })); + + runningTasks++; + var taskFn = task[task.length - 1]; + if (task.length > 1) { + taskFn(results, taskCallback); + } else { + taskFn(taskCallback); + } + } + + function checkForDeadlocks() { + // Kahn's algorithm + // https://en.wikipedia.org/wiki/Topological_sorting#Kahn.27s_algorithm + // http://connalle.blogspot.com/2013/10/topological-sortingkahn-algorithm.html + var currentTask; + var counter = 0; + while (readyToCheck.length) { + currentTask = readyToCheck.pop(); + counter++; + arrayEach(getDependents(currentTask), function (dependent) { + if (--uncheckedDependencies[dependent] === 0) { + readyToCheck.push(dependent); + } + }); + } + + if (counter !== numTasks) { + throw new Error('async.auto cannot execute tasks due to a recursive dependency'); + } + } + + function getDependents(taskName) { + var result = []; + baseForOwn(tasks, function (task, key) { + if (isArray(task) && baseIndexOf(task, taskName, 0) >= 0) { + result.push(key); + } + }); + return result; + } +}; + +/** + * A specialized version of `_.map` for arrays without support for iteratee + * shorthands. + * + * @private + * @param {Array} [array] The array to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @returns {Array} Returns the new mapped array. + */ +function arrayMap(array, iteratee) { + var index = -1, + length = array == null ? 0 : array.length, + result = Array(length); + + while (++index < length) { + result[index] = iteratee(array[index], index, array); + } + return result; +} + +/** `Object#toString` result references. */ +var symbolTag = '[object Symbol]'; + +/** + * Checks if `value` is classified as a `Symbol` primitive or object. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a symbol, else `false`. + * @example + * + * _.isSymbol(Symbol.iterator); + * // => true + * + * _.isSymbol('abc'); + * // => false + */ +function isSymbol(value) { + return typeof value == 'symbol' || + (isObjectLike(value) && baseGetTag(value) == symbolTag); +} + +/** Used as references for various `Number` constants. */ +var INFINITY = 1 / 0; + +/** Used to convert symbols to primitives and strings. */ +var symbolProto = Symbol$1 ? Symbol$1.prototype : undefined; +var symbolToString = symbolProto ? symbolProto.toString : undefined; + +/** + * The base implementation of `_.toString` which doesn't convert nullish + * values to empty strings. + * + * @private + * @param {*} value The value to process. + * @returns {string} Returns the string. + */ +function baseToString(value) { + // Exit early for strings to avoid a performance hit in some environments. + if (typeof value == 'string') { + return value; + } + if (isArray(value)) { + // Recursively convert values (susceptible to call stack limits). + return arrayMap(value, baseToString) + ''; + } + if (isSymbol(value)) { + return symbolToString ? symbolToString.call(value) : ''; + } + var result = (value + ''); + return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result; +} + +/** + * The base implementation of `_.slice` without an iteratee call guard. + * + * @private + * @param {Array} array The array to slice. + * @param {number} [start=0] The start position. + * @param {number} [end=array.length] The end position. + * @returns {Array} Returns the slice of `array`. + */ +function baseSlice(array, start, end) { + var index = -1, + length = array.length; + + if (start < 0) { + start = -start > length ? 0 : (length + start); + } + end = end > length ? length : end; + if (end < 0) { + end += length; + } + length = start > end ? 0 : ((end - start) >>> 0); + start >>>= 0; + + var result = Array(length); + while (++index < length) { + result[index] = array[index + start]; + } + return result; +} + +/** + * Casts `array` to a slice if it's needed. + * + * @private + * @param {Array} array The array to inspect. + * @param {number} start The start position. + * @param {number} [end=array.length] The end position. + * @returns {Array} Returns the cast slice. + */ +function castSlice(array, start, end) { + var length = array.length; + end = end === undefined ? length : end; + return (!start && end >= length) ? array : baseSlice(array, start, end); +} + +/** + * Used by `_.trim` and `_.trimEnd` to get the index of the last string symbol + * that is not found in the character symbols. + * + * @private + * @param {Array} strSymbols The string symbols to inspect. + * @param {Array} chrSymbols The character symbols to find. + * @returns {number} Returns the index of the last unmatched string symbol. + */ +function charsEndIndex(strSymbols, chrSymbols) { + var index = strSymbols.length; + + while (index-- && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {} + return index; +} + +/** + * Used by `_.trim` and `_.trimStart` to get the index of the first string symbol + * that is not found in the character symbols. + * + * @private + * @param {Array} strSymbols The string symbols to inspect. + * @param {Array} chrSymbols The character symbols to find. + * @returns {number} Returns the index of the first unmatched string symbol. + */ +function charsStartIndex(strSymbols, chrSymbols) { + var index = -1, + length = strSymbols.length; + + while (++index < length && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {} + return index; +} + +/** + * Converts an ASCII `string` to an array. + * + * @private + * @param {string} string The string to convert. + * @returns {Array} Returns the converted array. + */ +function asciiToArray(string) { + return string.split(''); +} + +/** Used to compose unicode character classes. */ +var rsAstralRange = '\\ud800-\\udfff'; +var rsComboMarksRange = '\\u0300-\\u036f\\ufe20-\\ufe23'; +var rsComboSymbolsRange = '\\u20d0-\\u20f0'; +var rsVarRange = '\\ufe0e\\ufe0f'; + +/** Used to compose unicode capture groups. */ +var rsZWJ = '\\u200d'; + +/** Used to detect strings with [zero-width joiners or code points from the astral planes](http://eev.ee/blog/2015/09/12/dark-corners-of-unicode/). */ +var reHasUnicode = RegExp('[' + rsZWJ + rsAstralRange + rsComboMarksRange + rsComboSymbolsRange + rsVarRange + ']'); + +/** + * Checks if `string` contains Unicode symbols. + * + * @private + * @param {string} string The string to inspect. + * @returns {boolean} Returns `true` if a symbol is found, else `false`. + */ +function hasUnicode(string) { + return reHasUnicode.test(string); +} + +/** Used to compose unicode character classes. */ +var rsAstralRange$1 = '\\ud800-\\udfff'; +var rsComboMarksRange$1 = '\\u0300-\\u036f\\ufe20-\\ufe23'; +var rsComboSymbolsRange$1 = '\\u20d0-\\u20f0'; +var rsVarRange$1 = '\\ufe0e\\ufe0f'; + +/** Used to compose unicode capture groups. */ +var rsAstral = '[' + rsAstralRange$1 + ']'; +var rsCombo = '[' + rsComboMarksRange$1 + rsComboSymbolsRange$1 + ']'; +var rsFitz = '\\ud83c[\\udffb-\\udfff]'; +var rsModifier = '(?:' + rsCombo + '|' + rsFitz + ')'; +var rsNonAstral = '[^' + rsAstralRange$1 + ']'; +var rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}'; +var rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]'; +var rsZWJ$1 = '\\u200d'; + +/** Used to compose unicode regexes. */ +var reOptMod = rsModifier + '?'; +var rsOptVar = '[' + rsVarRange$1 + ']?'; +var rsOptJoin = '(?:' + rsZWJ$1 + '(?:' + [rsNonAstral, rsRegional, rsSurrPair].join('|') + ')' + rsOptVar + reOptMod + ')*'; +var rsSeq = rsOptVar + reOptMod + rsOptJoin; +var rsSymbol = '(?:' + [rsNonAstral + rsCombo + '?', rsCombo, rsRegional, rsSurrPair, rsAstral].join('|') + ')'; + +/** Used to match [string symbols](https://mathiasbynens.be/notes/javascript-unicode). */ +var reUnicode = RegExp(rsFitz + '(?=' + rsFitz + ')|' + rsSymbol + rsSeq, 'g'); + +/** + * Converts a Unicode `string` to an array. + * + * @private + * @param {string} string The string to convert. + * @returns {Array} Returns the converted array. + */ +function unicodeToArray(string) { + return string.match(reUnicode) || []; +} + +/** + * Converts `string` to an array. + * + * @private + * @param {string} string The string to convert. + * @returns {Array} Returns the converted array. + */ +function stringToArray(string) { + return hasUnicode(string) + ? unicodeToArray(string) + : asciiToArray(string); +} + +/** + * Converts `value` to a string. An empty string is returned for `null` + * and `undefined` values. The sign of `-0` is preserved. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Lang + * @param {*} value The value to convert. + * @returns {string} Returns the converted string. + * @example + * + * _.toString(null); + * // => '' + * + * _.toString(-0); + * // => '-0' + * + * _.toString([1, 2, 3]); + * // => '1,2,3' + */ +function toString(value) { + return value == null ? '' : baseToString(value); +} + +/** Used to match leading and trailing whitespace. */ +var reTrim = /^\s+|\s+$/g; + +/** + * Removes leading and trailing whitespace or specified characters from `string`. + * + * @static + * @memberOf _ + * @since 3.0.0 + * @category String + * @param {string} [string=''] The string to trim. + * @param {string} [chars=whitespace] The characters to trim. + * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. + * @returns {string} Returns the trimmed string. + * @example + * + * _.trim(' abc '); + * // => 'abc' + * + * _.trim('-_-abc-_-', '_-'); + * // => 'abc' + * + * _.map([' foo ', ' bar '], _.trim); + * // => ['foo', 'bar'] + */ +function trim(string, chars, guard) { + string = toString(string); + if (string && (guard || chars === undefined)) { + return string.replace(reTrim, ''); + } + if (!string || !(chars = baseToString(chars))) { + return string; + } + var strSymbols = stringToArray(string), + chrSymbols = stringToArray(chars), + start = charsStartIndex(strSymbols, chrSymbols), + end = charsEndIndex(strSymbols, chrSymbols) + 1; + + return castSlice(strSymbols, start, end).join(''); +} + +var FN_ARGS = /^(function)?\s*[^\(]*\(\s*([^\)]*)\)/m; +var FN_ARG_SPLIT = /,/; +var FN_ARG = /(=.+)?(\s*)$/; +var STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg; + +function parseParams(func) { + func = func.toString().replace(STRIP_COMMENTS, ''); + func = func.match(FN_ARGS)[2].replace(' ', ''); + func = func ? func.split(FN_ARG_SPLIT) : []; + func = func.map(function (arg) { + return trim(arg.replace(FN_ARG, '')); + }); + return func; +} + +/** + * A dependency-injected version of the [async.auto]{@link module:ControlFlow.auto} function. Dependent + * tasks are specified as parameters to the function, after the usual callback + * parameter, with the parameter names matching the names of the tasks it + * depends on. This can provide even more readable task graphs which can be + * easier to maintain. + * + * If a final callback is specified, the task results are similarly injected, + * specified as named parameters after the initial error parameter. + * + * The autoInject function is purely syntactic sugar and its semantics are + * otherwise equivalent to [async.auto]{@link module:ControlFlow.auto}. + * + * @name autoInject + * @static + * @memberOf module:ControlFlow + * @method + * @see [async.auto]{@link module:ControlFlow.auto} + * @category Control Flow + * @param {Object} tasks - An object, each of whose properties is a function of + * the form 'func([dependencies...], callback). The object's key of a property + * serves as the name of the task defined by that property, i.e. can be used + * when specifying requirements for other tasks. + * * The `callback` parameter is a `callback(err, result)` which must be called + * when finished, passing an `error` (which can be `null`) and the result of + * the function's execution. The remaining parameters name other tasks on + * which the task is dependent, and the results from those tasks are the + * arguments of those parameters. + * @param {Function} [callback] - An optional callback which is called when all + * the tasks have been completed. It receives the `err` argument if any `tasks` + * pass an error to their callback, and a `results` object with any completed + * task results, similar to `auto`. + * @example + * + * // The example from `auto` can be rewritten as follows: + * async.autoInject({ + * get_data: function(callback) { + * // async code to get some data + * callback(null, 'data', 'converted to array'); + * }, + * make_folder: function(callback) { + * // async code to create a directory to store a file in + * // this is run at the same time as getting the data + * callback(null, 'folder'); + * }, + * write_file: function(get_data, make_folder, callback) { + * // once there is some data and the directory exists, + * // write the data to a file in the directory + * callback(null, 'filename'); + * }, + * email_link: function(write_file, callback) { + * // once the file is written let's email a link to it... + * // write_file contains the filename returned by write_file. + * callback(null, {'file':write_file, 'email':'user@example.com'}); + * } + * }, function(err, results) { + * console.log('err = ', err); + * console.log('email_link = ', results.email_link); + * }); + * + * // If you are using a JS minifier that mangles parameter names, `autoInject` + * // will not work with plain functions, since the parameter names will be + * // collapsed to a single letter identifier. To work around this, you can + * // explicitly specify the names of the parameters your task function needs + * // in an array, similar to Angular.js dependency injection. + * + * // This still has an advantage over plain `auto`, since the results a task + * // depends on are still spread into arguments. + * async.autoInject({ + * //... + * write_file: ['get_data', 'make_folder', function(get_data, make_folder, callback) { + * callback(null, 'filename'); + * }], + * email_link: ['write_file', function(write_file, callback) { + * callback(null, {'file':write_file, 'email':'user@example.com'}); + * }] + * //... + * }, function(err, results) { + * console.log('err = ', err); + * console.log('email_link = ', results.email_link); + * }); + */ +function autoInject(tasks, callback) { + var newTasks = {}; + + baseForOwn(tasks, function (taskFn, key) { + var params; + + if (isArray(taskFn)) { + params = taskFn.slice(0, -1); + taskFn = taskFn[taskFn.length - 1]; + + newTasks[key] = params.concat(params.length > 0 ? newTask : taskFn); + } else if (taskFn.length === 1) { + // no dependencies, use the function as-is + newTasks[key] = taskFn; + } else { + params = parseParams(taskFn); + if (taskFn.length === 0 && params.length === 0) { + throw new Error("autoInject task functions require explicit parameters."); + } + + params.pop(); + + newTasks[key] = params.concat(newTask); + } + + function newTask(results, taskCb) { + var newArgs = arrayMap(params, function (name) { + return results[name]; + }); + newArgs.push(taskCb); + taskFn.apply(null, newArgs); + } + }); + + auto(newTasks, callback); +} + +var hasSetImmediate = typeof setImmediate === 'function' && setImmediate; +var hasNextTick = typeof process === 'object' && typeof process.nextTick === 'function'; + +function fallback(fn) { + setTimeout(fn, 0); +} + +function wrap(defer) { + return rest(function (fn, args) { + defer(function () { + fn.apply(null, args); + }); + }); +} + +var _defer; + +if (hasSetImmediate) { + _defer = setImmediate; +} else if (hasNextTick) { + _defer = process.nextTick; +} else { + _defer = fallback; +} + +var setImmediate$1 = wrap(_defer); + +// Simple doubly linked list (https://en.wikipedia.org/wiki/Doubly_linked_list) implementation +// used for queues. This implementation assumes that the node provided by the user can be modified +// to adjust the next and last properties. We implement only the minimal functionality +// for queue support. +function DLL() { + this.head = this.tail = null; + this.length = 0; +} + +function setInitial(dll, node) { + dll.length = 1; + dll.head = dll.tail = node; +} + +DLL.prototype.removeLink = function (node) { + if (node.prev) node.prev.next = node.next;else this.head = node.next; + if (node.next) node.next.prev = node.prev;else this.tail = node.prev; + + node.prev = node.next = null; + this.length -= 1; + return node; +}; + +DLL.prototype.empty = DLL; + +DLL.prototype.insertAfter = function (node, newNode) { + newNode.prev = node; + newNode.next = node.next; + if (node.next) node.next.prev = newNode;else this.tail = newNode; + node.next = newNode; + this.length += 1; +}; + +DLL.prototype.insertBefore = function (node, newNode) { + newNode.prev = node.prev; + newNode.next = node; + if (node.prev) node.prev.next = newNode;else this.head = newNode; + node.prev = newNode; + this.length += 1; +}; + +DLL.prototype.unshift = function (node) { + if (this.head) this.insertBefore(this.head, node);else setInitial(this, node); +}; + +DLL.prototype.push = function (node) { + if (this.tail) this.insertAfter(this.tail, node);else setInitial(this, node); +}; + +DLL.prototype.shift = function () { + return this.head && this.removeLink(this.head); +}; + +DLL.prototype.pop = function () { + return this.tail && this.removeLink(this.tail); +}; + +function queue(worker, concurrency, payload) { + if (concurrency == null) { + concurrency = 1; + } else if (concurrency === 0) { + throw new Error('Concurrency must not be zero'); + } + + function _insert(data, insertAtFront, callback) { + if (callback != null && typeof callback !== 'function') { + throw new Error('task callback must be a function'); + } + q.started = true; + if (!isArray(data)) { + data = [data]; + } + if (data.length === 0 && q.idle()) { + // call drain immediately if there are no tasks + return setImmediate$1(function () { + q.drain(); + }); + } + + for (var i = 0, l = data.length; i < l; i++) { + var item = { + data: data[i], + callback: callback || noop + }; + + if (insertAtFront) { + q._tasks.unshift(item); + } else { + q._tasks.push(item); + } + } + setImmediate$1(q.process); + } + + function _next(tasks) { + return rest(function (args) { + workers -= 1; + + for (var i = 0, l = tasks.length; i < l; i++) { + var task = tasks[i]; + var index = baseIndexOf(workersList, task, 0); + if (index >= 0) { + workersList.splice(index); + } + + task.callback.apply(task, args); + + if (args[0] != null) { + q.error(args[0], task.data); + } + } + + if (workers <= q.concurrency - q.buffer) { + q.unsaturated(); + } + + if (q.idle()) { + q.drain(); + } + q.process(); + }); + } + + var workers = 0; + var workersList = []; + var q = { + _tasks: new DLL(), + concurrency: concurrency, + payload: payload, + saturated: noop, + unsaturated: noop, + buffer: concurrency / 4, + empty: noop, + drain: noop, + error: noop, + started: false, + paused: false, + push: function (data, callback) { + _insert(data, false, callback); + }, + kill: function () { + q.drain = noop; + q._tasks.empty(); + }, + unshift: function (data, callback) { + _insert(data, true, callback); + }, + process: function () { + while (!q.paused && workers < q.concurrency && q._tasks.length) { + var tasks = [], + data = []; + var l = q._tasks.length; + if (q.payload) l = Math.min(l, q.payload); + for (var i = 0; i < l; i++) { + var node = q._tasks.shift(); + tasks.push(node); + data.push(node.data); + } + + if (q._tasks.length === 0) { + q.empty(); + } + workers += 1; + workersList.push(tasks[0]); + + if (workers === q.concurrency) { + q.saturated(); + } + + var cb = onlyOnce(_next(tasks)); + worker(data, cb); + } + }, + length: function () { + return q._tasks.length; + }, + running: function () { + return workers; + }, + workersList: function () { + return workersList; + }, + idle: function () { + return q._tasks.length + workers === 0; + }, + pause: function () { + q.paused = true; + }, + resume: function () { + if (q.paused === false) { + return; + } + q.paused = false; + var resumeCount = Math.min(q.concurrency, q._tasks.length); + // Need to call q.process once per concurrent + // worker to preserve full concurrency after pause + for (var w = 1; w <= resumeCount; w++) { + setImmediate$1(q.process); + } + } + }; + return q; +} + +/** + * A cargo of tasks for the worker function to complete. Cargo inherits all of + * the same methods and event callbacks as [`queue`]{@link module:ControlFlow.queue}. + * @typedef {Object} CargoObject + * @memberOf module:ControlFlow + * @property {Function} length - A function returning the number of items + * waiting to be processed. Invoke like `cargo.length()`. + * @property {number} payload - An `integer` for determining how many tasks + * should be process per round. This property can be changed after a `cargo` is + * created to alter the payload on-the-fly. + * @property {Function} push - Adds `task` to the `queue`. The callback is + * called once the `worker` has finished processing the task. Instead of a + * single task, an array of `tasks` can be submitted. The respective callback is + * used for every task in the list. Invoke like `cargo.push(task, [callback])`. + * @property {Function} saturated - A callback that is called when the + * `queue.length()` hits the concurrency and further tasks will be queued. + * @property {Function} empty - A callback that is called when the last item + * from the `queue` is given to a `worker`. + * @property {Function} drain - A callback that is called when the last item + * from the `queue` has returned from the `worker`. + * @property {Function} idle - a function returning false if there are items + * waiting or being processed, or true if not. Invoke like `cargo.idle()`. + * @property {Function} pause - a function that pauses the processing of tasks + * until `resume()` is called. Invoke like `cargo.pause()`. + * @property {Function} resume - a function that resumes the processing of + * queued tasks when the queue is paused. Invoke like `cargo.resume()`. + * @property {Function} kill - a function that removes the `drain` callback and + * empties remaining tasks from the queue forcing it to go idle. Invoke like `cargo.kill()`. + */ + +/** + * Creates a `cargo` object with the specified payload. Tasks added to the + * cargo will be processed altogether (up to the `payload` limit). If the + * `worker` is in progress, the task is queued until it becomes available. Once + * the `worker` has completed some tasks, each callback of those tasks is + * called. Check out [these](https://camo.githubusercontent.com/6bbd36f4cf5b35a0f11a96dcd2e97711ffc2fb37/68747470733a2f2f662e636c6f75642e6769746875622e636f6d2f6173736574732f313637363837312f36383130382f62626330636662302d356632392d313165322d393734662d3333393763363464633835382e676966) [animations](https://camo.githubusercontent.com/f4810e00e1c5f5f8addbe3e9f49064fd5d102699/68747470733a2f2f662e636c6f75642e6769746875622e636f6d2f6173736574732f313637363837312f36383130312f38346339323036362d356632392d313165322d383134662d3964336430323431336266642e676966) + * for how `cargo` and `queue` work. + * + * While [`queue`]{@link module:ControlFlow.queue} passes only one task to one of a group of workers + * at a time, cargo passes an array of tasks to a single worker, repeating + * when the worker is finished. + * + * @name cargo + * @static + * @memberOf module:ControlFlow + * @method + * @see [async.queue]{@link module:ControlFlow.queue} + * @category Control Flow + * @param {Function} worker - An asynchronous function for processing an array + * of queued tasks, which must call its `callback(err)` argument when finished, + * with an optional `err` argument. Invoked with `(tasks, callback)`. + * @param {number} [payload=Infinity] - An optional `integer` for determining + * how many tasks should be processed per round; if omitted, the default is + * unlimited. + * @returns {module:ControlFlow.CargoObject} A cargo object to manage the tasks. Callbacks can + * attached as certain properties to listen for specific events during the + * lifecycle of the cargo and inner queue. + * @example + * + * // create a cargo object with payload 2 + * var cargo = async.cargo(function(tasks, callback) { + * for (var i=0; i 3) { + cb = cb || noop; + eachfn(arr, limit, wrappedIteratee, done); + } else { + cb = iteratee; + cb = cb || noop; + iteratee = limit; + eachfn(arr, wrappedIteratee, done); + } + }; +} + +function _findGetResult(v, x) { + return x; +} + +/** + * Returns the first value in `coll` that passes an async truth test. The + * `iteratee` is applied in parallel, meaning the first iteratee to return + * `true` will fire the detect `callback` with that result. That means the + * result might not be the first item in the original `coll` (in terms of order) + * that passes the test. + + * If order within the original `coll` is important, then look at + * [`detectSeries`]{@link module:Collections.detectSeries}. + * + * @name detect + * @static + * @memberOf module:Collections + * @method + * @alias find + * @category Collections + * @param {Array|Iterable|Object} coll - A collection to iterate over. + * @param {Function} iteratee - A truth test to apply to each item in `coll`. + * The iteratee is passed a `callback(err, truthValue)` which must be called + * with a boolean argument once it has completed. Invoked with (item, callback). + * @param {Function} [callback] - A callback which is called as soon as any + * iteratee returns `true`, or after all the `iteratee` functions have finished. + * Result will be the first item in the array that passes the truth test + * (iteratee) or the value `undefined` if none passed. Invoked with + * (err, result). + * @example + * + * async.detect(['file1','file2','file3'], function(filePath, callback) { + * fs.access(filePath, function(err) { + * callback(null, !err) + * }); + * }, function(err, result) { + * // result now equals the first file in the list that exists + * }); + */ +var detect = _createTester(eachOf, identity, _findGetResult); + +/** + * The same as [`detect`]{@link module:Collections.detect} but runs a maximum of `limit` async operations at a + * time. + * + * @name detectLimit + * @static + * @memberOf module:Collections + * @method + * @see [async.detect]{@link module:Collections.detect} + * @alias findLimit + * @category Collections + * @param {Array|Iterable|Object} coll - A collection to iterate over. + * @param {number} limit - The maximum number of async operations at a time. + * @param {Function} iteratee - A truth test to apply to each item in `coll`. + * The iteratee is passed a `callback(err, truthValue)` which must be called + * with a boolean argument once it has completed. Invoked with (item, callback). + * @param {Function} [callback] - A callback which is called as soon as any + * iteratee returns `true`, or after all the `iteratee` functions have finished. + * Result will be the first item in the array that passes the truth test + * (iteratee) or the value `undefined` if none passed. Invoked with + * (err, result). + */ +var detectLimit = _createTester(eachOfLimit, identity, _findGetResult); + +/** + * The same as [`detect`]{@link module:Collections.detect} but runs only a single async operation at a time. + * + * @name detectSeries + * @static + * @memberOf module:Collections + * @method + * @see [async.detect]{@link module:Collections.detect} + * @alias findSeries + * @category Collections + * @param {Array|Iterable|Object} coll - A collection to iterate over. + * @param {Function} iteratee - A truth test to apply to each item in `coll`. + * The iteratee is passed a `callback(err, truthValue)` which must be called + * with a boolean argument once it has completed. Invoked with (item, callback). + * @param {Function} [callback] - A callback which is called as soon as any + * iteratee returns `true`, or after all the `iteratee` functions have finished. + * Result will be the first item in the array that passes the truth test + * (iteratee) or the value `undefined` if none passed. Invoked with + * (err, result). + */ +var detectSeries = _createTester(eachOfSeries, identity, _findGetResult); + +function consoleFunc(name) { + return rest(function (fn, args) { + fn.apply(null, args.concat(rest(function (err, args) { + if (typeof console === 'object') { + if (err) { + if (console.error) { + console.error(err); + } + } else if (console[name]) { + arrayEach(args, function (x) { + console[name](x); + }); + } + } + }))); + }); +} + +/** + * Logs the result of an `async` function to the `console` using `console.dir` + * to display the properties of the resulting object. Only works in Node.js or + * in browsers that support `console.dir` and `console.error` (such as FF and + * Chrome). If multiple arguments are returned from the async function, + * `console.dir` is called on each argument in order. + * + * @name dir + * @static + * @memberOf module:Utils + * @method + * @category Util + * @param {Function} function - The function you want to eventually apply all + * arguments to. + * @param {...*} arguments... - Any number of arguments to apply to the function. + * @example + * + * // in a module + * var hello = function(name, callback) { + * setTimeout(function() { + * callback(null, {hello: name}); + * }, 1000); + * }; + * + * // in the node repl + * node> async.dir(hello, 'world'); + * {hello: 'world'} + */ +var dir = consoleFunc('dir'); + +/** + * The post-check version of [`during`]{@link module:ControlFlow.during}. To reflect the difference in + * the order of operations, the arguments `test` and `fn` are switched. + * + * Also a version of [`doWhilst`]{@link module:ControlFlow.doWhilst} with asynchronous `test` function. + * @name doDuring + * @static + * @memberOf module:ControlFlow + * @method + * @see [async.during]{@link module:ControlFlow.during} + * @category Control Flow + * @param {Function} fn - A function which is called each time `test` passes. + * The function is passed a `callback(err)`, which must be called once it has + * completed with an optional `err` argument. Invoked with (callback). + * @param {Function} test - asynchronous truth test to perform before each + * execution of `fn`. Invoked with (...args, callback), where `...args` are the + * non-error args from the previous callback of `fn`. + * @param {Function} [callback] - A callback which is called after the test + * function has failed and repeated execution of `fn` has stopped. `callback` + * will be passed an error if one occured, otherwise `null`. + */ +function doDuring(fn, test, callback) { + callback = onlyOnce(callback || noop); + + var next = rest(function (err, args) { + if (err) return callback(err); + args.push(check); + test.apply(this, args); + }); + + function check(err, truth) { + if (err) return callback(err); + if (!truth) return callback(null); + fn(next); + } + + check(null, true); +} + +/** + * The post-check version of [`whilst`]{@link module:ControlFlow.whilst}. To reflect the difference in + * the order of operations, the arguments `test` and `iteratee` are switched. + * + * `doWhilst` is to `whilst` as `do while` is to `while` in plain JavaScript. + * + * @name doWhilst + * @static + * @memberOf module:ControlFlow + * @method + * @see [async.whilst]{@link module:ControlFlow.whilst} + * @category Control Flow + * @param {Function} iteratee - A function which is called each time `test` + * passes. The function is passed a `callback(err)`, which must be called once + * it has completed with an optional `err` argument. Invoked with (callback). + * @param {Function} test - synchronous truth test to perform after each + * execution of `iteratee`. Invoked with the non-error callback results of + * `iteratee`. + * @param {Function} [callback] - A callback which is called after the test + * function has failed and repeated execution of `iteratee` has stopped. + * `callback` will be passed an error and any arguments passed to the final + * `iteratee`'s callback. Invoked with (err, [results]); + */ +function doWhilst(iteratee, test, callback) { + callback = onlyOnce(callback || noop); + var next = rest(function (err, args) { + if (err) return callback(err); + if (test.apply(this, args)) return iteratee(next); + callback.apply(null, [null].concat(args)); + }); + iteratee(next); +} + +/** + * Like ['doWhilst']{@link module:ControlFlow.doWhilst}, except the `test` is inverted. Note the + * argument ordering differs from `until`. + * + * @name doUntil + * @static + * @memberOf module:ControlFlow + * @method + * @see [async.doWhilst]{@link module:ControlFlow.doWhilst} + * @category Control Flow + * @param {Function} fn - A function which is called each time `test` fails. + * The function is passed a `callback(err)`, which must be called once it has + * completed with an optional `err` argument. Invoked with (callback). + * @param {Function} test - synchronous truth test to perform after each + * execution of `fn`. Invoked with the non-error callback results of `fn`. + * @param {Function} [callback] - A callback which is called after the test + * function has passed and repeated execution of `fn` has stopped. `callback` + * will be passed an error and any arguments passed to the final `fn`'s + * callback. Invoked with (err, [results]); + */ +function doUntil(fn, test, callback) { + doWhilst(fn, function () { + return !test.apply(this, arguments); + }, callback); +} + +/** + * Like [`whilst`]{@link module:ControlFlow.whilst}, except the `test` is an asynchronous function that + * is passed a callback in the form of `function (err, truth)`. If error is + * passed to `test` or `fn`, the main callback is immediately called with the + * value of the error. + * + * @name during + * @static + * @memberOf module:ControlFlow + * @method + * @see [async.whilst]{@link module:ControlFlow.whilst} + * @category Control Flow + * @param {Function} test - asynchronous truth test to perform before each + * execution of `fn`. Invoked with (callback). + * @param {Function} fn - A function which is called each time `test` passes. + * The function is passed a `callback(err)`, which must be called once it has + * completed with an optional `err` argument. Invoked with (callback). + * @param {Function} [callback] - A callback which is called after the test + * function has failed and repeated execution of `fn` has stopped. `callback` + * will be passed an error, if one occured, otherwise `null`. + * @example + * + * var count = 0; + * + * async.during( + * function (callback) { + * return callback(null, count < 5); + * }, + * function (callback) { + * count++; + * setTimeout(callback, 1000); + * }, + * function (err) { + * // 5 seconds have passed + * } + * ); + */ +function during(test, fn, callback) { + callback = onlyOnce(callback || noop); + + function next(err) { + if (err) return callback(err); + test(check); + } + + function check(err, truth) { + if (err) return callback(err); + if (!truth) return callback(null); + fn(next); + } + + test(check); +} + +function _withoutIndex(iteratee) { + return function (value, index, callback) { + return iteratee(value, callback); + }; +} + +/** + * Applies the function `iteratee` to each item in `coll`, in parallel. + * The `iteratee` is called with an item from the list, and a callback for when + * it has finished. If the `iteratee` passes an error to its `callback`, the + * main `callback` (for the `each` function) is immediately called with the + * error. + * + * Note, that since this function applies `iteratee` to each item in parallel, + * there is no guarantee that the iteratee functions will complete in order. + * + * @name each + * @static + * @memberOf module:Collections + * @method + * @alias forEach + * @category Collection + * @param {Array|Iterable|Object} coll - A collection to iterate over. + * @param {Function} iteratee - A function to apply to each item + * in `coll`. The iteratee is passed a `callback(err)` which must be called once + * it has completed. If no error has occurred, the `callback` should be run + * without arguments or with an explicit `null` argument. The array index is not + * passed to the iteratee. Invoked with (item, callback). If you need the index, + * use `eachOf`. + * @param {Function} [callback] - A callback which is called when all + * `iteratee` functions have finished, or an error occurs. Invoked with (err). + * @example + * + * // assuming openFiles is an array of file names and saveFile is a function + * // to save the modified contents of that file: + * + * async.each(openFiles, saveFile, function(err){ + * // if any of the saves produced an error, err would equal that error + * }); + * + * // assuming openFiles is an array of file names + * async.each(openFiles, function(file, callback) { + * + * // Perform operation on file here. + * console.log('Processing file ' + file); + * + * if( file.length > 32 ) { + * console.log('This file name is too long'); + * callback('File name too long'); + * } else { + * // Do work to process file here + * console.log('File processed'); + * callback(); + * } + * }, function(err) { + * // if any of the file processing produced an error, err would equal that error + * if( err ) { + * // One of the iterations produced an error. + * // All processing will now stop. + * console.log('A file failed to process'); + * } else { + * console.log('All files have been processed successfully'); + * } + * }); + */ +function eachLimit(coll, iteratee, callback) { + eachOf(coll, _withoutIndex(iteratee), callback); +} + +/** + * The same as [`each`]{@link module:Collections.each} but runs a maximum of `limit` async operations at a time. + * + * @name eachLimit + * @static + * @memberOf module:Collections + * @method + * @see [async.each]{@link module:Collections.each} + * @alias forEachLimit + * @category Collection + * @param {Array|Iterable|Object} coll - A 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)` which must be called once it has + * completed. If no error has occurred, the `callback` should be run without + * arguments or with an explicit `null` argument. The array index is not passed + * to the iteratee. Invoked with (item, callback). If you need the index, use + * `eachOfLimit`. + * @param {Function} [callback] - A callback which is called when all + * `iteratee` functions have finished, or an error occurs. Invoked with (err). + */ +function eachLimit$1(coll, limit, iteratee, callback) { + _eachOfLimit(limit)(coll, _withoutIndex(iteratee), callback); +} + +/** + * The same as [`each`]{@link module:Collections.each} but runs only a single async operation at a time. + * + * @name eachSeries + * @static + * @memberOf module:Collections + * @method + * @see [async.each]{@link module:Collections.each} + * @alias forEachSeries + * @category Collection + * @param {Array|Iterable|Object} coll - A collection to iterate over. + * @param {Function} iteratee - A function to apply to each + * item in `coll`. The iteratee is passed a `callback(err)` which must be called + * once it has completed. If no error has occurred, the `callback` should be run + * without arguments or with an explicit `null` argument. The array index is + * not passed to the iteratee. Invoked with (item, callback). If you need the + * index, use `eachOfSeries`. + * @param {Function} [callback] - A callback which is called when all + * `iteratee` functions have finished, or an error occurs. Invoked with (err). + */ +var eachSeries = doLimit(eachLimit$1, 1); + +/** + * Wrap an async function and ensure it calls its callback on a later tick of + * the event loop. If the function already calls its callback on a next tick, + * no extra deferral is added. This is useful for preventing stack overflows + * (`RangeError: Maximum call stack size exceeded`) and generally keeping + * [Zalgo](http://blog.izs.me/post/59142742143/designing-apis-for-asynchrony) + * contained. + * + * @name ensureAsync + * @static + * @memberOf module:Utils + * @method + * @category Util + * @param {Function} fn - an async function, one that expects a node-style + * callback as its last argument. + * @returns {Function} Returns a wrapped function with the exact same call + * signature as the function passed in. + * @example + * + * function sometimesAsync(arg, callback) { + * if (cache[arg]) { + * return callback(null, cache[arg]); // this would be synchronous!! + * } else { + * doSomeIO(arg, callback); // this IO would be asynchronous + * } + * } + * + * // this has a risk of stack overflows if many results are cached in a row + * async.mapSeries(args, sometimesAsync, done); + * + * // this will defer sometimesAsync's callback if necessary, + * // preventing stack overflows + * async.mapSeries(args, async.ensureAsync(sometimesAsync), done); + */ +function ensureAsync(fn) { + return initialParams(function (args, callback) { + var sync = true; + args.push(function () { + var innerArgs = arguments; + if (sync) { + setImmediate$1(function () { + callback.apply(null, innerArgs); + }); + } else { + callback.apply(null, innerArgs); + } + }); + fn.apply(this, args); + sync = false; + }); +} + +function notId(v) { + return !v; +} + +/** + * Returns `true` if every element in `coll` satisfies an async test. If any + * iteratee call returns `false`, the main `callback` is immediately called. + * + * @name every + * @static + * @memberOf module:Collections + * @method + * @alias all + * @category Collection + * @param {Array|Iterable|Object} coll - A collection to iterate over. + * @param {Function} iteratee - A truth test to apply to each item in the + * collection in parallel. The iteratee is passed a `callback(err, truthValue)` + * which must be called with a boolean argument once it has completed. Invoked + * with (item, callback). + * @param {Function} [callback] - A callback which is called after all the + * `iteratee` functions have finished. Result will be either `true` or `false` + * depending on the values of the async tests. Invoked with (err, result). + * @example + * + * async.every(['file1','file2','file3'], function(filePath, callback) { + * fs.access(filePath, function(err) { + * callback(null, !err) + * }); + * }, function(err, result) { + * // if result is true then every file exists + * }); + */ +var every = _createTester(eachOf, notId, notId); + +/** + * The same as [`every`]{@link module:Collections.every} but runs a maximum of `limit` async operations at a time. + * + * @name everyLimit + * @static + * @memberOf module:Collections + * @method + * @see [async.every]{@link module:Collections.every} + * @alias allLimit + * @category Collection + * @param {Array|Iterable|Object} coll - A collection to iterate over. + * @param {number} limit - The maximum number of async operations at a time. + * @param {Function} iteratee - A truth test to apply to each item in the + * collection in parallel. The iteratee is passed a `callback(err, truthValue)` + * which must be called with a boolean argument once it has completed. Invoked + * with (item, callback). + * @param {Function} [callback] - A callback which is called after all the + * `iteratee` functions have finished. Result will be either `true` or `false` + * depending on the values of the async tests. Invoked with (err, result). + */ +var everyLimit = _createTester(eachOfLimit, notId, notId); + +/** + * The same as [`every`]{@link module:Collections.every} but runs only a single async operation at a time. + * + * @name everySeries + * @static + * @memberOf module:Collections + * @method + * @see [async.every]{@link module:Collections.every} + * @alias allSeries + * @category Collection + * @param {Array|Iterable|Object} coll - A collection to iterate over. + * @param {Function} iteratee - A truth test to apply to each item in the + * collection in parallel. The iteratee is passed a `callback(err, truthValue)` + * which must be called with a boolean argument once it has completed. Invoked + * with (item, callback). + * @param {Function} [callback] - A callback which is called after all the + * `iteratee` functions have finished. Result will be either `true` or `false` + * depending on the values of the async tests. Invoked with (err, result). + */ +var everySeries = doLimit(everyLimit, 1); + +/** + * The base implementation of `_.property` without support for deep paths. + * + * @private + * @param {string} key The key of the property to get. + * @returns {Function} Returns the new accessor function. + */ +function baseProperty(key) { + return function(object) { + return object == null ? undefined : object[key]; + }; +} + +function filterArray(eachfn, arr, iteratee, callback) { + var truthValues = new Array(arr.length); + eachfn(arr, function (x, index, callback) { + iteratee(x, function (err, v) { + truthValues[index] = !!v; + callback(err); + }); + }, function (err) { + if (err) return callback(err); + var results = []; + for (var i = 0; i < arr.length; i++) { + if (truthValues[i]) results.push(arr[i]); + } + callback(null, results); + }); +} + +function filterGeneric(eachfn, coll, iteratee, callback) { + var results = []; + eachfn(coll, function (x, index, callback) { + iteratee(x, function (err, v) { + if (err) { + callback(err); + } else { + if (v) { + results.push({ index: index, value: x }); + } + callback(); + } + }); + }, function (err) { + if (err) { + callback(err); + } else { + callback(null, arrayMap(results.sort(function (a, b) { + return a.index - b.index; + }), baseProperty('value'))); + } + }); +} + +function _filter(eachfn, coll, iteratee, callback) { + var filter = isArrayLike(coll) ? filterArray : filterGeneric; + filter(eachfn, coll, iteratee, callback || noop); +} + +/** + * Returns a new array of all the values in `coll` which pass an async truth + * test. This operation is performed in parallel, but the results array will be + * in the same order as the original. + * + * @name filter + * @static + * @memberOf module:Collections + * @method + * @alias select + * @category Collection + * @param {Array|Iterable|Object} coll - A collection to iterate over. + * @param {Function} iteratee - A truth test to apply to each item in `coll`. + * The `iteratee` is passed a `callback(err, truthValue)`, which must be called + * with a boolean argument once it has completed. Invoked with (item, callback). + * @param {Function} [callback] - A callback which is called after all the + * `iteratee` functions have finished. Invoked with (err, results). + * @example + * + * async.filter(['file1','file2','file3'], function(filePath, callback) { + * fs.access(filePath, function(err) { + * callback(null, !err) + * }); + * }, function(err, results) { + * // results now equals an array of the existing files + * }); + */ +var filter = doParallel(_filter); + +/** + * The same as [`filter`]{@link module:Collections.filter} but runs a maximum of `limit` async operations at a + * time. + * + * @name filterLimit + * @static + * @memberOf module:Collections + * @method + * @see [async.filter]{@link module:Collections.filter} + * @alias selectLimit + * @category Collection + * @param {Array|Iterable|Object} coll - A collection to iterate over. + * @param {number} limit - The maximum number of async operations at a time. + * @param {Function} iteratee - A truth test to apply to each item in `coll`. + * The `iteratee` is passed a `callback(err, truthValue)`, which must be called + * with a boolean argument once it has completed. Invoked with (item, callback). + * @param {Function} [callback] - A callback which is called after all the + * `iteratee` functions have finished. Invoked with (err, results). + */ +var filterLimit = doParallelLimit(_filter); + +/** + * The same as [`filter`]{@link module:Collections.filter} but runs only a single async operation at a time. + * + * @name filterSeries + * @static + * @memberOf module:Collections + * @method + * @see [async.filter]{@link module:Collections.filter} + * @alias selectSeries + * @category Collection + * @param {Array|Iterable|Object} coll - A collection to iterate over. + * @param {Function} iteratee - A truth test to apply to each item in `coll`. + * The `iteratee` is passed a `callback(err, truthValue)`, which must be called + * with a boolean argument once it has completed. Invoked with (item, callback). + * @param {Function} [callback] - A callback which is called after all the + * `iteratee` functions have finished. Invoked with (err, results) + */ +var filterSeries = doLimit(filterLimit, 1); + +/** + * Calls the asynchronous function `fn` with a callback parameter that allows it + * to call itself again, in series, indefinitely. + + * If an error is passed to the + * callback then `errback` is called with the error, and execution stops, + * otherwise it will never be called. + * + * @name forever + * @static + * @memberOf module:ControlFlow + * @method + * @category Control Flow + * @param {Function} fn - a function to call repeatedly. Invoked with (next). + * @param {Function} [errback] - when `fn` passes an error to it's callback, + * this function will be called, and execution stops. Invoked with (err). + * @example + * + * async.forever( + * function(next) { + * // next is suitable for passing to things that need a callback(err [, whatever]); + * // it will result in this function being called again. + * }, + * function(err) { + * // if next is called with a value in its first parameter, it will appear + * // in here as 'err', and execution will stop. + * } + * ); + */ +function forever(fn, errback) { + var done = onlyOnce(errback || noop); + var task = ensureAsync(fn); + + function next(err) { + if (err) return done(err); + task(next); + } + next(); +} + +/** + * Logs the result of an `async` function to the `console`. Only works in + * Node.js or in browsers that support `console.log` and `console.error` (such + * as FF and Chrome). If multiple arguments are returned from the async + * function, `console.log` is called on each argument in order. + * + * @name log + * @static + * @memberOf module:Utils + * @method + * @category Util + * @param {Function} function - The function you want to eventually apply all + * arguments to. + * @param {...*} arguments... - Any number of arguments to apply to the function. + * @example + * + * // in a module + * var hello = function(name, callback) { + * setTimeout(function() { + * callback(null, 'hello ' + name); + * }, 1000); + * }; + * + * // in the node repl + * node> async.log(hello, 'world'); + * 'hello world' + */ +var log = consoleFunc('log'); + +/** + * The same as [`mapValues`]{@link module:Collections.mapValues} but runs a maximum of `limit` async operations at a + * time. + * + * @name mapValuesLimit + * @static + * @memberOf module:Collections + * @method + * @see [async.mapValues]{@link module:Collections.mapValues} + * @category Collection + * @param {Object} obj - A collection to iterate over. + * @param {number} limit - The maximum number of async operations at a time. + * @param {Function} iteratee - A function to apply to each value in `obj`. + * The iteratee is passed a `callback(err, transformed)` which must be called + * once it has completed with an error (which can be `null`) and a + * transformed value. Invoked with (value, key, callback). + * @param {Function} [callback] - A callback which is called when all `iteratee` + * functions have finished, or an error occurs. `result` is a new object consisting + * of each key from `obj`, with each transformed value on the right-hand side. + * Invoked with (err, result). + */ +function mapValuesLimit(obj, limit, iteratee, callback) { + callback = once(callback || noop); + var newObj = {}; + eachOfLimit(obj, limit, function (val, key, next) { + iteratee(val, key, function (err, result) { + if (err) return next(err); + newObj[key] = result; + next(); + }); + }, function (err) { + callback(err, newObj); + }); +} + +/** + * A relative of [`map`]{@link module:Collections.map}, designed for use with objects. + * + * Produces a new Object by mapping each value of `obj` through the `iteratee` + * function. The `iteratee` is called each `value` and `key` from `obj` and a + * callback for when it has finished processing. Each of these callbacks takes + * two arguments: an `error`, and the transformed item from `obj`. If `iteratee` + * passes an error to its callback, the main `callback` (for the `mapValues` + * function) is immediately called with the error. + * + * Note, the order of the keys in the result is not guaranteed. The keys will + * be roughly in the order they complete, (but this is very engine-specific) + * + * @name mapValues + * @static + * @memberOf module:Collections + * @method + * @category Collection + * @param {Object} obj - A collection to iterate over. + * @param {Function} iteratee - A function to apply to each value and key in + * `coll`. The iteratee is passed a `callback(err, transformed)` which must be + * called once it has completed with an error (which can be `null`) and a + * transformed value. Invoked with (value, key, callback). + * @param {Function} [callback] - A callback which is called when all `iteratee` + * functions have finished, or an error occurs. `result` is a new object consisting + * of each key from `obj`, with each transformed value on the right-hand side. + * Invoked with (err, result). + * @example + * + * async.mapValues({ + * f1: 'file1', + * f2: 'file2', + * f3: 'file3' + * }, function (file, key, callback) { + * fs.stat(file, callback); + * }, function(err, result) { + * // result is now a map of stats for each file, e.g. + * // { + * // f1: [stats for file1], + * // f2: [stats for file2], + * // f3: [stats for file3] + * // } + * }); + */ + +var mapValues = doLimit(mapValuesLimit, Infinity); + +/** + * The same as [`mapValues`]{@link module:Collections.mapValues} but runs only a single async operation at a time. + * + * @name mapValuesSeries + * @static + * @memberOf module:Collections + * @method + * @see [async.mapValues]{@link module:Collections.mapValues} + * @category Collection + * @param {Object} obj - A collection to iterate over. + * @param {Function} iteratee - A function to apply to each value in `obj`. + * The iteratee is passed a `callback(err, transformed)` which must be called + * once it has completed with an error (which can be `null`) and a + * transformed value. Invoked with (value, key, callback). + * @param {Function} [callback] - A callback which is called when all `iteratee` + * functions have finished, or an error occurs. `result` is a new object consisting + * of each key from `obj`, with each transformed value on the right-hand side. + * Invoked with (err, result). + */ +var mapValuesSeries = doLimit(mapValuesLimit, 1); + +function has(obj, key) { + return key in obj; +} + +/** + * Caches the results of an `async` function. When creating a hash to store + * function results against, the callback is omitted from the hash and an + * optional hash function can be used. + * + * If no hash function is specified, the first argument is used as a hash key, + * which may work reasonably if it is a string or a data type that converts to a + * distinct string. Note that objects and arrays will not behave reasonably. + * Neither will cases where the other arguments are significant. In such cases, + * specify your own hash function. + * + * The cache of results is exposed as the `memo` property of the function + * returned by `memoize`. + * + * @name memoize + * @static + * @memberOf module:Utils + * @method + * @category Util + * @param {Function} fn - The function to proxy and cache results from. + * @param {Function} hasher - An optional function for generating a custom hash + * for storing results. It has all the arguments applied to it apart from the + * callback, and must be synchronous. + * @returns {Function} a memoized version of `fn` + * @example + * + * var slow_fn = function(name, callback) { + * // do something + * callback(null, result); + * }; + * var fn = async.memoize(slow_fn); + * + * // fn can now be used as if it were slow_fn + * fn('some name', function() { + * // callback + * }); + */ +function memoize(fn, hasher) { + var memo = Object.create(null); + var queues = Object.create(null); + hasher = hasher || identity; + var memoized = initialParams(function memoized(args, callback) { + var key = hasher.apply(null, args); + if (has(memo, key)) { + setImmediate$1(function () { + callback.apply(null, memo[key]); + }); + } else if (has(queues, key)) { + queues[key].push(callback); + } else { + queues[key] = [callback]; + fn.apply(null, args.concat(rest(function (args) { + memo[key] = args; + var q = queues[key]; + delete queues[key]; + for (var i = 0, l = q.length; i < l; i++) { + q[i].apply(null, args); + } + }))); + } + }); + memoized.memo = memo; + memoized.unmemoized = fn; + return memoized; +} + +/** + * Calls `callback` on a later loop around the event loop. In Node.js this just + * calls `setImmediate`. In the browser it will use `setImmediate` if + * available, otherwise `setTimeout(callback, 0)`, which means other higher + * priority events may precede the execution of `callback`. + * + * This is used internally for browser-compatibility purposes. + * + * @name nextTick + * @static + * @memberOf module:Utils + * @method + * @alias setImmediate + * @category Util + * @param {Function} callback - The function to call on a later loop around + * the event loop. Invoked with (args...). + * @param {...*} args... - any number of additional arguments to pass to the + * callback on the next tick. + * @example + * + * var call_order = []; + * async.nextTick(function() { + * call_order.push('two'); + * // call_order now equals ['one','two'] + * }); + * call_order.push('one'); + * + * async.setImmediate(function (a, b, c) { + * // a, b, and c equal 1, 2, and 3 + * }, 1, 2, 3); + */ +var _defer$1; + +if (hasNextTick) { + _defer$1 = process.nextTick; +} else if (hasSetImmediate) { + _defer$1 = setImmediate; +} else { + _defer$1 = fallback; +} + +var nextTick = wrap(_defer$1); + +function _parallel(eachfn, tasks, callback) { + callback = callback || noop; + var results = isArrayLike(tasks) ? [] : {}; + + eachfn(tasks, function (task, key, callback) { + task(rest(function (err, args) { + if (args.length <= 1) { + args = args[0]; + } + results[key] = args; + callback(err); + })); + }, function (err) { + callback(err, results); + }); +} + +/** + * Run the `tasks` collection of functions in parallel, without waiting until + * the previous function has completed. If any of the functions pass an error to + * its callback, the main `callback` is immediately called with the value of the + * error. Once the `tasks` have completed, the results are passed to the final + * `callback` as an array. + * + * **Note:** `parallel` is about kicking-off I/O tasks in parallel, not about + * parallel execution of code. If your tasks do not use any timers or perform + * any I/O, they will actually be executed in series. Any synchronous setup + * sections for each task will happen one after the other. JavaScript remains + * single-threaded. + * + * It is also possible to use an object instead of an array. Each property will + * be run as a function and the results will be passed to the final `callback` + * as an object instead of an array. This can be a more readable way of handling + * results from {@link async.parallel}. + * + * @name parallel + * @static + * @memberOf module:ControlFlow + * @method + * @category Control Flow + * @param {Array|Iterable|Object} tasks - A collection containing functions to run. + * Each function is passed a `callback(err, result)` which it must call on + * completion with an error `err` (which can be `null`) and an optional `result` + * value. + * @param {Function} [callback] - An optional callback to run once all the + * functions have completed successfully. This function gets a results array + * (or object) containing all the result arguments passed to the task callbacks. + * Invoked with (err, results). + * @example + * async.parallel([ + * function(callback) { + * setTimeout(function() { + * callback(null, 'one'); + * }, 200); + * }, + * function(callback) { + * setTimeout(function() { + * callback(null, 'two'); + * }, 100); + * } + * ], + * // optional callback + * function(err, results) { + * // the results array will equal ['one','two'] even though + * // the second function had a shorter timeout. + * }); + * + * // an example using an object instead of an array + * async.parallel({ + * one: function(callback) { + * setTimeout(function() { + * callback(null, 1); + * }, 200); + * }, + * two: function(callback) { + * setTimeout(function() { + * callback(null, 2); + * }, 100); + * } + * }, function(err, results) { + * // results is now equals to: {one: 1, two: 2} + * }); + */ +function parallelLimit(tasks, callback) { + _parallel(eachOf, tasks, callback); +} + +/** + * The same as [`parallel`]{@link module:ControlFlow.parallel} but runs a maximum of `limit` async operations at a + * time. + * + * @name parallelLimit + * @static + * @memberOf module:ControlFlow + * @method + * @see [async.parallel]{@link module:ControlFlow.parallel} + * @category Control Flow + * @param {Array|Collection} tasks - A collection containing functions to run. + * Each function is passed a `callback(err, result)` which it must call on + * completion with an error `err` (which can be `null`) and an optional `result` + * value. + * @param {number} limit - The maximum number of async operations at a time. + * @param {Function} [callback] - An optional callback to run once all the + * functions have completed successfully. This function gets a results array + * (or object) containing all the result arguments passed to the task callbacks. + * Invoked with (err, results). + */ +function parallelLimit$1(tasks, limit, callback) { + _parallel(_eachOfLimit(limit), tasks, callback); +} + +/** + * A queue of tasks for the worker function to complete. + * @typedef {Object} QueueObject + * @memberOf module:ControlFlow + * @property {Function} length - a function returning the number of items + * waiting to be processed. Invoke with `queue.length()`. + * @property {boolean} started - a boolean indicating whether or not any + * items have been pushed and processed by the queue. + * @property {Function} running - a function returning the number of items + * currently being processed. Invoke with `queue.running()`. + * @property {Function} workersList - a function returning the array of items + * currently being processed. Invoke with `queue.workersList()`. + * @property {Function} idle - a function returning false if there are items + * waiting or being processed, or true if not. Invoke with `queue.idle()`. + * @property {number} concurrency - an integer for determining how many `worker` + * functions should be run in parallel. This property can be changed after a + * `queue` is created to alter the concurrency on-the-fly. + * @property {Function} push - add a new task to the `queue`. Calls `callback` + * once the `worker` has finished processing the task. Instead of a single task, + * a `tasks` array can be submitted. The respective callback is used for every + * task in the list. Invoke with `queue.push(task, [callback])`, + * @property {Function} unshift - add a new task to the front of the `queue`. + * Invoke with `queue.unshift(task, [callback])`. + * @property {Function} saturated - a callback that is called when the number of + * running workers hits the `concurrency` limit, and further tasks will be + * queued. + * @property {Function} unsaturated - a callback that is called when the number + * of running workers is less than the `concurrency` & `buffer` limits, and + * further tasks will not be queued. + * @property {number} buffer - A minimum threshold buffer in order to say that + * the `queue` is `unsaturated`. + * @property {Function} empty - a callback that is called when the last item + * from the `queue` is given to a `worker`. + * @property {Function} drain - a callback that is called when the last item + * from the `queue` has returned from the `worker`. + * @property {Function} error - a callback that is called when a task errors. + * Has the signature `function(error, task)`. + * @property {boolean} paused - a boolean for determining whether the queue is + * in a paused state. + * @property {Function} pause - a function that pauses the processing of tasks + * until `resume()` is called. Invoke with `queue.pause()`. + * @property {Function} resume - a function that resumes the processing of + * queued tasks when the queue is paused. Invoke with `queue.resume()`. + * @property {Function} kill - a function that removes the `drain` callback and + * empties remaining tasks from the queue forcing it to go idle. Invoke with `queue.kill()`. + */ + +/** + * Creates a `queue` object with the specified `concurrency`. Tasks added to the + * `queue` are processed in parallel (up to the `concurrency` limit). If all + * `worker`s are in progress, the task is queued until one becomes available. + * Once a `worker` completes a `task`, that `task`'s callback is called. + * + * @name queue + * @static + * @memberOf module:ControlFlow + * @method + * @category Control Flow + * @param {Function} worker - An asynchronous function for processing a queued + * task, which must call its `callback(err)` argument when finished, with an + * optional `error` as an argument. If you want to handle errors from an + * individual task, pass a callback to `q.push()`. Invoked with + * (task, callback). + * @param {number} [concurrency=1] - An `integer` for determining how many + * `worker` functions should be run in parallel. If omitted, the concurrency + * defaults to `1`. If the concurrency is `0`, an error is thrown. + * @returns {module:ControlFlow.QueueObject} A queue object to manage the tasks. Callbacks can + * attached as certain properties to listen for specific events during the + * lifecycle of the queue. + * @example + * + * // create a queue object with concurrency 2 + * var q = async.queue(function(task, callback) { + * console.log('hello ' + task.name); + * callback(); + * }, 2); + * + * // assign a callback + * q.drain = function() { + * console.log('all items have been processed'); + * }; + * + * // add some items to the queue + * q.push({name: 'foo'}, function(err) { + * console.log('finished processing foo'); + * }); + * q.push({name: 'bar'}, function (err) { + * console.log('finished processing bar'); + * }); + * + * // add some items to the queue (batch-wise) + * q.push([{name: 'baz'},{name: 'bay'},{name: 'bax'}], function(err) { + * console.log('finished processing item'); + * }); + * + * // add some items to the front of the queue + * q.unshift({name: 'bar'}, function (err) { + * console.log('finished processing bar'); + * }); + */ +var queue$1 = function (worker, concurrency) { + return queue(function (items, cb) { + worker(items[0], cb); + }, concurrency, 1); +}; + +/** + * The same as [async.queue]{@link module:ControlFlow.queue} only tasks are assigned a priority and + * completed in ascending priority order. + * + * @name priorityQueue + * @static + * @memberOf module:ControlFlow + * @method + * @see [async.queue]{@link module:ControlFlow.queue} + * @category Control Flow + * @param {Function} worker - An asynchronous function for processing a queued + * task, which must call its `callback(err)` argument when finished, with an + * optional `error` as an argument. If you want to handle errors from an + * individual task, pass a callback to `q.push()`. Invoked with + * (task, callback). + * @param {number} concurrency - An `integer` for determining how many `worker` + * functions should be run in parallel. If omitted, the concurrency defaults to + * `1`. If the concurrency is `0`, an error is thrown. + * @returns {module:ControlFlow.QueueObject} A priorityQueue object to manage the tasks. There are two + * differences between `queue` and `priorityQueue` objects: + * * `push(task, priority, [callback])` - `priority` should be a number. If an + * array of `tasks` is given, all tasks will be assigned the same priority. + * * The `unshift` method was removed. + */ +var priorityQueue = function (worker, concurrency) { + // Start with a normal queue + var q = queue$1(worker, concurrency); + + // Override push to accept second parameter representing priority + q.push = function (data, priority, callback) { + if (callback == null) callback = noop; + if (typeof callback !== 'function') { + throw new Error('task callback must be a function'); + } + q.started = true; + if (!isArray(data)) { + data = [data]; + } + if (data.length === 0) { + // call drain immediately if there are no tasks + return setImmediate$1(function () { + q.drain(); + }); + } + + priority = priority || 0; + var nextNode = q._tasks.head; + while (nextNode && priority >= nextNode.priority) { + nextNode = nextNode.next; + } + + for (var i = 0, l = data.length; i < l; i++) { + var item = { + data: data[i], + priority: priority, + callback: callback + }; + + if (nextNode) { + q._tasks.insertBefore(nextNode, item); + } else { + q._tasks.push(item); + } + } + setImmediate$1(q.process); + }; + + // Remove unshift function + delete q.unshift; + + return q; +}; + +/** + * Runs the `tasks` array of functions in parallel, without waiting until the + * previous function has completed. Once any of the `tasks` complete or pass an + * error to its callback, the main `callback` is immediately called. It's + * equivalent to `Promise.race()`. + * + * @name race + * @static + * @memberOf module:ControlFlow + * @method + * @category Control Flow + * @param {Array} tasks - An array containing functions to run. Each function + * is passed a `callback(err, result)` which it must call on completion with an + * error `err` (which can be `null`) and an optional `result` value. + * @param {Function} callback - A callback to run once any of the functions have + * completed. This function gets an error or result from the first function that + * completed. Invoked with (err, result). + * @returns undefined + * @example + * + * async.race([ + * function(callback) { + * setTimeout(function() { + * callback(null, 'one'); + * }, 200); + * }, + * function(callback) { + * setTimeout(function() { + * callback(null, 'two'); + * }, 100); + * } + * ], + * // main callback + * function(err, result) { + * // the result will be equal to 'two' as it finishes earlier + * }); + */ +function race(tasks, callback) { + callback = once(callback || noop); + if (!isArray(tasks)) return callback(new TypeError('First argument to race must be an array of functions')); + if (!tasks.length) return callback(); + for (var i = 0, l = tasks.length; i < l; i++) { + tasks[i](callback); + } +} + +var slice = Array.prototype.slice; + +/** + * Same as [`reduce`]{@link module:Collections.reduce}, only operates on `array` in reverse order. + * + * @name reduceRight + * @static + * @memberOf module:Collections + * @method + * @see [async.reduce]{@link module:Collections.reduce} + * @alias foldr + * @category Collection + * @param {Array} array - A collection to iterate over. + * @param {*} memo - The initial state of the reduction. + * @param {Function} iteratee - A function applied to each item in the + * array to produce the next step in the reduction. The `iteratee` is passed a + * `callback(err, reduction)` which accepts an optional error as its first + * argument, and the state of the reduction as the second. If an error is + * passed to the callback, the reduction is stopped and the main `callback` is + * immediately called with the error. Invoked with (memo, item, callback). + * @param {Function} [callback] - A callback which is called after all the + * `iteratee` functions have finished. Result is the reduced value. Invoked with + * (err, result). + */ +function reduceRight(array, memo, iteratee, callback) { + var reversed = slice.call(array).reverse(); + reduce(reversed, memo, iteratee, callback); +} + +/** + * Wraps the function in another function that always returns data even when it + * errors. + * + * The object returned has either the property `error` or `value`. + * + * @name reflect + * @static + * @memberOf module:Utils + * @method + * @category Util + * @param {Function} fn - The function you want to wrap + * @returns {Function} - A function that always passes null to it's callback as + * the error. The second argument to the callback will be an `object` with + * either an `error` or a `value` property. + * @example + * + * async.parallel([ + * async.reflect(function(callback) { + * // do some stuff ... + * callback(null, 'one'); + * }), + * async.reflect(function(callback) { + * // do some more stuff but error ... + * callback('bad stuff happened'); + * }), + * async.reflect(function(callback) { + * // do some more stuff ... + * callback(null, 'two'); + * }) + * ], + * // optional callback + * function(err, results) { + * // values + * // results[0].value = 'one' + * // results[1].error = 'bad stuff happened' + * // results[2].value = 'two' + * }); + */ +function reflect(fn) { + return initialParams(function reflectOn(args, reflectCallback) { + args.push(rest(function callback(err, cbArgs) { + if (err) { + reflectCallback(null, { + error: err + }); + } else { + var value = null; + if (cbArgs.length === 1) { + value = cbArgs[0]; + } else if (cbArgs.length > 1) { + value = cbArgs; + } + reflectCallback(null, { + value: value + }); + } + })); + + return fn.apply(this, args); + }); +} + +function reject$1(eachfn, arr, iteratee, callback) { + _filter(eachfn, arr, function (value, cb) { + iteratee(value, function (err, v) { + cb(err, !v); + }); + }, callback); +} + +/** + * The opposite of [`filter`]{@link module:Collections.filter}. Removes values that pass an `async` truth test. + * + * @name reject + * @static + * @memberOf module:Collections + * @method + * @see [async.filter]{@link module:Collections.filter} + * @category Collection + * @param {Array|Iterable|Object} coll - A collection to iterate over. + * @param {Function} iteratee - A truth test to apply to each item in `coll`. + * The `iteratee` is passed a `callback(err, truthValue)`, which must be called + * with a boolean argument once it has completed. Invoked with (item, callback). + * @param {Function} [callback] - A callback which is called after all the + * `iteratee` functions have finished. Invoked with (err, results). + * @example + * + * async.reject(['file1','file2','file3'], function(filePath, callback) { + * fs.access(filePath, function(err) { + * callback(null, !err) + * }); + * }, function(err, results) { + * // results now equals an array of missing files + * createFiles(results); + * }); + */ +var reject = doParallel(reject$1); + +/** + * A helper function that wraps an array or an object of functions with reflect. + * + * @name reflectAll + * @static + * @memberOf module:Utils + * @method + * @see [async.reflect]{@link module:Utils.reflect} + * @category Util + * @param {Array} tasks - The array of functions to wrap in `async.reflect`. + * @returns {Array} Returns an array of functions, each function wrapped in + * `async.reflect` + * @example + * + * let tasks = [ + * function(callback) { + * setTimeout(function() { + * callback(null, 'one'); + * }, 200); + * }, + * function(callback) { + * // do some more stuff but error ... + * callback(new Error('bad stuff happened')); + * }, + * function(callback) { + * setTimeout(function() { + * callback(null, 'two'); + * }, 100); + * } + * ]; + * + * async.parallel(async.reflectAll(tasks), + * // optional callback + * function(err, results) { + * // values + * // results[0].value = 'one' + * // results[1].error = Error('bad stuff happened') + * // results[2].value = 'two' + * }); + * + * // an example using an object instead of an array + * let tasks = { + * one: function(callback) { + * setTimeout(function() { + * callback(null, 'one'); + * }, 200); + * }, + * two: function(callback) { + * callback('two'); + * }, + * three: function(callback) { + * setTimeout(function() { + * callback(null, 'three'); + * }, 100); + * } + * }; + * + * async.parallel(async.reflectAll(tasks), + * // optional callback + * function(err, results) { + * // values + * // results.one.value = 'one' + * // results.two.error = 'two' + * // results.three.value = 'three' + * }); + */ +function reflectAll(tasks) { + var results; + if (isArray(tasks)) { + results = arrayMap(tasks, reflect); + } else { + results = {}; + baseForOwn(tasks, function (task, key) { + results[key] = reflect.call(this, task); + }); + } + return results; +} + +/** + * The same as [`reject`]{@link module:Collections.reject} but runs a maximum of `limit` async operations at a + * time. + * + * @name rejectLimit + * @static + * @memberOf module:Collections + * @method + * @see [async.reject]{@link module:Collections.reject} + * @category Collection + * @param {Array|Iterable|Object} coll - A collection to iterate over. + * @param {number} limit - The maximum number of async operations at a time. + * @param {Function} iteratee - A truth test to apply to each item in `coll`. + * The `iteratee` is passed a `callback(err, truthValue)`, which must be called + * with a boolean argument once it has completed. Invoked with (item, callback). + * @param {Function} [callback] - A callback which is called after all the + * `iteratee` functions have finished. Invoked with (err, results). + */ +var rejectLimit = doParallelLimit(reject$1); + +/** + * The same as [`reject`]{@link module:Collections.reject} but runs only a single async operation at a time. + * + * @name rejectSeries + * @static + * @memberOf module:Collections + * @method + * @see [async.reject]{@link module:Collections.reject} + * @category Collection + * @param {Array|Iterable|Object} coll - A collection to iterate over. + * @param {Function} iteratee - A truth test to apply to each item in `coll`. + * The `iteratee` is passed a `callback(err, truthValue)`, which must be called + * with a boolean argument once it has completed. Invoked with (item, callback). + * @param {Function} [callback] - A callback which is called after all the + * `iteratee` functions have finished. Invoked with (err, results). + */ +var rejectSeries = doLimit(rejectLimit, 1); + +/** + * Creates a function that returns `value`. + * + * @static + * @memberOf _ + * @since 2.4.0 + * @category Util + * @param {*} value The value to return from the new function. + * @returns {Function} Returns the new constant function. + * @example + * + * var objects = _.times(2, _.constant({ 'a': 1 })); + * + * console.log(objects); + * // => [{ 'a': 1 }, { 'a': 1 }] + * + * console.log(objects[0] === objects[1]); + * // => true + */ +function constant$1(value) { + return function() { + return value; + }; +} + +/** + * Attempts to get a successful response from `task` no more than `times` times + * before returning an error. If the task is successful, the `callback` will be + * passed the result of the successful task. If all attempts fail, the callback + * will be passed the error and result (if any) of the final attempt. + * + * @name retry + * @static + * @memberOf module:ControlFlow + * @method + * @category Control Flow + * @param {Object|number} [opts = {times: 5, interval: 0}| 5] - Can be either an + * object with `times` and `interval` or a number. + * * `times` - The number of attempts to make before giving up. The default + * is `5`. + * * `interval` - The time to wait between retries, in milliseconds. The + * default is `0`. The interval may also be specified as a function of the + * retry count (see example). + * * `errorFilter` - An optional synchronous function that is invoked on + * erroneous result. If it returns `true` the retry attempts will continue; + * if the function returns `false` the retry flow is aborted with the current + * attempt's error and result being returned to the final callback. + * Invoked with (err). + * * If `opts` is a number, the number specifies the number of times to retry, + * with the default interval of `0`. + * @param {Function} task - A function which receives two arguments: (1) a + * `callback(err, result)` which must be called when finished, passing `err` + * (which can be `null`) and the `result` of the function's execution, and (2) + * a `results` object, containing the results of the previously executed + * functions (if nested inside another control flow). Invoked with + * (callback, results). + * @param {Function} [callback] - An optional callback which is called when the + * task has succeeded, or after the final failed attempt. It receives the `err` + * and `result` arguments of the last attempt at completing the `task`. Invoked + * with (err, results). + * @example + * + * // The `retry` function can be used as a stand-alone control flow by passing + * // a callback, as shown below: + * + * // try calling apiMethod 3 times + * async.retry(3, apiMethod, function(err, result) { + * // do something with the result + * }); + * + * // try calling apiMethod 3 times, waiting 200 ms between each retry + * async.retry({times: 3, interval: 200}, apiMethod, function(err, result) { + * // do something with the result + * }); + * + * // try calling apiMethod 10 times with exponential backoff + * // (i.e. intervals of 100, 200, 400, 800, 1600, ... milliseconds) + * async.retry({ + * times: 10, + * interval: function(retryCount) { + * return 50 * Math.pow(2, retryCount); + * } + * }, apiMethod, function(err, result) { + * // do something with the result + * }); + * + * // try calling apiMethod the default 5 times no delay between each retry + * async.retry(apiMethod, function(err, result) { + * // do something with the result + * }); + * + * // try calling apiMethod only when error condition satisfies, all other + * // errors will abort the retry control flow and return to final callback + * async.retry({ + * errorFilter: function(err) { + * return err.message === 'Temporary error'; // only retry on a specific error + * } + * }, apiMethod, function(err, result) { + * // do something with the result + * }); + * + * // It can also be embedded within other control flow functions to retry + * // individual methods that are not as reliable, like this: + * async.auto({ + * users: api.getUsers.bind(api), + * payments: async.retry(3, api.getPayments.bind(api)) + * }, function(err, results) { + * // do something with the results + * }); + * + */ +function retry(opts, task, callback) { + var DEFAULT_TIMES = 5; + var DEFAULT_INTERVAL = 0; + + var options = { + times: DEFAULT_TIMES, + intervalFunc: constant$1(DEFAULT_INTERVAL) + }; + + function parseTimes(acc, t) { + if (typeof t === 'object') { + acc.times = +t.times || DEFAULT_TIMES; + + acc.intervalFunc = typeof t.interval === 'function' ? t.interval : constant$1(+t.interval || DEFAULT_INTERVAL); + + acc.errorFilter = t.errorFilter; + } else if (typeof t === 'number' || typeof t === 'string') { + acc.times = +t || DEFAULT_TIMES; + } else { + throw new Error("Invalid arguments for async.retry"); + } + } + + if (arguments.length < 3 && typeof opts === 'function') { + callback = task || noop; + task = opts; + } else { + parseTimes(options, opts); + callback = callback || noop; + } + + if (typeof task !== 'function') { + throw new Error("Invalid arguments for async.retry"); + } + + var attempt = 1; + function retryAttempt() { + task(function (err) { + if (err && attempt++ < options.times && (typeof options.errorFilter != 'function' || options.errorFilter(err))) { + setTimeout(retryAttempt, options.intervalFunc(attempt)); + } else { + callback.apply(null, arguments); + } + }); + } + + retryAttempt(); +} + +/** + * A close relative of [`retry`]{@link module:ControlFlow.retry}. This method wraps a task and makes it + * retryable, rather than immediately calling it with retries. + * + * @name retryable + * @static + * @memberOf module:ControlFlow + * @method + * @see [async.retry]{@link module:ControlFlow.retry} + * @category Control Flow + * @param {Object|number} [opts = {times: 5, interval: 0}| 5] - optional + * options, exactly the same as from `retry` + * @param {Function} task - the asynchronous function to wrap + * @returns {Functions} The wrapped function, which when invoked, will retry on + * an error, based on the parameters specified in `opts`. + * @example + * + * async.auto({ + * dep1: async.retryable(3, getFromFlakyService), + * process: ["dep1", async.retryable(3, function (results, cb) { + * maybeProcessData(results.dep1, cb); + * })] + * }, callback); + */ +var retryable = function (opts, task) { + if (!task) { + task = opts; + opts = null; + } + return initialParams(function (args, callback) { + function taskFn(cb) { + task.apply(null, args.concat(cb)); + } + + if (opts) retry(opts, taskFn, callback);else retry(taskFn, callback); + }); +}; + +/** + * Run the functions in the `tasks` collection in series, each one running once + * the previous function has completed. If any functions in the series pass an + * error to its callback, no more functions are run, and `callback` is + * immediately called with the value of the error. Otherwise, `callback` + * receives an array of results when `tasks` have completed. + * + * It is also possible to use an object instead of an array. Each property will + * be run as a function, and the results will be passed to the final `callback` + * as an object instead of an array. This can be a more readable way of handling + * results from {@link async.series}. + * + * **Note** that while many implementations preserve the order of object + * properties, the [ECMAScript Language Specification](http://www.ecma-international.org/ecma-262/5.1/#sec-8.6) + * explicitly states that + * + * > The mechanics and order of enumerating the properties is not specified. + * + * So if you rely on the order in which your series of functions are executed, + * and want this to work on all platforms, consider using an array. + * + * @name series + * @static + * @memberOf module:ControlFlow + * @method + * @category Control Flow + * @param {Array|Iterable|Object} tasks - A collection containing functions to run, each + * function is passed a `callback(err, result)` it must call on completion with + * an error `err` (which can be `null`) and an optional `result` value. + * @param {Function} [callback] - An optional callback to run once all the + * functions have completed. This function gets a results array (or object) + * containing all the result arguments passed to the `task` callbacks. Invoked + * with (err, result). + * @example + * async.series([ + * function(callback) { + * // do some stuff ... + * callback(null, 'one'); + * }, + * function(callback) { + * // do some more stuff ... + * callback(null, 'two'); + * } + * ], + * // optional callback + * function(err, results) { + * // results is now equal to ['one', 'two'] + * }); + * + * async.series({ + * one: function(callback) { + * setTimeout(function() { + * callback(null, 1); + * }, 200); + * }, + * two: function(callback){ + * setTimeout(function() { + * callback(null, 2); + * }, 100); + * } + * }, function(err, results) { + * // results is now equal to: {one: 1, two: 2} + * }); + */ +function series(tasks, callback) { + _parallel(eachOfSeries, tasks, callback); +} + +/** + * Returns `true` if at least one element in the `coll` satisfies an async test. + * If any iteratee call returns `true`, the main `callback` is immediately + * called. + * + * @name some + * @static + * @memberOf module:Collections + * @method + * @alias any + * @category Collection + * @param {Array|Iterable|Object} coll - A collection to iterate over. + * @param {Function} iteratee - A truth test to apply to each item in the array + * in parallel. The iteratee is passed a `callback(err, truthValue)` which must + * be called with a boolean argument once it has completed. Invoked with + * (item, callback). + * @param {Function} [callback] - A callback which is called as soon as any + * iteratee returns `true`, or after all the iteratee functions have finished. + * Result will be either `true` or `false` depending on the values of the async + * tests. Invoked with (err, result). + * @example + * + * async.some(['file1','file2','file3'], function(filePath, callback) { + * fs.access(filePath, function(err) { + * callback(null, !err) + * }); + * }, function(err, result) { + * // if result is true then at least one of the files exists + * }); + */ +var some = _createTester(eachOf, Boolean, identity); + +/** + * The same as [`some`]{@link module:Collections.some} but runs a maximum of `limit` async operations at a time. + * + * @name someLimit + * @static + * @memberOf module:Collections + * @method + * @see [async.some]{@link module:Collections.some} + * @alias anyLimit + * @category Collection + * @param {Array|Iterable|Object} coll - A collection to iterate over. + * @param {number} limit - The maximum number of async operations at a time. + * @param {Function} iteratee - A truth test to apply to each item in the array + * in parallel. The iteratee is passed a `callback(err, truthValue)` which must + * be called with a boolean argument once it has completed. Invoked with + * (item, callback). + * @param {Function} [callback] - A callback which is called as soon as any + * iteratee returns `true`, or after all the iteratee functions have finished. + * Result will be either `true` or `false` depending on the values of the async + * tests. Invoked with (err, result). + */ +var someLimit = _createTester(eachOfLimit, Boolean, identity); + +/** + * The same as [`some`]{@link module:Collections.some} but runs only a single async operation at a time. + * + * @name someSeries + * @static + * @memberOf module:Collections + * @method + * @see [async.some]{@link module:Collections.some} + * @alias anySeries + * @category Collection + * @param {Array|Iterable|Object} coll - A collection to iterate over. + * @param {Function} iteratee - A truth test to apply to each item in the array + * in parallel. The iteratee is passed a `callback(err, truthValue)` which must + * be called with a boolean argument once it has completed. Invoked with + * (item, callback). + * @param {Function} [callback] - A callback which is called as soon as any + * iteratee returns `true`, or after all the iteratee functions have finished. + * Result will be either `true` or `false` depending on the values of the async + * tests. Invoked with (err, result). + */ +var someSeries = doLimit(someLimit, 1); + +/** + * Sorts a list by the results of running each `coll` value through an async + * `iteratee`. + * + * @name sortBy + * @static + * @memberOf module:Collections + * @method + * @category Collection + * @param {Array|Iterable|Object} coll - A collection to iterate over. + * @param {Function} iteratee - A function to apply to each item in `coll`. + * The iteratee is passed a `callback(err, sortValue)` which must be called once + * it has completed with an error (which can be `null`) and a value to use as + * the sort criteria. Invoked with (item, callback). + * @param {Function} callback - A callback which is called after all the + * `iteratee` functions have finished, or an error occurs. Results is the items + * from the original `coll` sorted by the values returned by the `iteratee` + * calls. Invoked with (err, results). + * @example + * + * async.sortBy(['file1','file2','file3'], function(file, callback) { + * fs.stat(file, function(err, stats) { + * callback(err, stats.mtime); + * }); + * }, function(err, results) { + * // results is now the original array of files sorted by + * // modified date + * }); + * + * // By modifying the callback parameter the + * // sorting order can be influenced: + * + * // ascending order + * async.sortBy([1,9,3,5], function(x, callback) { + * callback(null, x); + * }, function(err,result) { + * // result callback + * }); + * + * // descending order + * async.sortBy([1,9,3,5], function(x, callback) { + * callback(null, x*-1); //<- x*-1 instead of x, turns the order around + * }, function(err,result) { + * // result callback + * }); + */ +function sortBy(coll, iteratee, callback) { + map(coll, function (x, callback) { + iteratee(x, function (err, criteria) { + if (err) return callback(err); + callback(null, { value: x, criteria: criteria }); + }); + }, function (err, results) { + if (err) return callback(err); + callback(null, arrayMap(results.sort(comparator), baseProperty('value'))); + }); + + function comparator(left, right) { + var a = left.criteria, + b = right.criteria; + return a < b ? -1 : a > b ? 1 : 0; + } +} + +/** + * Sets a time limit on an asynchronous function. If the function does not call + * its callback within the specified milliseconds, it will be called with a + * timeout error. The code property for the error object will be `'ETIMEDOUT'`. + * + * @name timeout + * @static + * @memberOf module:Utils + * @method + * @category Util + * @param {Function} asyncFn - The asynchronous function you want to set the + * time limit. + * @param {number} milliseconds - The specified time limit. + * @param {*} [info] - Any variable you want attached (`string`, `object`, etc) + * to timeout Error for more information.. + * @returns {Function} Returns a wrapped function that can be used with any of + * the control flow functions. Invoke this function with the same + * parameters as you would `asyncFunc`. + * @example + * + * function myFunction(foo, callback) { + * doAsyncTask(foo, function(err, data) { + * // handle errors + * if (err) return callback(err); + * + * // do some stuff ... + * + * // return processed data + * return callback(null, data); + * }); + * } + * + * var wrapped = async.timeout(myFunction, 1000); + * + * // call `wrapped` as you would `myFunction` + * wrapped({ bar: 'bar' }, function(err, data) { + * // if `myFunction` takes < 1000 ms to execute, `err` + * // and `data` will have their expected values + * + * // else `err` will be an Error with the code 'ETIMEDOUT' + * }); + */ +function timeout(asyncFn, milliseconds, info) { + var originalCallback, timer; + var timedOut = false; + + function injectedCallback() { + if (!timedOut) { + originalCallback.apply(null, arguments); + clearTimeout(timer); + } + } + + function timeoutCallback() { + var name = asyncFn.name || 'anonymous'; + var error = new Error('Callback function "' + name + '" timed out.'); + error.code = 'ETIMEDOUT'; + if (info) { + error.info = info; + } + timedOut = true; + originalCallback(error); + } + + return initialParams(function (args, origCallback) { + originalCallback = origCallback; + // setup timer and call original function + timer = setTimeout(timeoutCallback, milliseconds); + asyncFn.apply(null, args.concat(injectedCallback)); + }); +} + +/* Built-in method references for those with the same name as other `lodash` methods. */ +var nativeCeil = Math.ceil; +var nativeMax$1 = Math.max; + +/** + * The base implementation of `_.range` and `_.rangeRight` which doesn't + * coerce arguments. + * + * @private + * @param {number} start The start of the range. + * @param {number} end The end of the range. + * @param {number} step The value to increment or decrement by. + * @param {boolean} [fromRight] Specify iterating from right to left. + * @returns {Array} Returns the range of numbers. + */ +function baseRange(start, end, step, fromRight) { + var index = -1, + length = nativeMax$1(nativeCeil((end - start) / (step || 1)), 0), + result = Array(length); + + while (length--) { + result[fromRight ? length : ++index] = start; + start += step; + } + return result; +} + +/** + * The same as [times]{@link module:ControlFlow.times} but runs a maximum of `limit` async operations at a + * time. + * + * @name timesLimit + * @static + * @memberOf module:ControlFlow + * @method + * @see [async.times]{@link module:ControlFlow.times} + * @category Control Flow + * @param {number} count - The number of times to run the function. + * @param {number} limit - The maximum number of async operations at a time. + * @param {Function} iteratee - The function to call `n` times. Invoked with the + * iteration index and a callback (n, next). + * @param {Function} callback - see [async.map]{@link module:Collections.map}. + */ +function timeLimit(count, limit, iteratee, callback) { + mapLimit(baseRange(0, count, 1), limit, iteratee, callback); +} + +/** + * Calls the `iteratee` function `n` times, and accumulates results in the same + * manner you would use with [map]{@link module:Collections.map}. + * + * @name times + * @static + * @memberOf module:ControlFlow + * @method + * @see [async.map]{@link module:Collections.map} + * @category Control Flow + * @param {number} n - The number of times to run the function. + * @param {Function} iteratee - The function to call `n` times. Invoked with the + * iteration index and a callback (n, next). + * @param {Function} callback - see {@link module:Collections.map}. + * @example + * + * // Pretend this is some complicated async factory + * var createUser = function(id, callback) { + * callback(null, { + * id: 'user' + id + * }); + * }; + * + * // generate 5 users + * async.times(5, function(n, next) { + * createUser(n, function(err, user) { + * next(err, user); + * }); + * }, function(err, users) { + * // we should now have 5 users + * }); + */ +var times = doLimit(timeLimit, Infinity); + +/** + * The same as [times]{@link module:ControlFlow.times} but runs only a single async operation at a time. + * + * @name timesSeries + * @static + * @memberOf module:ControlFlow + * @method + * @see [async.times]{@link module:ControlFlow.times} + * @category Control Flow + * @param {number} n - The number of times to run the function. + * @param {Function} iteratee - The function to call `n` times. Invoked with the + * iteration index and a callback (n, next). + * @param {Function} callback - see {@link module:Collections.map}. + */ +var timesSeries = doLimit(timeLimit, 1); + +/** + * A relative of `reduce`. Takes an Object or Array, and iterates over each + * element in series, each step potentially mutating an `accumulator` value. + * The type of the accumulator defaults to the type of collection passed in. + * + * @name transform + * @static + * @memberOf module:Collections + * @method + * @category Collection + * @param {Array|Iterable|Object} coll - A collection to iterate over. + * @param {*} [accumulator] - The initial state of the transform. If omitted, + * it will default to an empty Object or Array, depending on the type of `coll` + * @param {Function} iteratee - A function applied to each item in the + * collection that potentially modifies the accumulator. The `iteratee` is + * passed a `callback(err)` which accepts an optional error as its first + * argument. If an error is passed to the callback, the transform is stopped + * and the main `callback` is immediately called with the error. + * Invoked with (accumulator, item, key, callback). + * @param {Function} [callback] - A callback which is called after all the + * `iteratee` functions have finished. Result is the transformed accumulator. + * Invoked with (err, result). + * @example + * + * async.transform([1,2,3], function(acc, item, index, callback) { + * // pointless async: + * process.nextTick(function() { + * acc.push(item * 2) + * callback(null) + * }); + * }, function(err, result) { + * // result is now equal to [2, 4, 6] + * }); + * + * @example + * + * async.transform({a: 1, b: 2, c: 3}, function (obj, val, key, callback) { + * setImmediate(function () { + * obj[key] = val * 2; + * callback(); + * }) + * }, function (err, result) { + * // result is equal to {a: 2, b: 4, c: 6} + * }) + */ +function transform(coll, accumulator, iteratee, callback) { + if (arguments.length === 3) { + callback = iteratee; + iteratee = accumulator; + accumulator = isArray(coll) ? [] : {}; + } + callback = once(callback || noop); + + eachOf(coll, function (v, k, cb) { + iteratee(accumulator, v, k, cb); + }, function (err) { + callback(err, accumulator); + }); +} + +/** + * Undoes a [memoize]{@link module:Utils.memoize}d function, reverting it to the original, + * unmemoized form. Handy for testing. + * + * @name unmemoize + * @static + * @memberOf module:Utils + * @method + * @see [async.memoize]{@link module:Utils.memoize} + * @category Util + * @param {Function} fn - the memoized function + * @returns {Function} a function that calls the original unmemoized function + */ +function unmemoize(fn) { + return function () { + return (fn.unmemoized || fn).apply(null, arguments); + }; +} + +/** + * Repeatedly call `iteratee`, while `test` returns `true`. Calls `callback` when + * stopped, or an error occurs. + * + * @name whilst + * @static + * @memberOf module:ControlFlow + * @method + * @category Control Flow + * @param {Function} test - synchronous truth test to perform before each + * execution of `iteratee`. Invoked with (). + * @param {Function} iteratee - A function which is called each time `test` passes. + * The function is passed a `callback(err)`, which must be called once it has + * completed with an optional `err` argument. Invoked with (callback). + * @param {Function} [callback] - A callback which is called after the test + * function has failed and repeated execution of `iteratee` has stopped. `callback` + * will be passed an error and any arguments passed to the final `iteratee`'s + * callback. Invoked with (err, [results]); + * @returns undefined + * @example + * + * var count = 0; + * async.whilst( + * function() { return count < 5; }, + * function(callback) { + * count++; + * setTimeout(function() { + * callback(null, count); + * }, 1000); + * }, + * function (err, n) { + * // 5 seconds have passed, n = 5 + * } + * ); + */ +function whilst(test, iteratee, callback) { + callback = onlyOnce(callback || noop); + if (!test()) return callback(null); + var next = rest(function (err, args) { + if (err) return callback(err); + if (test()) return iteratee(next); + callback.apply(null, [null].concat(args)); + }); + iteratee(next); +} + +/** + * Repeatedly call `fn` until `test` returns `true`. Calls `callback` when + * stopped, or an error occurs. `callback` will be passed an error and any + * arguments passed to the final `fn`'s callback. + * + * The inverse of [whilst]{@link module:ControlFlow.whilst}. + * + * @name until + * @static + * @memberOf module:ControlFlow + * @method + * @see [async.whilst]{@link module:ControlFlow.whilst} + * @category Control Flow + * @param {Function} test - synchronous truth test to perform before each + * execution of `fn`. Invoked with (). + * @param {Function} fn - A function which is called each time `test` fails. + * The function is passed a `callback(err)`, which must be called once it has + * completed with an optional `err` argument. Invoked with (callback). + * @param {Function} [callback] - A callback which is called after the test + * function has passed and repeated execution of `fn` has stopped. `callback` + * will be passed an error and any arguments passed to the final `fn`'s + * callback. Invoked with (err, [results]); + */ +function until(test, fn, callback) { + whilst(function () { + return !test.apply(this, arguments); + }, fn, callback); +} + +/** + * Runs the `tasks` array of functions in series, each passing their results to + * the next in the array. However, if any of the `tasks` pass an error to their + * own callback, the next function is not executed, and the main `callback` is + * immediately called with the error. + * + * @name waterfall + * @static + * @memberOf module:ControlFlow + * @method + * @category Control Flow + * @param {Array} tasks - An array of functions to run, each function is passed + * a `callback(err, result1, result2, ...)` it must call on completion. The + * first argument is an error (which can be `null`) and any further arguments + * will be passed as arguments in order to the next task. + * @param {Function} [callback] - An optional callback to run once all the + * functions have completed. This will be passed the results of the last task's + * callback. Invoked with (err, [results]). + * @returns undefined + * @example + * + * async.waterfall([ + * function(callback) { + * callback(null, 'one', 'two'); + * }, + * function(arg1, arg2, callback) { + * // arg1 now equals 'one' and arg2 now equals 'two' + * callback(null, 'three'); + * }, + * function(arg1, callback) { + * // arg1 now equals 'three' + * callback(null, 'done'); + * } + * ], function (err, result) { + * // result now equals 'done' + * }); + * + * // Or, with named functions: + * async.waterfall([ + * myFirstFunction, + * mySecondFunction, + * myLastFunction, + * ], function (err, result) { + * // result now equals 'done' + * }); + * function myFirstFunction(callback) { + * callback(null, 'one', 'two'); + * } + * function mySecondFunction(arg1, arg2, callback) { + * // arg1 now equals 'one' and arg2 now equals 'two' + * callback(null, 'three'); + * } + * function myLastFunction(arg1, callback) { + * // arg1 now equals 'three' + * callback(null, 'done'); + * } + */ +var waterfall = function (tasks, callback) { + callback = once(callback || noop); + if (!isArray(tasks)) return callback(new Error('First argument to waterfall must be an array of functions')); + if (!tasks.length) return callback(); + var taskIndex = 0; + + function nextTask(args) { + if (taskIndex === tasks.length) { + return callback.apply(null, [null].concat(args)); + } + + var taskCallback = onlyOnce(rest(function (err, args) { + if (err) { + return callback.apply(null, [err].concat(args)); + } + nextTask(args); + })); + + args.push(taskCallback); + + var task = tasks[taskIndex++]; + task.apply(null, args); + } + + nextTask([]); +}; + +/** + * 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`, it can also be used directly in the browser. + * @module async + */ + +/** + * A collection of `async` functions for manipulating collections, such as + * arrays and objects. + * @module Collections + */ + +/** + * A collection of `async` functions for controlling the flow through a script. + * @module ControlFlow + */ + +/** + * A collection of `async` utility functions. + * @module Utils + */ +var index = { + applyEach: applyEach, + applyEachSeries: applyEachSeries, + apply: apply$2, + asyncify: asyncify, + auto: auto, + autoInject: autoInject, + cargo: cargo, + compose: compose, + concat: concat, + concatSeries: concatSeries, + constant: constant, + detect: detect, + detectLimit: detectLimit, + detectSeries: detectSeries, + dir: dir, + doDuring: doDuring, + doUntil: doUntil, + doWhilst: doWhilst, + during: during, + each: eachLimit, + eachLimit: eachLimit$1, + eachOf: eachOf, + eachOfLimit: eachOfLimit, + eachOfSeries: eachOfSeries, + eachSeries: eachSeries, + ensureAsync: ensureAsync, + every: every, + everyLimit: everyLimit, + everySeries: everySeries, + filter: filter, + filterLimit: filterLimit, + filterSeries: filterSeries, + forever: forever, + log: log, + map: map, + mapLimit: mapLimit, + mapSeries: mapSeries, + mapValues: mapValues, + mapValuesLimit: mapValuesLimit, + mapValuesSeries: mapValuesSeries, + memoize: memoize, + nextTick: nextTick, + parallel: parallelLimit, + parallelLimit: parallelLimit$1, + priorityQueue: priorityQueue, + queue: queue$1, + race: race, + reduce: reduce, + reduceRight: reduceRight, + reflect: reflect, + reflectAll: reflectAll, + reject: reject, + rejectLimit: rejectLimit, + rejectSeries: rejectSeries, + retry: retry, + retryable: retryable, + seq: seq$1, + series: series, + setImmediate: setImmediate$1, + some: some, + someLimit: someLimit, + someSeries: someSeries, + sortBy: sortBy, + timeout: timeout, + times: times, + timesLimit: timeLimit, + timesSeries: timesSeries, + transform: transform, + unmemoize: unmemoize, + until: until, + waterfall: waterfall, + whilst: whilst, + + // aliases + all: every, + any: some, + forEach: eachLimit, + forEachSeries: eachSeries, + forEachLimit: eachLimit$1, + forEachOf: eachOf, + forEachOfSeries: eachOfSeries, + forEachOfLimit: eachOfLimit, + inject: reduce, + foldl: reduce, + foldr: reduceRight, + select: filter, + selectLimit: filterLimit, + selectSeries: filterSeries, + wrapSync: asyncify +}; + +exports['default'] = index; +exports.applyEach = applyEach; +exports.applyEachSeries = applyEachSeries; +exports.apply = apply$2; +exports.asyncify = asyncify; +exports.auto = auto; +exports.autoInject = autoInject; +exports.cargo = cargo; +exports.compose = compose; +exports.concat = concat; +exports.concatSeries = concatSeries; +exports.constant = constant; +exports.detect = detect; +exports.detectLimit = detectLimit; +exports.detectSeries = detectSeries; +exports.dir = dir; +exports.doDuring = doDuring; +exports.doUntil = doUntil; +exports.doWhilst = doWhilst; +exports.during = during; +exports.each = eachLimit; +exports.eachLimit = eachLimit$1; +exports.eachOf = eachOf; +exports.eachOfLimit = eachOfLimit; +exports.eachOfSeries = eachOfSeries; +exports.eachSeries = eachSeries; +exports.ensureAsync = ensureAsync; +exports.every = every; +exports.everyLimit = everyLimit; +exports.everySeries = everySeries; +exports.filter = filter; +exports.filterLimit = filterLimit; +exports.filterSeries = filterSeries; +exports.forever = forever; +exports.log = log; +exports.map = map; +exports.mapLimit = mapLimit; +exports.mapSeries = mapSeries; +exports.mapValues = mapValues; +exports.mapValuesLimit = mapValuesLimit; +exports.mapValuesSeries = mapValuesSeries; +exports.memoize = memoize; +exports.nextTick = nextTick; +exports.parallel = parallelLimit; +exports.parallelLimit = parallelLimit$1; +exports.priorityQueue = priorityQueue; +exports.queue = queue$1; +exports.race = race; +exports.reduce = reduce; +exports.reduceRight = reduceRight; +exports.reflect = reflect; +exports.reflectAll = reflectAll; +exports.reject = reject; +exports.rejectLimit = rejectLimit; +exports.rejectSeries = rejectSeries; +exports.retry = retry; +exports.retryable = retryable; +exports.seq = seq$1; +exports.series = series; +exports.setImmediate = setImmediate$1; +exports.some = some; +exports.someLimit = someLimit; +exports.someSeries = someSeries; +exports.sortBy = sortBy; +exports.timeout = timeout; +exports.times = times; +exports.timesLimit = timeLimit; +exports.timesSeries = timesSeries; +exports.transform = transform; +exports.unmemoize = unmemoize; +exports.until = until; +exports.waterfall = waterfall; +exports.whilst = whilst; +exports.all = every; +exports.allLimit = everyLimit; +exports.allSeries = everySeries; +exports.any = some; +exports.anyLimit = someLimit; +exports.anySeries = someSeries; +exports.find = detect; +exports.findLimit = detectLimit; +exports.findSeries = detectSeries; +exports.forEach = eachLimit; +exports.forEachSeries = eachSeries; +exports.forEachLimit = eachLimit$1; +exports.forEachOf = eachOf; +exports.forEachOfSeries = eachOfSeries; +exports.forEachOfLimit = eachOfLimit; +exports.inject = reduce; +exports.foldl = reduce; +exports.foldr = reduceRight; +exports.select = filter; +exports.selectLimit = filterLimit; +exports.selectSeries = filterSeries; +exports.wrapSync = asyncify; + +Object.defineProperty(exports, '__esModule', { value: true }); + +}))); diff --git a/scripts/jsdoc-custom.js b/scripts/jsdoc-custom.js new file mode 100644 index 000000000..b101444a8 --- /dev/null +++ b/scripts/jsdoc-custom.js @@ -0,0 +1,129 @@ +/* eslint no-undef: "off" */ +if (typeof setImmediate !== 'function' && typeof async === 'object') { + setImmediate = async.setImmediate; +} + +$(function initSearchBar() { + function matchSubstrs(methodName) { + var tokens = []; + var len = methodName.length; + for (var size = 1; size <= len; size++){ + for (var i = 0; i+size<= len; i++){ + tokens.push(methodName.substr(i, size)); + } + } + return tokens; + } + + var methodNames = new Bloodhound({ + datumTokenizer: matchSubstrs, + queryTokenizer: Bloodhound.tokenizers.whitespace, + prefetch: { + url: './data/methodNames.json', + cache: false + } + }); + + var sourceFiles = new Bloodhound({ + datumTokenizer: matchSubstrs, + queryTokenizer: Bloodhound.tokenizers.whitespace, + prefetch: { + url: './data/sourceFiles.json', + cache: false + } + }); + + var githubIssues = new Bloodhound({ + datumTokenizer: Bloodhound.tokenizers.whitespace, + queryTokenizer: Bloodhound.tokenizers.whitespace, + remote: { + url: 'https://api.github.com/search/issues?q=%QUERY+repo:caolan/async', + cache: true, + wildcard: '%QUERY', + transform: function(response) { + return $.map(response.items, function(issue) { + // if (issue.state !== 'open') { + // return null; + // } + return { + url: issue.html_url, + name: issue.number + ': ' + issue.title, + number: issue.number + }; + }).sort(function(a, b) { + return b.number - a.number; + }); + } + } + }); + + $('.typeahead').typeahead({ + hint: true, + highlight: true, + minLength: 1 + }, { + name: 'Methods', + source: methodNames, + templates: { + header: '

Methods

' + } + }, { + name: 'Files', + source: sourceFiles, + templates: { + header: '

Source Files

' + } + }, { + name: 'Issues', + source: githubIssues, + display: 'name', + templates: { + header: '

Issues

' + } + }).on('typeahead:select', function(ev, suggestion) { + var host; + if (location.origin != "null") { + host = location.origin; + } else { + host = location.protocol + '//' + location.host; + } + + var _path = location.pathname.split("/"); + var currentPage = _path[_path.length - 1]; + host += "/" + _path.slice(1, -1).join("/") + "/"; + + // handle issues + if (typeof suggestion !== 'string') { + location.href = suggestion.url; + // handle source files + } else if (suggestion.indexOf('.html') !== -1) { + location.href = host + suggestion; + } else { + var parenIndex = suggestion.indexOf('('); + if (parenIndex !== -1) { + suggestion = suggestion.substring(0, parenIndex-1); + } + + // handle searching from one of the source files or the home page + if (currentPage !== 'docs.html') { + location.href = host + 'docs.html#' + suggestion; + } else { + var $el = document.getElementById(suggestion); + $('#main-container').animate({ scrollTop: $el.offsetTop - 60 }, 500); + location.hash = '#'+suggestion; + } + } + }); + + function fixOldHash() { + var hash = window.location.hash; + if (hash) { + var hashMatches = hash.match(/^#\.(\w+)$/); + if (hashMatches) { + window.location.hash = '#'+hashMatches[1]; + } + } + } + + fixOldHash(); +}); diff --git a/scripts/linenumber.js b/scripts/linenumber.js new file mode 100644 index 000000000..8d52f7eaf --- /dev/null +++ b/scripts/linenumber.js @@ -0,0 +1,25 @@ +/*global document */ +(function() { + var source = document.getElementsByClassName('prettyprint source linenums'); + var i = 0; + var lineNumber = 0; + var lineId; + var lines; + var totalLines; + var anchorHash; + + if (source && source[0]) { + anchorHash = document.location.hash.substring(1); + lines = source[0].getElementsByTagName('li'); + totalLines = lines.length; + + for (; i < totalLines; i++) { + lineNumber++; + lineId = 'line' + lineNumber; + lines[i].id = lineId; + if (lineId === anchorHash) { + lines[i].className += ' selected'; + } + } + } +})(); diff --git a/scripts/prettify/Apache-License-2.0.txt b/scripts/prettify/Apache-License-2.0.txt new file mode 100644 index 000000000..d64569567 --- /dev/null +++ b/scripts/prettify/Apache-License-2.0.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/scripts/prettify/lang-css.js b/scripts/prettify/lang-css.js new file mode 100644 index 000000000..041e1f590 --- /dev/null +++ b/scripts/prettify/lang-css.js @@ -0,0 +1,2 @@ +PR.registerLangHandler(PR.createSimpleLexer([["pln",/^[\t\n\f\r ]+/,null," \t\r\n "]],[["str",/^"(?:[^\n\f\r"\\]|\\(?:\r\n?|\n|\f)|\\[\S\s])*"/,null],["str",/^'(?:[^\n\f\r'\\]|\\(?:\r\n?|\n|\f)|\\[\S\s])*'/,null],["lang-css-str",/^url\(([^"')]*)\)/i],["kwd",/^(?:url|rgb|!important|@import|@page|@media|@charset|inherit)(?=[^\w-]|$)/i,null],["lang-css-kw",/^(-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*)\s*:/i],["com",/^\/\*[^*]*\*+(?:[^*/][^*]*\*+)*\//],["com", +/^(?:<\!--|--\>)/],["lit",/^(?:\d+|\d*\.\d+)(?:%|[a-z]+)?/i],["lit",/^#[\da-f]{3,6}/i],["pln",/^-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*/i],["pun",/^[^\s\w"']+/]]),["css"]);PR.registerLangHandler(PR.createSimpleLexer([],[["kwd",/^-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*/i]]),["css-kw"]);PR.registerLangHandler(PR.createSimpleLexer([],[["str",/^[^"')]+/]]),["css-str"]); diff --git a/scripts/prettify/prettify.js b/scripts/prettify/prettify.js new file mode 100644 index 000000000..eef5ad7e6 --- /dev/null +++ b/scripts/prettify/prettify.js @@ -0,0 +1,28 @@ +var q=null;window.PR_SHOULD_USE_CONTINUATION=!0; +(function(){function L(a){function m(a){var f=a.charCodeAt(0);if(f!==92)return f;var b=a.charAt(1);return(f=r[b])?f:"0"<=b&&b<="7"?parseInt(a.substring(1),8):b==="u"||b==="x"?parseInt(a.substring(2),16):a.charCodeAt(1)}function e(a){if(a<32)return(a<16?"\\x0":"\\x")+a.toString(16);a=String.fromCharCode(a);if(a==="\\"||a==="-"||a==="["||a==="]")a="\\"+a;return a}function h(a){for(var f=a.substring(1,a.length-1).match(/\\u[\dA-Fa-f]{4}|\\x[\dA-Fa-f]{2}|\\[0-3][0-7]{0,2}|\\[0-7]{1,2}|\\[\S\s]|[^\\]/g),a= +[],b=[],o=f[0]==="^",c=o?1:0,i=f.length;c122||(d<65||j>90||b.push([Math.max(65,j)|32,Math.min(d,90)|32]),d<97||j>122||b.push([Math.max(97,j)&-33,Math.min(d,122)&-33]))}}b.sort(function(a,f){return a[0]-f[0]||f[1]-a[1]});f=[];j=[NaN,NaN];for(c=0;ci[0]&&(i[1]+1>i[0]&&b.push("-"),b.push(e(i[1])));b.push("]");return b.join("")}function y(a){for(var f=a.source.match(/\[(?:[^\\\]]|\\[\S\s])*]|\\u[\dA-Fa-f]{4}|\\x[\dA-Fa-f]{2}|\\\d+|\\[^\dux]|\(\?[!:=]|[()^]|[^()[\\^]+/g),b=f.length,d=[],c=0,i=0;c=2&&a==="["?f[c]=h(j):a!=="\\"&&(f[c]=j.replace(/[A-Za-z]/g,function(a){a=a.charCodeAt(0);return"["+String.fromCharCode(a&-33,a|32)+"]"}));return f.join("")}for(var t=0,s=!1,l=!1,p=0,d=a.length;p=5&&"lang-"===b.substring(0,5))&&!(o&&typeof o[1]==="string"))c=!1,b="src";c||(r[f]=b)}i=d;d+=f.length;if(c){c=o[1];var j=f.indexOf(c),k=j+c.length;o[2]&&(k=f.length-o[2].length,j=k-c.length);b=b.substring(5);B(l+i,f.substring(0,j),e,p);B(l+i+j,c,C(b,c),p);B(l+i+k,f.substring(k),e,p)}else p.push(l+i,b)}a.e=p}var h={},y;(function(){for(var e=a.concat(m), +l=[],p={},d=0,g=e.length;d=0;)h[n.charAt(k)]=r;r=r[1];n=""+r;p.hasOwnProperty(n)||(l.push(r),p[n]=q)}l.push(/[\S\s]/);y=L(l)})();var t=m.length;return e}function u(a){var m=[],e=[];a.tripleQuotedStrings?m.push(["str",/^(?:'''(?:[^'\\]|\\[\S\s]|''?(?=[^']))*(?:'''|$)|"""(?:[^"\\]|\\[\S\s]|""?(?=[^"]))*(?:"""|$)|'(?:[^'\\]|\\[\S\s])*(?:'|$)|"(?:[^"\\]|\\[\S\s])*(?:"|$))/,q,"'\""]):a.multiLineStrings?m.push(["str",/^(?:'(?:[^'\\]|\\[\S\s])*(?:'|$)|"(?:[^"\\]|\\[\S\s])*(?:"|$)|`(?:[^\\`]|\\[\S\s])*(?:`|$))/, +q,"'\"`"]):m.push(["str",/^(?:'(?:[^\n\r'\\]|\\.)*(?:'|$)|"(?:[^\n\r"\\]|\\.)*(?:"|$))/,q,"\"'"]);a.verbatimStrings&&e.push(["str",/^@"(?:[^"]|"")*(?:"|$)/,q]);var h=a.hashComments;h&&(a.cStyleComments?(h>1?m.push(["com",/^#(?:##(?:[^#]|#(?!##))*(?:###|$)|.*)/,q,"#"]):m.push(["com",/^#(?:(?:define|elif|else|endif|error|ifdef|include|ifndef|line|pragma|undef|warning)\b|[^\n\r]*)/,q,"#"]),e.push(["str",/^<(?:(?:(?:\.\.\/)*|\/?)(?:[\w-]+(?:\/[\w-]+)+)?[\w-]+\.h|[a-z]\w*)>/,q])):m.push(["com",/^#[^\n\r]*/, +q,"#"]));a.cStyleComments&&(e.push(["com",/^\/\/[^\n\r]*/,q]),e.push(["com",/^\/\*[\S\s]*?(?:\*\/|$)/,q]));a.regexLiterals&&e.push(["lang-regex",/^(?:^^\.?|[!+-]|!=|!==|#|%|%=|&|&&|&&=|&=|\(|\*|\*=|\+=|,|-=|->|\/|\/=|:|::|;|<|<<|<<=|<=|=|==|===|>|>=|>>|>>=|>>>|>>>=|[?@[^]|\^=|\^\^|\^\^=|{|\||\|=|\|\||\|\|=|~|break|case|continue|delete|do|else|finally|instanceof|return|throw|try|typeof)\s*(\/(?=[^*/])(?:[^/[\\]|\\[\S\s]|\[(?:[^\\\]]|\\[\S\s])*(?:]|$))+\/)/]);(h=a.types)&&e.push(["typ",h]);a=(""+a.keywords).replace(/^ | $/g, +"");a.length&&e.push(["kwd",RegExp("^(?:"+a.replace(/[\s,]+/g,"|")+")\\b"),q]);m.push(["pln",/^\s+/,q," \r\n\t\xa0"]);e.push(["lit",/^@[$_a-z][\w$@]*/i,q],["typ",/^(?:[@_]?[A-Z]+[a-z][\w$@]*|\w+_t\b)/,q],["pln",/^[$_a-z][\w$@]*/i,q],["lit",/^(?:0x[\da-f]+|(?:\d(?:_\d+)*\d*(?:\.\d*)?|\.\d\+)(?:e[+-]?\d+)?)[a-z]*/i,q,"0123456789"],["pln",/^\\[\S\s]?/,q],["pun",/^.[^\s\w"-$'./@\\`]*/,q]);return x(m,e)}function D(a,m){function e(a){switch(a.nodeType){case 1:if(k.test(a.className))break;if("BR"===a.nodeName)h(a), +a.parentNode&&a.parentNode.removeChild(a);else for(a=a.firstChild;a;a=a.nextSibling)e(a);break;case 3:case 4:if(p){var b=a.nodeValue,d=b.match(t);if(d){var c=b.substring(0,d.index);a.nodeValue=c;(b=b.substring(d.index+d[0].length))&&a.parentNode.insertBefore(s.createTextNode(b),a.nextSibling);h(a);c||a.parentNode.removeChild(a)}}}}function h(a){function b(a,d){var e=d?a.cloneNode(!1):a,f=a.parentNode;if(f){var f=b(f,1),g=a.nextSibling;f.appendChild(e);for(var h=g;h;h=g)g=h.nextSibling,f.appendChild(h)}return e} +for(;!a.nextSibling;)if(a=a.parentNode,!a)return;for(var a=b(a.nextSibling,0),e;(e=a.parentNode)&&e.nodeType===1;)a=e;d.push(a)}var k=/(?:^|\s)nocode(?:\s|$)/,t=/\r\n?|\n/,s=a.ownerDocument,l;a.currentStyle?l=a.currentStyle.whiteSpace:window.getComputedStyle&&(l=s.defaultView.getComputedStyle(a,q).getPropertyValue("white-space"));var p=l&&"pre"===l.substring(0,3);for(l=s.createElement("LI");a.firstChild;)l.appendChild(a.firstChild);for(var d=[l],g=0;g=0;){var h=m[e];A.hasOwnProperty(h)?window.console&&console.warn("cannot override language handler %s",h):A[h]=a}}function C(a,m){if(!a||!A.hasOwnProperty(a))a=/^\s*=o&&(h+=2);e>=c&&(a+=2)}}catch(w){"console"in window&&console.log(w&&w.stack?w.stack:w)}}var v=["break,continue,do,else,for,if,return,while"],w=[[v,"auto,case,char,const,default,double,enum,extern,float,goto,int,long,register,short,signed,sizeof,static,struct,switch,typedef,union,unsigned,void,volatile"], +"catch,class,delete,false,import,new,operator,private,protected,public,this,throw,true,try,typeof"],F=[w,"alignof,align_union,asm,axiom,bool,concept,concept_map,const_cast,constexpr,decltype,dynamic_cast,explicit,export,friend,inline,late_check,mutable,namespace,nullptr,reinterpret_cast,static_assert,static_cast,template,typeid,typename,using,virtual,where"],G=[w,"abstract,boolean,byte,extends,final,finally,implements,import,instanceof,null,native,package,strictfp,super,synchronized,throws,transient"], +H=[G,"as,base,by,checked,decimal,delegate,descending,dynamic,event,fixed,foreach,from,group,implicit,in,interface,internal,into,is,lock,object,out,override,orderby,params,partial,readonly,ref,sbyte,sealed,stackalloc,string,select,uint,ulong,unchecked,unsafe,ushort,var"],w=[w,"debugger,eval,export,function,get,null,set,undefined,var,with,Infinity,NaN"],I=[v,"and,as,assert,class,def,del,elif,except,exec,finally,from,global,import,in,is,lambda,nonlocal,not,or,pass,print,raise,try,with,yield,False,True,None"], +J=[v,"alias,and,begin,case,class,def,defined,elsif,end,ensure,false,in,module,next,nil,not,or,redo,rescue,retry,self,super,then,true,undef,unless,until,when,yield,BEGIN,END"],v=[v,"case,done,elif,esac,eval,fi,function,in,local,set,then,until"],K=/^(DIR|FILE|vector|(de|priority_)?queue|list|stack|(const_)?iterator|(multi)?(set|map)|bitset|u?(int|float)\d*)/,N=/\S/,O=u({keywords:[F,H,w,"caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END"+ +I,J,v],hashComments:!0,cStyleComments:!0,multiLineStrings:!0,regexLiterals:!0}),A={};k(O,["default-code"]);k(x([],[["pln",/^[^]*(?:>|$)/],["com",/^<\!--[\S\s]*?(?:--\>|$)/],["lang-",/^<\?([\S\s]+?)(?:\?>|$)/],["lang-",/^<%([\S\s]+?)(?:%>|$)/],["pun",/^(?:<[%?]|[%?]>)/],["lang-",/^]*>([\S\s]+?)<\/xmp\b[^>]*>/i],["lang-js",/^]*>([\S\s]*?)(<\/script\b[^>]*>)/i],["lang-css",/^]*>([\S\s]*?)(<\/style\b[^>]*>)/i],["lang-in.tag",/^(<\/?[a-z][^<>]*>)/i]]), +["default-markup","htm","html","mxml","xhtml","xml","xsl"]);k(x([["pln",/^\s+/,q," \t\r\n"],["atv",/^(?:"[^"]*"?|'[^']*'?)/,q,"\"'"]],[["tag",/^^<\/?[a-z](?:[\w-.:]*\w)?|\/?>$/i],["atn",/^(?!style[\s=]|on)[a-z](?:[\w:-]*\w)?/i],["lang-uq.val",/^=\s*([^\s"'>]*(?:[^\s"'/>]|\/(?=\s)))/],["pun",/^[/<->]+/],["lang-js",/^on\w+\s*=\s*"([^"]+)"/i],["lang-js",/^on\w+\s*=\s*'([^']+)'/i],["lang-js",/^on\w+\s*=\s*([^\s"'>]+)/i],["lang-css",/^style\s*=\s*"([^"]+)"/i],["lang-css",/^style\s*=\s*'([^']+)'/i],["lang-css", +/^style\s*=\s*([^\s"'>]+)/i]]),["in.tag"]);k(x([],[["atv",/^[\S\s]+/]]),["uq.val"]);k(u({keywords:F,hashComments:!0,cStyleComments:!0,types:K}),["c","cc","cpp","cxx","cyc","m"]);k(u({keywords:"null,true,false"}),["json"]);k(u({keywords:H,hashComments:!0,cStyleComments:!0,verbatimStrings:!0,types:K}),["cs"]);k(u({keywords:G,cStyleComments:!0}),["java"]);k(u({keywords:v,hashComments:!0,multiLineStrings:!0}),["bsh","csh","sh"]);k(u({keywords:I,hashComments:!0,multiLineStrings:!0,tripleQuotedStrings:!0}), +["cv","py"]);k(u({keywords:"caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END",hashComments:!0,multiLineStrings:!0,regexLiterals:!0}),["perl","pl","pm"]);k(u({keywords:J,hashComments:!0,multiLineStrings:!0,regexLiterals:!0}),["rb"]);k(u({keywords:w,cStyleComments:!0,regexLiterals:!0}),["js"]);k(u({keywords:"all,and,by,catch,class,else,extends,false,finally,for,if,in,is,isnt,loop,new,no,not,null,of,off,on,or,return,super,then,true,try,unless,until,when,while,yes", +hashComments:3,cStyleComments:!0,multilineStrings:!0,tripleQuotedStrings:!0,regexLiterals:!0}),["coffee"]);k(x([],[["str",/^[\S\s]+/]]),["regex"]);window.prettyPrintOne=function(a,m,e){var h=document.createElement("PRE");h.innerHTML=a;e&&D(h,e);E({g:m,i:e,h:h});return h.innerHTML};window.prettyPrint=function(a){function m(){for(var e=window.PR_SHOULD_USE_CONTINUATION?l.now()+250:Infinity;p=0){var k=k.match(g),f,b;if(b= +!k){b=n;for(var o=void 0,c=b.firstChild;c;c=c.nextSibling)var i=c.nodeType,o=i===1?o?b:c:i===3?N.test(c.nodeValue)?b:o:o;b=(f=o===b?void 0:o)&&"CODE"===f.tagName}b&&(k=f.className.match(g));k&&(k=k[1]);b=!1;for(o=n.parentNode;o;o=o.parentNode)if((o.tagName==="pre"||o.tagName==="code"||o.tagName==="xmp")&&o.className&&o.className.indexOf("prettyprint")>=0){b=!0;break}b||((b=(b=n.className.match(/\blinenums\b(?::(\d+))?/))?b[1]&&b[1].length?+b[1]:!0:!1)&&D(n,b),d={g:k,h:n,i:b},E(d))}}p + + + + + + seq.js - Documentation + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +

seq.js

+ + + + + + + +
+
+
import noop from 'lodash/noop';
+import rest from './internal/rest';
+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]{@link module:ControlFlow.compose} with the arguments reversed.
+ *
+ * Each function is executed with the `this` binding of the composed function.
+ *
+ * @name seq
+ * @static
+ * @memberOf module:ControlFlow
+ * @method
+ * @see [async.compose]{@link module:ControlFlow.compose}
+ * @category Control Flow
+ * @param {...Function} functions - the asynchronous functions to compose
+ * @returns {Function} a function that composes the `functions` in order
+ * @example
+ *
+ * // Requires lodash (or underscore), express3 and dresende's orm2.
+ * // Part of an app, that fetches cats of the logged user.
+ * // This example uses `seq` function to avoid overnesting and error
+ * // handling clutter.
+ * app.get('/cats', function(request, response) {
+ *     var User = request.models.User;
+ *     async.seq(
+ *         _.bind(User.get, User),  // 'User.get' has signature (id, callback(err, data))
+ *         function(user, fn) {
+ *             user.getCats(fn);      // 'getCats' has signature (callback(err, data))
+ *         }
+ *     )(req.session.user_id, function (err, cats) {
+ *         if (err) {
+ *             console.error(err);
+ *             response.json({ status: 'error', message: err.message });
+ *         } else {
+ *             response.json({ status: 'ok', message: 'Cats found', data: cats });
+ *         }
+ *     });
+ * });
+ */
+export default rest(function seq(functions) {
+    return rest(function(args) {
+        var that = this;
+
+        var cb = args[args.length - 1];
+        if (typeof cb == 'function') {
+            args.pop();
+        } else {
+            cb = noop;
+        }
+
+        reduce(functions, args, function(newargs, fn, cb) {
+            fn.apply(that, newargs.concat(rest(function(err, nextargs) {
+                cb(err, nextargs);
+            })));
+        },
+        function(err, results) {
+            cb.apply(that, [err].concat(results));
+        });
+    });
+})
+
+
+
+ + + + +
+ Documentation generated by JSDoc 3.4.3 on Tue Mar 28 2017 00:02:51 GMT-0400 (EDT) using the Minami theme. + Documentation has been modified from the original. For more information, please see the async repository.
+
+ + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/series.js.html b/series.js.html new file mode 100644 index 000000000..4ab4d14d5 --- /dev/null +++ b/series.js.html @@ -0,0 +1,177 @@ + + + + + + + series.js - Documentation + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +

series.js

+ + + + + + + +
+
+
import parallel from './internal/parallel';
+import eachOfSeries from './eachOfSeries';
+
+/**
+ * Run the functions in the `tasks` collection in series, each one running once
+ * the previous function has completed. If any functions in the series pass an
+ * error to its callback, no more functions are run, and `callback` is
+ * immediately called with the value of the error. Otherwise, `callback`
+ * receives an array of results when `tasks` have completed.
+ *
+ * It is also possible to use an object instead of an array. Each property will
+ * be run as a function, and the results will be passed to the final `callback`
+ * as an object instead of an array. This can be a more readable way of handling
+ *  results from {@link async.series}.
+ *
+ * **Note** that while many implementations preserve the order of object
+ * properties, the [ECMAScript Language Specification](http://www.ecma-international.org/ecma-262/5.1/#sec-8.6)
+ * explicitly states that
+ *
+ * > The mechanics and order of enumerating the properties is not specified.
+ *
+ * So if you rely on the order in which your series of functions are executed,
+ * and want this to work on all platforms, consider using an array.
+ *
+ * @name series
+ * @static
+ * @memberOf module:ControlFlow
+ * @method
+ * @category Control Flow
+ * @param {Array|Iterable|Object} tasks - A collection containing functions to run, each
+ * function is passed a `callback(err, result)` it must call on completion with
+ * an error `err` (which can be `null`) and an optional `result` value.
+ * @param {Function} [callback] - An optional callback to run once all the
+ * functions have completed. This function gets a results array (or object)
+ * containing all the result arguments passed to the `task` callbacks. Invoked
+ * with (err, result).
+ * @example
+ * async.series([
+ *     function(callback) {
+ *         // do some stuff ...
+ *         callback(null, 'one');
+ *     },
+ *     function(callback) {
+ *         // do some more stuff ...
+ *         callback(null, 'two');
+ *     }
+ * ],
+ * // optional callback
+ * function(err, results) {
+ *     // results is now equal to ['one', 'two']
+ * });
+ *
+ * async.series({
+ *     one: function(callback) {
+ *         setTimeout(function() {
+ *             callback(null, 1);
+ *         }, 200);
+ *     },
+ *     two: function(callback){
+ *         setTimeout(function() {
+ *             callback(null, 2);
+ *         }, 100);
+ *     }
+ * }, function(err, results) {
+ *     // results is now equal to: {one: 1, two: 2}
+ * });
+ */
+export default function series(tasks, callback) {
+    parallel(eachOfSeries, tasks, callback);
+}
+
+
+
+ + + + +
+ Documentation generated by JSDoc 3.4.3 on Tue Mar 28 2017 00:02:51 GMT-0400 (EDT) using the Minami theme. + Documentation has been modified from the original. For more information, please see the async repository.
+
+ + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/setImmediate.js.html b/setImmediate.js.html new file mode 100644 index 000000000..7e62354a0 --- /dev/null +++ b/setImmediate.js.html @@ -0,0 +1,141 @@ + + + + + + + setImmediate.js - Documentation + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +

setImmediate.js

+ + + + + + + +
+
+
import setImmediate from './internal/setImmediate';
+
+/**
+ * Calls `callback` on a later loop around the event loop. In Node.js this just
+ * calls `setImmediate`.  In the browser it will use `setImmediate` if
+ * available, otherwise `setTimeout(callback, 0)`, which means other higher
+ * priority events may precede the execution of `callback`.
+ *
+ * This is used internally for browser-compatibility purposes.
+ *
+ * @name setImmediate
+ * @static
+ * @memberOf module:Utils
+ * @method
+ * @alias nextTick
+ * @category Util
+ * @param {Function} callback - The function to call on a later loop around
+ * the event loop. Invoked with (args...).
+ * @param {...*} args... - any number of additional arguments to pass to the
+ * callback on the next tick.
+ * @example
+ *
+ * var call_order = [];
+ * async.nextTick(function() {
+ *     call_order.push('two');
+ *     // call_order now equals ['one','two']
+ * });
+ * call_order.push('one');
+ *
+ * async.setImmediate(function (a, b, c) {
+ *     // a, b, and c equal 1, 2, and 3
+ * }, 1, 2, 3);
+ */
+export default setImmediate;
+
+
+
+ + + + +
+ Documentation generated by JSDoc 3.4.3 on Tue Mar 28 2017 00:02:51 GMT-0400 (EDT) using the Minami theme. + Documentation has been modified from the original. For more information, please see the async repository.
+
+ + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/some.js.html b/some.js.html new file mode 100644 index 000000000..16fcf6a18 --- /dev/null +++ b/some.js.html @@ -0,0 +1,142 @@ + + + + + + + some.js - Documentation + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +

some.js

+ + + + + + + +
+
+
import createTester from './internal/createTester';
+import doParallel from './internal/doParallel';
+import identity from 'lodash/identity';
+
+/**
+ * Returns `true` if at least one element in the `coll` satisfies an async test.
+ * If any iteratee call returns `true`, the main `callback` is immediately
+ * called.
+ *
+ * @name some
+ * @static
+ * @memberOf module:Collections
+ * @method
+ * @alias any
+ * @category Collection
+ * @param {Array|Iterable|Object} coll - A collection to iterate over.
+ * @param {Function} iteratee - A truth test to apply to each item in the array
+ * in parallel. The iteratee is passed a `callback(err, truthValue)` which must
+ * be called with a boolean argument once it has completed. Invoked with
+ * (item, callback).
+ * @param {Function} [callback] - A callback which is called as soon as any
+ * iteratee returns `true`, or after all the iteratee functions have finished.
+ * Result will be either `true` or `false` depending on the values of the async
+ * tests. Invoked with (err, result).
+ * @example
+ *
+ * async.some(['file1','file2','file3'], function(filePath, callback) {
+ *     fs.access(filePath, function(err) {
+ *         callback(null, !err)
+ *     });
+ * }, function(err, result) {
+ *     // if result is true then at least one of the files exists
+ * });
+ */
+export default doParallel(createTester(Boolean, identity));
+
+
+
+ + + + +
+ Documentation generated by JSDoc 3.4.3 on Tue Mar 28 2017 00:02:51 GMT-0400 (EDT) using the Minami theme. + Documentation has been modified from the original. For more information, please see the async repository.
+
+ + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/someLimit.js.html b/someLimit.js.html new file mode 100644 index 000000000..f0c20e1f5 --- /dev/null +++ b/someLimit.js.html @@ -0,0 +1,133 @@ + + + + + + + someLimit.js - Documentation + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +

someLimit.js

+ + + + + + + +
+
+
import createTester from './internal/createTester';
+import doParallelLimit from './internal/doParallelLimit';
+import identity from 'lodash/identity';
+
+/**
+ * The same as [`some`]{@link module:Collections.some} but runs a maximum of `limit` async operations at a time.
+ *
+ * @name someLimit
+ * @static
+ * @memberOf module:Collections
+ * @method
+ * @see [async.some]{@link module:Collections.some}
+ * @alias anyLimit
+ * @category Collection
+ * @param {Array|Iterable|Object} coll - A collection to iterate over.
+ * @param {number} limit - The maximum number of async operations at a time.
+ * @param {Function} iteratee - A truth test to apply to each item in the array
+ * in parallel. The iteratee is passed a `callback(err, truthValue)` which must
+ * be called with a boolean argument once it has completed. Invoked with
+ * (item, callback).
+ * @param {Function} [callback] - A callback which is called as soon as any
+ * iteratee returns `true`, or after all the iteratee functions have finished.
+ * Result will be either `true` or `false` depending on the values of the async
+ * tests. Invoked with (err, result).
+ */
+export default doParallelLimit(createTester(Boolean, identity));
+
+
+
+ + + + +
+ Documentation generated by JSDoc 3.4.3 on Tue Mar 28 2017 00:02:51 GMT-0400 (EDT) using the Minami theme. + Documentation has been modified from the original. For more information, please see the async repository.
+
+ + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/someSeries.js.html b/someSeries.js.html new file mode 100644 index 000000000..9b249878a --- /dev/null +++ b/someSeries.js.html @@ -0,0 +1,131 @@ + + + + + + + someSeries.js - Documentation + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +

someSeries.js

+ + + + + + + +
+
+
import someLimit from './someLimit';
+import doLimit from './internal/doLimit';
+
+/**
+ * The same as [`some`]{@link module:Collections.some} but runs only a single async operation at a time.
+ *
+ * @name someSeries
+ * @static
+ * @memberOf module:Collections
+ * @method
+ * @see [async.some]{@link module:Collections.some}
+ * @alias anySeries
+ * @category Collection
+ * @param {Array|Iterable|Object} coll - A collection to iterate over.
+ * @param {Function} iteratee - A truth test to apply to each item in the array
+ * in parallel. The iteratee is passed a `callback(err, truthValue)` which must
+ * be called with a boolean argument once it has completed. Invoked with
+ * (item, callback).
+ * @param {Function} [callback] - A callback which is called as soon as any
+ * iteratee returns `true`, or after all the iteratee functions have finished.
+ * Result will be either `true` or `false` depending on the values of the async
+ * tests. Invoked with (err, result).
+ */
+export default doLimit(someLimit, 1);
+
+
+
+ + + + +
+ Documentation generated by JSDoc 3.4.3 on Tue Mar 28 2017 00:02:51 GMT-0400 (EDT) using the Minami theme. + Documentation has been modified from the original. For more information, please see the async repository.
+
+ + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sortBy.js.html b/sortBy.js.html new file mode 100644 index 000000000..aab1cc4e7 --- /dev/null +++ b/sortBy.js.html @@ -0,0 +1,174 @@ + + + + + + + sortBy.js - Documentation + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +

sortBy.js

+ + + + + + + +
+
+
import arrayMap from 'lodash/_arrayMap';
+import property from 'lodash/_baseProperty';
+
+import map from './map';
+
+/**
+ * Sorts a list by the results of running each `coll` value through an async
+ * `iteratee`.
+ *
+ * @name sortBy
+ * @static
+ * @memberOf module:Collections
+ * @method
+ * @category Collection
+ * @param {Array|Iterable|Object} coll - A collection to iterate over.
+ * @param {Function} iteratee - A function to apply to each item in `coll`.
+ * The iteratee is passed a `callback(err, sortValue)` which must be called once
+ * it has completed with an error (which can be `null`) and a value to use as
+ * the sort criteria. Invoked with (item, callback).
+ * @param {Function} callback - A callback which is called after all the
+ * `iteratee` functions have finished, or an error occurs. Results is the items
+ * from the original `coll` sorted by the values returned by the `iteratee`
+ * calls. Invoked with (err, results).
+ * @example
+ *
+ * async.sortBy(['file1','file2','file3'], function(file, callback) {
+ *     fs.stat(file, function(err, stats) {
+ *         callback(err, stats.mtime);
+ *     });
+ * }, function(err, results) {
+ *     // results is now the original array of files sorted by
+ *     // modified date
+ * });
+ *
+ * // By modifying the callback parameter the
+ * // sorting order can be influenced:
+ *
+ * // ascending order
+ * async.sortBy([1,9,3,5], function(x, callback) {
+ *     callback(null, x);
+ * }, function(err,result) {
+ *     // result callback
+ * });
+ *
+ * // descending order
+ * async.sortBy([1,9,3,5], function(x, callback) {
+ *     callback(null, x*-1);    //<- x*-1 instead of x, turns the order around
+ * }, function(err,result) {
+ *     // result callback
+ * });
+ */
+export default function sortBy (coll, iteratee, callback) {
+    map(coll, function (x, callback) {
+        iteratee(x, function (err, criteria) {
+            if (err) return callback(err);
+            callback(null, {value: x, criteria: criteria});
+        });
+    }, function (err, results) {
+        if (err) return callback(err);
+        callback(null, arrayMap(results.sort(comparator), property('value')));
+    });
+
+    function comparator(left, right) {
+        var a = left.criteria, b = right.criteria;
+        return a < b ? -1 : a > b ? 1 : 0;
+    }
+}
+
+
+
+ + + + +
+ Documentation generated by JSDoc 3.4.3 on Tue Mar 28 2017 00:02:51 GMT-0400 (EDT) using the Minami theme. + Documentation has been modified from the original. For more information, please see the async repository.
+
+ + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/styles/jsdoc-custom.css b/styles/jsdoc-custom.css deleted file mode 100644 index 04316d793..000000000 --- a/styles/jsdoc-custom.css +++ /dev/null @@ -1,3 +0,0 @@ -.page-title { - padding-top: 12px; -} diff --git a/styles/jsdoc-default.css b/styles/jsdoc-default.css new file mode 100644 index 000000000..fee48f167 --- /dev/null +++ b/styles/jsdoc-default.css @@ -0,0 +1,824 @@ +* { + box-sizing: border-box +} + +html, body { + height: 100%; + width: 100%; +} + +body { + color: #4d4e53; + background-color: white; + margin: 0 auto; + padding: 0; + + font-family: 'Helvetica Neue', Helvetica, sans-serif; + font-size: 16px; + line-height: 160%; +} + +a, +a:active { + color: #0095dd; + text-decoration: none; +} + +a:hover { + text-decoration: underline +} + +p, ul, ol, blockquote { + margin-bottom: 1em; +} + +h1, h2, h3, h4, h5, h6 { + font-family: 'Montserrat', sans-serif; +} + +h1, h2, h3, h4, h5, h6 { + color: #565656; + font-weight: 400; + margin: 0; + padding-top: 1em; +} + +h1 { + font-weight: 300; + font-size: 48px; + margin: 1em 0 .5em; +} + +h1.page-title { + font-size: 48px; + margin: 1em 30px; +} + +h2 { + font-size: 30px; + margin: 1.5em 0 .3em; +} + +h3 { + font-size: 24px; + margin: 1.2em 0 .3em; +} + +h4 { + font-size: 20px; + margin: 1em 0 .2em; + padding-top: 6em; + color: #4d4e53; +} + +h5, .container-overview .subsection-title { + font-size: 120%; + letter-spacing: -0.01em; + margin: 8px 0 3px 0; +} + +h6 { + font-size: 100%; + letter-spacing: -0.01em; + margin: 6px 0 3px 0; + font-style: italic; +} + +tt, code, kbd, samp { + font-family: Consolas, Monaco, 'Andale Mono', monospace; + background: #f4f4f4; + padding: 1px 5px; + border-radius: 5px; +} + +.class-description { + font-size: 130%; + line-height: 140%; + margin-bottom: 1em; + margin-top: 1em; +} + +.class-description:empty { + margin: 0 +} + +#main { + position: fixed; + top: 50px; + left: 250px; + right: 0; + bottom: 0; + float: none; + min-width: 360px; + overflow-y: hidden; +} + +#main-container { + position: relative; + width: 100%; + height: 100%; + overflow-y: scroll; + padding-left: 16px; + padding-right: 16px; +} + +#main-container h1 { + margin-top: 100px !important; + padding-top: 0px; + border-left: 2px solid #3391FE; +} + +#main-container h4 { + margin-top: 120px !important; + padding-top: 0px; + padding-left: 16px; + margin-left: -16px; + border-left: 2px solid #3391FE; +} + +header { + display: block +} + +section, h1 { + display: block; + background-color: #fff; + padding: 2em 30px 0; +} + +#toc > h3 { + margin-bottom: 0px; +} + +#toc > .methods > li { + padding: 0px 10px; +} + +#toc > .methods > li > a { + font-size: 12px; + padding: 0px; +} + +#toc > .methods > .toc-header { + margin-top: 10px; +} + +#toc > .methods > .toc-method { + padding: 0px; + margin: 0px 10px; +} + +#toc > .methods > .toc-method > a, +#toc > .methods > .toc-method > a.active { + padding: 0px 0px 0px 20px; + border-left: 1px solid #D8DCDF; + color: #98999A; +} + +#toc > .methods > .toc-method.active { + background-color: #E8E8E8; +} + +.nav.navbar-right .navbar-form { + padding: 0; + margin: 6px 0px; +} + +.navbar-collapse.collapse { + display: block!important; +} + +.navbar-nav>li, .navbar-nav { + float: left !important; +} + +.navbar-nav.navbar-right:last-child { + margin-right: -15px !important; +} + +.navbar-right { + float: right!important; +} + +.twitter-typeahead input { + border-radius: 8px; + height: 38px; +} + +.twitter-typeahead input.tt-hint { + color: #AAA; +} + +.tt-menu { + background-color: white; + width: 100%; + box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.1); + z-index: 11; + overflow-y: auto; +} + +.tt-suggestion, .tt-menu h3 { + font-size: 14px; + padding: 0.6em; + margin: 0; + cursor: pointer; +} + +.tt-menu h3 { + cursor: default; + font-weight: bold; + color: #888; +} + +.tt-suggestion:hover { + background-color: rgba(128, 128, 128, 0.2); +} + +.tt-cursor { + background-color: #D3D3D3; +} + +.search-bar-header-first { + margin: 5px 0px; + border-bottom: 1px solid #D3D3D3; +} + +.search-bar-header { + margin: 5px 0px; + border-top: 1px solid #D3D3D3; + border-bottom: 1px solid #D3D3D3; +} + +.variation { + display: none +} + +.signature-attributes { + font-size: 60%; + color: #aaa; + font-style: italic; + font-weight: lighter; +} + +nav { + float: left; + display: block; + width: 250px; + background: #FAFAFA; + overflow: auto; + position: fixed; + height: 100%; + top: 50px; + padding-left: 12px; + overflow-y: auto; + height: calc(100% - 50px); + box-shadow: 1px 0 rgba(0, 0, 0, 0.1); +} + +nav h3 { + margin-top: 12px; + font-size: 13px; + text-transform: uppercase; + letter-spacing: 1px; + font-weight: 700; + line-height: 24px; + margin: 15px 0 10px; + padding: 0; + color: #000; +} + +nav ul { + font-family: 'Lucida Grande', 'Lucida Sans Unicode', arial, sans-serif; + font-size: 100%; + line-height: 17px; + padding: 0; + margin: 0; + list-style-type: none; +} + +nav ul a, +nav ul a:active { + font-family: 'Montserrat', sans-serif; + line-height: 18px; + padding: 0; + display: block; + font-size: 12px; +} + +nav ul a:hover, +nav ul a:active { + color: hsl(200, 100%, 43%); + text-decoration: none; +} + +nav > ul { + padding: 0 10px; +} + +nav > ul > li > a { + color: #000; +} + +nav ul ul { + margin-bottom: 10px +} + +nav ul ul a { + color: hsl(207, 1%, 60%); + border-left: 1px solid hsl(207, 10%, 86%); +} + +nav ul ul a, +nav ul ul a:active { + padding-left: 20px +} + +nav h2 { + font-size: 12px; + margin: 0; + padding: 0; +} + +nav > h2 > a { + display: block; + margin: 10px 0 -10px; + color: hsl(202, 71%, 50%) !important; +} + + +.navbar-brand { + padding: 8px; +} + +.navbar-brand img { + height: 32px; +} + +.navbar-fixed-top { + z-index: 1; + background-color: #F0F0F0; + padding: 0px 10px; + border-left: 6px solid #3391FE; +} + +.navbar-fixed-top .navbar-right { + padding-right: 16px; +} + +.navbar .ion-social-github { + font-size: 1.5em; + float: left; + color: #3391FE; +} + +.navbar .ion-social-github:hover { + color: #3D7FC1; +} + +footer { + max-width: 800px; + margin: 0 auto; + color: hsl(0, 0%, 56%); + display: block; + padding: 30px 30px 0; + font-size: 12px; + line-height: 1.4; +} + +#main section, #main h1 { + margin: 0 auto; + max-width: 800px; +} + +article img { + max-width: 100%; +} + +/* fix bootstrap's styling */ +pre { + background: #fff; + padding: 0px; +} + +code { + color: hsl(0, 0%, 35%); +} + +.ancestors { + color: #999 +} + +.ancestors a { + color: #999 !important; + text-decoration: none; +} + +.clear { + clear: both +} + +.important { + font-weight: bold; + color: #950B02; +} + +.yes-def { + text-indent: -1000px +} + +.type-signature { + color: #aaa; + display: none; +} + +.name, .signature { + font-family: Consolas, Monaco, 'Andale Mono', monospace +} + +.details { + margin-top: 14px; + border-left: 2px solid #DDD; + line-height: 30px; +} + +.alias-details { + margin-top: -10px; + border-left: none; +} + +.details dt { + width: 120px; + float: left; + padding-left: 10px; +} + +.alias-details dt { + padding-left: 0px; +} + +.details dd { + margin-left: 70px +} + +.details ul { + margin: 0 +} + +.details ul { + list-style-type: none +} + +.details li { + margin-left: 30px +} + +.details pre.prettyprint { + margin: 0 +} + +.details .object-value { + padding-top: 0 +} + +.description { + margin-bottom: 1em; + margin-top: 1em; +} + +.code-caption { + font-style: italic; + font-size: 107%; + margin: 0; +} + +.prettyprint { + font-size: 13px; + border: 1px solid #ddd; + border-radius: 3px; + box-shadow: 0 1px 3px hsla(0, 0%, 0%, 0.05); + overflow: auto; +} + +.prettyprint.source { + width: inherit +} + +.prettyprint code { + font-size: 100%; + line-height: 18px; + display: block; + background-color: #fff; + color: #4D4E53; +} + +.prettyprint > code { + padding: 15px +} + +.prettyprint .linenums code { + padding: 0 1em; + min-height: 18px; +} + +.prettyprint .linenums li:first-of-type code { + padding-top: 15px +} + +.prettyprint code span.line { + display: inline-block +} + +.prettyprint.linenums { + padding-left: 70px; + -webkit-user-select: none; + -moz-user-select: none; + -ms-user-select: none; + user-select: none; +} + +.prettyprint.linenums ol { + padding-left: 0 +} + +.prettyprint.linenums li { + border-left: 3px #ddd solid +} + +.prettyprint.linenums li.selected, .prettyprint.linenums li.selected * { + background-color: lightyellow +} + +.prettyprint.linenums li * { + -webkit-user-select: text; + -moz-user-select: text; + -ms-user-select: text; + user-select: text; +} + +table.params { + margin-top: 1em; + box-shadow: none; + border: none; +} + +table.params td, table.params th { + border: none; + padding: 0 15px 8px 0; +} + +table.params td.type { + white-space: nowrap; +} + +.params .optional { + font-size: 80%; + color: hsl(0, 0%, 56%); +} + +.params, .props { + border-spacing: 0; + border: 1px solid #ddd; + border-collapse: collapse; + border-radius: 3px; + box-shadow: 0 1px 3px rgba(0,0,0,0.1); + width: 100%; + font-size: 14px; +} + +.params .name, .props .name, .name code { + color: #4D4E53; + font-family: Consolas, Monaco, 'Andale Mono', monospace; + font-size: 100%; +} + +.params td, .params th, .props td, .props th { + margin: 0px; + text-align: left; + vertical-align: top; + padding: 10px; + display: table-cell; +} + +.params td { + border-top: 1px solid #eee +} + +.params thead tr, .props thead tr { + background-color: #fff; + font-weight: bold; + color: hsl(0, 0%, 56%); +} + +.params .params thead tr, .props .props thead tr { + background-color: #fff; + font-weight: bold; +} + +.params td.description > p:first-child, .props td.description > p:first-child { + margin-top: 0; + padding-top: 0; +} + +.params td.description > p:last-child, .props td.description > p:last-child { + margin-bottom: 0; + padding-bottom: 0; +} + +dl.param-type { + border-bottom: 1px solid hsl(0, 0%, 87%); + margin-bottom: 30px; + padding-bottom: 30px; +} + +.param-type dt, .param-type dd { + display: inline-block +} + +.param-type dd { + font-family: Consolas, Monaco, 'Andale Mono', monospace +} + +.disabled { + color: #454545 +} + +/* navicon button */ +.navicon-button { + display: none; + position: relative; + padding: 2.0625rem 1.5rem; + transition: 0.25s; + cursor: pointer; + user-select: none; + opacity: .8; + color: #3391FE; +} +.navicon-button .navicon:before, .navicon-button .navicon:after { + transition: 0.25s; +} +.navicon-button:hover { + transition: 0.5s; + opacity: 1; +} +.navicon-button:hover .navicon:before, .navicon-button:hover .navicon:after { + transition: 0.25s; +} +.navicon-button:hover .navicon:before { + top: .825rem; +} +.navicon-button:hover .navicon:after { + top: -.825rem; +} + +/* navicon */ +.navicon { + position: relative; + width: 32px; + height: 4px; + background: #3391FE; + transition: 0.3s; + border-radius: 2px; +} +.navicon:before, .navicon:after { + display: block; + content: ""; + height: 4px; + width: 32px; + background: #3391FE; + position: absolute; + z-index: -1; + transition: 0.3s 0.25s; + border-radius: 2px; +} +.navicon:before { + top: 10px; +} +.navicon:after { + top: -10px; +} + +/* open */ +.nav-trigger:checked + label:not(.steps) .navicon:before, +.nav-trigger:checked + label:not(.steps) .navicon:after { + top: 0 !important; +} + +.nav-trigger:checked + label .navicon:before, +.nav-trigger:checked + label .navicon:after { + transition: 0.5s; +} + +/* Minus */ +.nav-trigger:checked + label { + transform: scale(0.75); +} + +/* × and + */ +.nav-trigger:checked + label.plus .navicon, +.nav-trigger:checked + label.x .navicon { + background: transparent; +} + +.nav-trigger:checked + label.plus .navicon:before, +.nav-trigger:checked + label.x .navicon:before { + transform: rotate(-45deg); + background: #FFF; +} + +.nav-trigger:checked + label.plus .navicon:after, +.nav-trigger:checked + label.x .navicon:after { + transform: rotate(45deg); + background: #FFF; +} + +.nav-trigger:checked + label.plus { + transform: scale(0.75) rotate(45deg); +} + +.nav-trigger:checked ~ nav { + left: 0 !important; +} + +.nav-trigger:checked ~ .overlay { + display: block; +} + +.nav-trigger { + position: fixed; + top: 0; + clip: rect(0, 0, 0, 0); +} + +.overlay { + display: none; + position: fixed; + top: 0; + bottom: 0; + left: 0; + right: 0; + width: 100%; + height: 100%; + background: hsla(0, 0%, 0%, 0.5); + z-index: 1; +} + +@media only screen and (min-width: 320px) and (max-width: 680px) { + body { + overflow-x: hidden; + } + + nav { + background: #FFF; + width: 250px; + height: 100%; + position: fixed; + top: 0; + right: 0; + bottom: 0; + left: -250px; + z-index: 3; + padding: 0 10px; + transition: left 0.2s; + } + + .navicon-button { + display: inline-block; + position: fixed; + right: 0; + z-index: 2; + } + + #main { + padding: 16px; + left: 0px; + min-width: 360px; + } + + #main h1.page-title { + margin: 1em 0; + } + + #main h4 { + margin-left: -8px; + padding-left: 8px; + } + + #main section { + padding: 0; + } + + footer { + margin-left: 0; + } +} + +@media only print { + nav { + display: none; + } + + #main { + float: none; + width: 100%; + } +} diff --git a/styles/prettify-jsdoc.css b/styles/prettify-jsdoc.css new file mode 100644 index 000000000..834a866d4 --- /dev/null +++ b/styles/prettify-jsdoc.css @@ -0,0 +1,111 @@ +/* JSDoc prettify.js theme */ + +/* plain text */ +.pln { + color: #000000; + font-weight: normal; + font-style: normal; +} + +/* string content */ +.str { + color: hsl(104, 100%, 24%); + font-weight: normal; + font-style: normal; +} + +/* a keyword */ +.kwd { + color: #000000; + font-weight: bold; + font-style: normal; +} + +/* a comment */ +.com { + font-weight: normal; + font-style: italic; +} + +/* a type name */ +.typ { + color: #000000; + font-weight: normal; + font-style: normal; +} + +/* a literal value */ +.lit { + color: #006400; + font-weight: normal; + font-style: normal; +} + +/* punctuation */ +.pun { + color: #000000; + font-weight: bold; + font-style: normal; +} + +/* lisp open bracket */ +.opn { + color: #000000; + font-weight: bold; + font-style: normal; +} + +/* lisp close bracket */ +.clo { + color: #000000; + font-weight: bold; + font-style: normal; +} + +/* a markup tag name */ +.tag { + color: #006400; + font-weight: normal; + font-style: normal; +} + +/* a markup attribute name */ +.atn { + color: #006400; + font-weight: normal; + font-style: normal; +} + +/* a markup attribute value */ +.atv { + color: #006400; + font-weight: normal; + font-style: normal; +} + +/* a declaration */ +.dec { + color: #000000; + font-weight: bold; + font-style: normal; +} + +/* a variable name */ +.var { + color: #000000; + font-weight: normal; + font-style: normal; +} + +/* a function name */ +.fun { + color: #000000; + font-weight: bold; + font-style: normal; +} + +/* Specify class=linenums on a pre to get line numbering */ +ol.linenums { + margin-top: 0; + margin-bottom: 0; +} diff --git a/styles/prettify-tomorrow.css b/styles/prettify-tomorrow.css new file mode 100644 index 000000000..81e74d135 --- /dev/null +++ b/styles/prettify-tomorrow.css @@ -0,0 +1,132 @@ +/* Tomorrow Theme */ +/* Original theme - https://github.com/chriskempson/tomorrow-theme */ +/* Pretty printing styles. Used with prettify.js. */ +/* SPAN elements with the classes below are added by prettyprint. */ +/* plain text */ +.pln { + color: #4d4d4c; } + +@media screen { + /* string content */ + .str { + color: hsl(104, 100%, 24%); } + + /* a keyword */ + .kwd { + color: hsl(240, 100%, 50%); } + + /* a comment */ + .com { + color: hsl(0, 0%, 60%); } + + /* a type name */ + .typ { + color: hsl(240, 100%, 32%); } + + /* a literal value */ + .lit { + color: hsl(240, 100%, 40%); } + + /* punctuation */ + .pun { + color: #000000; } + + /* lisp open bracket */ + .opn { + color: #000000; } + + /* lisp close bracket */ + .clo { + color: #000000; } + + /* a markup tag name */ + .tag { + color: #c82829; } + + /* a markup attribute name */ + .atn { + color: #f5871f; } + + /* a markup attribute value */ + .atv { + color: #3e999f; } + + /* a declaration */ + .dec { + color: #f5871f; } + + /* a variable name */ + .var { + color: #c82829; } + + /* a function name */ + .fun { + color: #4271ae; } } +/* Use higher contrast and text-weight for printable form. */ +@media print, projection { + .str { + color: #060; } + + .kwd { + color: #006; + font-weight: bold; } + + .com { + color: #600; + font-style: italic; } + + .typ { + color: #404; + font-weight: bold; } + + .lit { + color: #044; } + + .pun, .opn, .clo { + color: #440; } + + .tag { + color: #006; + font-weight: bold; } + + .atn { + color: #404; } + + .atv { + color: #060; } } +/* Style */ +/* +pre.prettyprint { + background: white; + font-family: Consolas, Monaco, 'Andale Mono', monospace; + font-size: 12px; + line-height: 1.5; + border: 1px solid #ccc; + padding: 10px; } +*/ + +/* Specify class=linenums on a pre to get line numbering */ +ol.linenums { + margin-top: 0; + margin-bottom: 0; } + +/* IE indents via margin-left */ +li.L0, +li.L1, +li.L2, +li.L3, +li.L4, +li.L5, +li.L6, +li.L7, +li.L8, +li.L9 { + /* */ } + +/* Alternate shading for lines */ +li.L1, +li.L3, +li.L5, +li.L7, +li.L9 { + /* */ } diff --git a/timeout.js.html b/timeout.js.html new file mode 100644 index 000000000..cf29f3677 --- /dev/null +++ b/timeout.js.html @@ -0,0 +1,180 @@ + + + + + + + timeout.js - Documentation + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +

timeout.js

+ + + + + + + +
+
+
import initialParams from './internal/initialParams';
+
+/**
+ * Sets a time limit on an asynchronous function. If the function does not call
+ * its callback within the specified milliseconds, it will be called with a
+ * timeout error. The code property for the error object will be `'ETIMEDOUT'`.
+ *
+ * @name timeout
+ * @static
+ * @memberOf module:Utils
+ * @method
+ * @category Util
+ * @param {Function} asyncFn - The asynchronous function you want to set the
+ * time limit.
+ * @param {number} milliseconds - The specified time limit.
+ * @param {*} [info] - Any variable you want attached (`string`, `object`, etc)
+ * to timeout Error for more information..
+ * @returns {Function} Returns a wrapped function that can be used with any of
+ * the control flow functions. Invoke this function with the same
+ * parameters as you would `asyncFunc`.
+ * @example
+ *
+ * function myFunction(foo, callback) {
+ *     doAsyncTask(foo, function(err, data) {
+ *         // handle errors
+ *         if (err) return callback(err);
+ *
+ *         // do some stuff ...
+ *
+ *         // return processed data
+ *         return callback(null, data);
+ *     });
+ * }
+ *
+ * var wrapped = async.timeout(myFunction, 1000);
+ *
+ * // call `wrapped` as you would `myFunction`
+ * wrapped({ bar: 'bar' }, function(err, data) {
+ *     // if `myFunction` takes < 1000 ms to execute, `err`
+ *     // and `data` will have their expected values
+ *
+ *     // else `err` will be an Error with the code 'ETIMEDOUT'
+ * });
+ */
+export default function timeout(asyncFn, milliseconds, info) {
+    var originalCallback, timer;
+    var timedOut = false;
+
+    function injectedCallback() {
+        if (!timedOut) {
+            originalCallback.apply(null, arguments);
+            clearTimeout(timer);
+        }
+    }
+
+    function timeoutCallback() {
+        var name = asyncFn.name || 'anonymous';
+        var error  = new Error('Callback function "' + name + '" timed out.');
+        error.code = 'ETIMEDOUT';
+        if (info) {
+            error.info = info;
+        }
+        timedOut = true;
+        originalCallback(error);
+    }
+
+    return initialParams(function (args, origCallback) {
+        originalCallback = origCallback;
+        // setup timer and call original function
+        timer = setTimeout(timeoutCallback, milliseconds);
+        asyncFn.apply(null, args.concat(injectedCallback));
+    });
+}
+
+
+
+ + + + +
+ Documentation generated by JSDoc 3.4.3 on Tue Mar 28 2017 00:02:51 GMT-0400 (EDT) using the Minami theme. + Documentation has been modified from the original. For more information, please see the async repository.
+
+ + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/times.js.html b/times.js.html new file mode 100644 index 000000000..1ad191e19 --- /dev/null +++ b/times.js.html @@ -0,0 +1,143 @@ + + + + + + + times.js - Documentation + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +

times.js

+ + + + + + + +
+
+
import timesLimit from './timesLimit';
+import doLimit from './internal/doLimit';
+
+/**
+ * Calls the `iteratee` function `n` times, and accumulates results in the same
+ * manner you would use with [map]{@link module:Collections.map}.
+ *
+ * @name times
+ * @static
+ * @memberOf module:ControlFlow
+ * @method
+ * @see [async.map]{@link module:Collections.map}
+ * @category Control Flow
+ * @param {number} n - The number of times to run the function.
+ * @param {Function} iteratee - The function to call `n` times. Invoked with the
+ * iteration index and a callback (n, next).
+ * @param {Function} callback - see {@link module:Collections.map}.
+ * @example
+ *
+ * // Pretend this is some complicated async factory
+ * var createUser = function(id, callback) {
+ *     callback(null, {
+ *         id: 'user' + id
+ *     });
+ * };
+ *
+ * // generate 5 users
+ * async.times(5, function(n, next) {
+ *     createUser(n, function(err, user) {
+ *         next(err, user);
+ *     });
+ * }, function(err, users) {
+ *     // we should now have 5 users
+ * });
+ */
+export default doLimit(timesLimit, Infinity);
+
+
+
+ + + + +
+ Documentation generated by JSDoc 3.4.3 on Tue Mar 28 2017 00:02:51 GMT-0400 (EDT) using the Minami theme. + Documentation has been modified from the original. For more information, please see the async repository.
+
+ + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/timesLimit.js.html b/timesLimit.js.html new file mode 100644 index 000000000..bcbd96837 --- /dev/null +++ b/timesLimit.js.html @@ -0,0 +1,129 @@ + + + + + + + timesLimit.js - Documentation + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +

timesLimit.js

+ + + + + + + +
+
+
import mapLimit from './mapLimit';
+import range from 'lodash/_baseRange';
+
+/**
+ * The same as [times]{@link module:ControlFlow.times} but runs a maximum of `limit` async operations at a
+ * time.
+ *
+ * @name timesLimit
+ * @static
+ * @memberOf module:ControlFlow
+ * @method
+ * @see [async.times]{@link module:ControlFlow.times}
+ * @category Control Flow
+ * @param {number} count - The number of times to run the function.
+ * @param {number} limit - The maximum number of async operations at a time.
+ * @param {Function} iteratee - The function to call `n` times. Invoked with the
+ * iteration index and a callback (n, next).
+ * @param {Function} callback - see [async.map]{@link module:Collections.map}.
+ */
+export default function timeLimit(count, limit, iteratee, callback) {
+    mapLimit(range(0, count, 1), limit, iteratee, callback);
+}
+
+
+
+ + + + +
+ Documentation generated by JSDoc 3.4.3 on Tue Mar 28 2017 00:02:51 GMT-0400 (EDT) using the Minami theme. + Documentation has been modified from the original. For more information, please see the async repository.
+
+ + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/timesSeries.js.html b/timesSeries.js.html new file mode 100644 index 000000000..c992ca1ec --- /dev/null +++ b/timesSeries.js.html @@ -0,0 +1,125 @@ + + + + + + + timesSeries.js - Documentation + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +

timesSeries.js

+ + + + + + + +
+
+
import timesLimit from './timesLimit';
+import doLimit from './internal/doLimit';
+
+/**
+ * The same as [times]{@link module:ControlFlow.times} but runs only a single async operation at a time.
+ *
+ * @name timesSeries
+ * @static
+ * @memberOf module:ControlFlow
+ * @method
+ * @see [async.times]{@link module:ControlFlow.times}
+ * @category Control Flow
+ * @param {number} n - The number of times to run the function.
+ * @param {Function} iteratee - The function to call `n` times. Invoked with the
+ * iteration index and a callback (n, next).
+ * @param {Function} callback - see {@link module:Collections.map}.
+ */
+export default doLimit(timesLimit, 1);
+
+
+
+ + + + +
+ Documentation generated by JSDoc 3.4.3 on Tue Mar 28 2017 00:02:51 GMT-0400 (EDT) using the Minami theme. + Documentation has been modified from the original. For more information, please see the async repository.
+
+ + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/transform.js.html b/transform.js.html new file mode 100644 index 000000000..ac1285b7c --- /dev/null +++ b/transform.js.html @@ -0,0 +1,172 @@ + + + + + + + transform.js - Documentation + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +

transform.js

+ + + + + + + +
+
+
import isArray from 'lodash/isArray';
+import noop from 'lodash/noop';
+
+import eachOf from './eachOf';
+import once from './internal/once';
+
+/**
+ * A relative of `reduce`.  Takes an Object or Array, and iterates over each
+ * element in series, each step potentially mutating an `accumulator` value.
+ * The type of the accumulator defaults to the type of collection passed in.
+ *
+ * @name transform
+ * @static
+ * @memberOf module:Collections
+ * @method
+ * @category Collection
+ * @param {Array|Iterable|Object} coll - A collection to iterate over.
+ * @param {*} [accumulator] - The initial state of the transform.  If omitted,
+ * it will default to an empty Object or Array, depending on the type of `coll`
+ * @param {Function} iteratee - A function applied to each item in the
+ * collection that potentially modifies the accumulator. The `iteratee` is
+ * passed a `callback(err)` which accepts an optional error as its first
+ * argument. If an error is passed to the callback, the transform is stopped
+ * and the main `callback` is immediately called with the error.
+ * Invoked with (accumulator, item, key, callback).
+ * @param {Function} [callback] - A callback which is called after all the
+ * `iteratee` functions have finished. Result is the transformed accumulator.
+ * Invoked with (err, result).
+ * @example
+ *
+ * async.transform([1,2,3], function(acc, item, index, callback) {
+ *     // pointless async:
+ *     process.nextTick(function() {
+ *         acc.push(item * 2)
+ *         callback(null)
+ *     });
+ * }, function(err, result) {
+ *     // result is now equal to [2, 4, 6]
+ * });
+ *
+ * @example
+ *
+ * async.transform({a: 1, b: 2, c: 3}, function (obj, val, key, callback) {
+ *     setImmediate(function () {
+ *         obj[key] = val * 2;
+ *         callback();
+ *     })
+ * }, function (err, result) {
+ *     // result is equal to {a: 2, b: 4, c: 6}
+ * })
+ */
+export default function transform (coll, accumulator, iteratee, callback) {
+    if (arguments.length === 3) {
+        callback = iteratee;
+        iteratee = accumulator;
+        accumulator = isArray(coll) ? [] : {};
+    }
+    callback = once(callback || noop);
+
+    eachOf(coll, function(v, k, cb) {
+        iteratee(accumulator, v, k, cb);
+    }, function(err) {
+        callback(err, accumulator);
+    });
+}
+
+
+
+ + + + +
+ Documentation generated by JSDoc 3.4.3 on Tue Mar 28 2017 00:02:51 GMT-0400 (EDT) using the Minami theme. + Documentation has been modified from the original. For more information, please see the async repository.
+
+ + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/unmemoize.js.html b/unmemoize.js.html new file mode 100644 index 000000000..99da85434 --- /dev/null +++ b/unmemoize.js.html @@ -0,0 +1,125 @@ + + + + + + + unmemoize.js - Documentation + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +

unmemoize.js

+ + + + + + + +
+
+
/**
+ * Undoes a [memoize]{@link module:Utils.memoize}d function, reverting it to the original,
+ * unmemoized form. Handy for testing.
+ *
+ * @name unmemoize
+ * @static
+ * @memberOf module:Utils
+ * @method
+ * @see [async.memoize]{@link module:Utils.memoize}
+ * @category Util
+ * @param {Function} fn - the memoized function
+ * @returns {Function} a function that calls the original unmemoized function
+ */
+export default  function unmemoize(fn) {
+    return function () {
+        return (fn.unmemoized || fn).apply(null, arguments);
+    };
+}
+
+
+
+ + + + +
+ Documentation generated by JSDoc 3.4.3 on Tue Mar 28 2017 00:02:51 GMT-0400 (EDT) using the Minami theme. + Documentation has been modified from the original. For more information, please see the async repository.
+
+ + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/until.js.html b/until.js.html new file mode 100644 index 000000000..9222b9e60 --- /dev/null +++ b/until.js.html @@ -0,0 +1,137 @@ + + + + + + + until.js - Documentation + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +

until.js

+ + + + + + + +
+
+
import whilst from './whilst';
+
+/**
+ * Repeatedly call `fn` until `test` returns `true`. Calls `callback` when
+ * stopped, or an error occurs. `callback` will be passed an error and any
+ * arguments passed to the final `fn`'s callback.
+ *
+ * The inverse of [whilst]{@link module:ControlFlow.whilst}.
+ *
+ * @name until
+ * @static
+ * @memberOf module:ControlFlow
+ * @method
+ * @see [async.whilst]{@link module:ControlFlow.whilst}
+ * @category Control Flow
+ * @param {Function} test - synchronous truth test to perform before each
+ * execution of `fn`. Invoked with ().
+ * @param {Function} fn - A function which is called each time `test` fails.
+ * The function is passed a `callback(err)`, which must be called once it has
+ * completed with an optional `err` argument. Invoked with (callback).
+ * @param {Function} [callback] - A callback which is called after the test
+ * function has passed and repeated execution of `fn` has stopped. `callback`
+ * will be passed an error and any arguments passed to the final `fn`'s
+ * callback. Invoked with (err, [results]);
+ */
+export default function until(test, fn, callback) {
+    whilst(function() {
+        return !test.apply(this, arguments);
+    }, fn, callback);
+}
+
+
+
+ + + + +
+ Documentation generated by JSDoc 3.4.3 on Tue Mar 28 2017 00:02:51 GMT-0400 (EDT) using the Minami theme. + Documentation has been modified from the original. For more information, please see the async repository.
+
+ + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/waterfall.js.html b/waterfall.js.html new file mode 100644 index 000000000..1c8ab85bd --- /dev/null +++ b/waterfall.js.html @@ -0,0 +1,197 @@ + + + + + + + waterfall.js - Documentation + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +

waterfall.js

+ + + + + + + +
+
+
import isArray from 'lodash/isArray';
+import noop from 'lodash/noop';
+import once from './internal/once';
+import rest from './internal/rest';
+
+import onlyOnce from './internal/onlyOnce';
+
+/**
+ * Runs the `tasks` array of functions in series, each passing their results to
+ * the next in the array. However, if any of the `tasks` pass an error to their
+ * own callback, the next function is not executed, and the main `callback` is
+ * immediately called with the error.
+ *
+ * @name waterfall
+ * @static
+ * @memberOf module:ControlFlow
+ * @method
+ * @category Control Flow
+ * @param {Array} tasks - An array of functions to run, each function is passed
+ * a `callback(err, result1, result2, ...)` it must call on completion. The
+ * first argument is an error (which can be `null`) and any further arguments
+ * will be passed as arguments in order to the next task.
+ * @param {Function} [callback] - An optional callback to run once all the
+ * functions have completed. This will be passed the results of the last task's
+ * callback. Invoked with (err, [results]).
+ * @returns undefined
+ * @example
+ *
+ * async.waterfall([
+ *     function(callback) {
+ *         callback(null, 'one', 'two');
+ *     },
+ *     function(arg1, arg2, callback) {
+ *         // arg1 now equals 'one' and arg2 now equals 'two'
+ *         callback(null, 'three');
+ *     },
+ *     function(arg1, callback) {
+ *         // arg1 now equals 'three'
+ *         callback(null, 'done');
+ *     }
+ * ], function (err, result) {
+ *     // result now equals 'done'
+ * });
+ *
+ * // Or, with named functions:
+ * async.waterfall([
+ *     myFirstFunction,
+ *     mySecondFunction,
+ *     myLastFunction,
+ * ], function (err, result) {
+ *     // result now equals 'done'
+ * });
+ * function myFirstFunction(callback) {
+ *     callback(null, 'one', 'two');
+ * }
+ * function mySecondFunction(arg1, arg2, callback) {
+ *     // arg1 now equals 'one' and arg2 now equals 'two'
+ *     callback(null, 'three');
+ * }
+ * function myLastFunction(arg1, callback) {
+ *     // arg1 now equals 'three'
+ *     callback(null, 'done');
+ * }
+ */
+export default  function(tasks, callback) {
+    callback = once(callback || noop);
+    if (!isArray(tasks)) return callback(new Error('First argument to waterfall must be an array of functions'));
+    if (!tasks.length) return callback();
+    var taskIndex = 0;
+
+    function nextTask(args) {
+        if (taskIndex === tasks.length) {
+            return callback.apply(null, [null].concat(args));
+        }
+
+        var taskCallback = onlyOnce(rest(function(err, args) {
+            if (err) {
+                return callback.apply(null, [err].concat(args));
+            }
+            nextTask(args);
+        }));
+
+        args.push(taskCallback);
+
+        var task = tasks[taskIndex++];
+        task.apply(null, args);
+    }
+
+    nextTask([]);
+}
+
+
+
+ + + + +
+ Documentation generated by JSDoc 3.4.3 on Tue Mar 28 2017 00:02:51 GMT-0400 (EDT) using the Minami theme. + Documentation has been modified from the original. For more information, please see the async repository.
+
+ + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/whilst.js.html b/whilst.js.html new file mode 100644 index 000000000..16d04b72a --- /dev/null +++ b/whilst.js.html @@ -0,0 +1,157 @@ + + + + + + + whilst.js - Documentation + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +

whilst.js

+ + + + + + + +
+
+
import noop from 'lodash/noop';
+import rest from './internal/rest';
+
+import onlyOnce from './internal/onlyOnce';
+
+/**
+ * Repeatedly call `iteratee`, while `test` returns `true`. Calls `callback` when
+ * stopped, or an error occurs.
+ *
+ * @name whilst
+ * @static
+ * @memberOf module:ControlFlow
+ * @method
+ * @category Control Flow
+ * @param {Function} test - synchronous truth test to perform before each
+ * execution of `iteratee`. Invoked with ().
+ * @param {Function} iteratee - A function which is called each time `test` passes.
+ * The function is passed a `callback(err)`, which must be called once it has
+ * completed with an optional `err` argument. Invoked with (callback).
+ * @param {Function} [callback] - A callback which is called after the test
+ * function has failed and repeated execution of `iteratee` has stopped. `callback`
+ * will be passed an error and any arguments passed to the final `iteratee`'s
+ * callback. Invoked with (err, [results]);
+ * @returns undefined
+ * @example
+ *
+ * var count = 0;
+ * async.whilst(
+ *     function() { return count < 5; },
+ *     function(callback) {
+ *         count++;
+ *         setTimeout(function() {
+ *             callback(null, count);
+ *         }, 1000);
+ *     },
+ *     function (err, n) {
+ *         // 5 seconds have passed, n = 5
+ *     }
+ * );
+ */
+export default function whilst(test, iteratee, callback) {
+    callback = onlyOnce(callback || noop);
+    if (!test()) return callback(null);
+    var next = rest(function(err, args) {
+        if (err) return callback(err);
+        if (test()) return iteratee(next);
+        callback.apply(null, [null].concat(args));
+    });
+    iteratee(next);
+}
+
+
+
+ + + + +
+ Documentation generated by JSDoc 3.4.3 on Tue Mar 28 2017 00:02:51 GMT-0400 (EDT) using the Minami theme. + Documentation has been modified from the original. For more information, please see the async repository.
+
+ + + +
+ + + + + + + + + + + + + + + \ No newline at end of file