summaryrefslogtreecommitdiff
path: root/lib/concatLimit.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/concatLimit.js')
-rw-r--r--lib/concatLimit.js30
1 files changed, 26 insertions, 4 deletions
diff --git a/lib/concatLimit.js b/lib/concatLimit.js
index a86fd74..4df03ea 100644
--- a/lib/concatLimit.js
+++ b/lib/concatLimit.js
@@ -1,5 +1,9 @@
-import doParallelLimit from './internal/doParallelLimit';
-import concat from './internal/concat';
+import noop from 'lodash/noop';
+import wrapAsync from './internal/wrapAsync';
+import slice from './internal/slice';
+import mapLimit from './mapLimit';
+
+var _concat = Array.prototype.concat;
/**
* The same as [`concat`]{@link module:Collections.concat} but runs a maximum of `limit` async operations at a time.
@@ -14,9 +18,27 @@ import concat from './internal/concat';
* @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(err)] - A callback which is called after all the
+ * @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).
*/
-export default doParallelLimit(concat);
+export default 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, mapResults) {
+ var result = [];
+ for (var i = 0; i < mapResults.length; i++) {
+ if (mapResults[i]) {
+ result = _concat.apply(result, mapResults[i]);
+ }
+ }
+
+ return callback(err, result);
+ });
+}