summaryrefslogtreecommitdiff
path: root/dist/async.js
diff options
context:
space:
mode:
Diffstat (limited to 'dist/async.js')
-rw-r--r--dist/async.js66
1 files changed, 46 insertions, 20 deletions
diff --git a/dist/async.js b/dist/async.js
index a0f30b0..c4fbcef 100644
--- a/dist/async.js
+++ b/dist/async.js
@@ -2235,9 +2235,10 @@ function queue(worker, concurrency, payload) {
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);
+ workersList.splice(index, 1);
}
task.callback.apply(task, arguments);
@@ -2298,11 +2299,11 @@ function queue(worker, concurrency, payload) {
for (var i = 0; i < l; i++) {
var node = q._tasks.shift();
tasks.push(node);
+ workersList.push(node);
data.push(node.data);
}
numRunning += 1;
- workersList.push(tasks[0]);
if (q._tasks.length === 0) {
q.empty();
@@ -2596,17 +2597,45 @@ var compose = function(/*...args*/) {
return seq.apply(null, slice(arguments).reverse());
};
-function concat$1(eachfn, arr, fn, callback) {
- var result = [];
- eachfn(arr, function (x, index, cb) {
- fn(x, function (err, y) {
- result = result.concat(y || []);
- cb(err);
+var _concat = Array.prototype.concat;
+
+/**
+ * The same as [`concat`]{@link module:Collections.concat} but runs a maximum of `limit` async operations at a time.
+ *
+ * @name concatLimit
+ * @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 {number} limit - The maximum number of async operations at a time.
+ * @param {AsyncFunction} iteratee - A function to apply to each item in `coll`,
+ * which should use an array as its result. 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 an array
+ * containing the concatenated results of the `iteratee` function. Invoked with
+ * (err, results).
+ */
+var concatLimit = function(coll, limit, iteratee, callback) {
+ callback = callback || noop;
+ var _iteratee = wrapAsync(iteratee);
+ mapLimit(coll, limit, function(val, callback) {
+ _iteratee(val, function(err /*, ...args*/) {
+ if (err) return callback(err);
+ return callback(null, slice(arguments, 1));
});
- }, function (err) {
- callback(err, result);
+ }, function(err, mapResults) {
+ var result = [];
+ for (var i = 0; i < mapResults.length; i++) {
+ if (mapResults[i]) {
+ result = _concat.apply(result, mapResults[i]);
+ }
+ }
+
+ return callback(err, result);
});
-}
+};
/**
* Applies `iteratee` to each item in `coll`, concatenating the results. Returns
@@ -2633,13 +2662,7 @@ function concat$1(eachfn, arr, fn, callback) {
* // files is now a list of filenames that exist in the 3 directories
* });
*/
-var concat = doParallel(concat$1);
-
-function doSeries(fn) {
- return function (obj, iteratee, callback) {
- return fn(eachOfSeries, obj, wrapAsync(iteratee), callback);
- };
-}
+var concat = doLimit(concatLimit, Infinity);
/**
* The same as [`concat`]{@link module:Collections.concat} but runs only a single async operation at a time.
@@ -2659,7 +2682,7 @@ function doSeries(fn) {
* containing the concatenated results of the `iteratee` function. Invoked with
* (err, results).
*/
-var concatSeries = doSeries(concat$1);
+var concatSeries = doLimit(concatLimit, 1);
/**
* Returns a function that when called, calls-back with the values provided.
@@ -3985,7 +4008,8 @@ function parallelLimit$1(tasks, limit, callback) {
* @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()`.
+ * empties remaining tasks from the queue forcing it to go idle. No more tasks
+ * should be pushed to the queue after calling this function. Invoke with `queue.kill()`.
*/
/**
@@ -5358,6 +5382,7 @@ var index = {
cargo: cargo,
compose: compose,
concat: concat,
+ concatLimit: concatLimit,
concatSeries: concatSeries,
constant: constant,
detect: detect,
@@ -5454,6 +5479,7 @@ exports.autoInject = autoInject;
exports.cargo = cargo;
exports.compose = compose;
exports.concat = concat;
+exports.concatLimit = concatLimit;
exports.concatSeries = concatSeries;
exports.constant = constant;
exports.detect = detect;