summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/auto.js14
-rw-r--r--lib/internal/parallel.js12
-rw-r--r--lib/internal/slice.js9
-rw-r--r--lib/waterfall.js10
4 files changed, 28 insertions, 17 deletions
diff --git a/lib/auto.js b/lib/auto.js
index ba0fdc3..d712cc1 100644
--- a/lib/auto.js
+++ b/lib/auto.js
@@ -4,7 +4,7 @@ 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 slice from 'lodash/slice';
import once from './internal/once';
import onlyOnce from './internal/onlyOnce';
@@ -192,26 +192,26 @@ export default function (tasks, concurrency, callback) {
function runTask(key, task) {
if (hasError) return;
- var taskCallback = onlyOnce(rest(function(err, args) {
+ var taskCallback = onlyOnce(function(err, result) {
runningTasks--;
- if (args.length <= 1) {
- args = args[0];
+ if (arguments.length > 2) {
+ result = slice(arguments, 1);
}
if (err) {
var safeResults = {};
forOwn(results, function(val, rkey) {
safeResults[rkey] = val;
});
- safeResults[key] = args;
+ safeResults[key] = result;
hasError = true;
listeners = Object.create(null);
callback(err, safeResults);
} else {
- results[key] = args;
+ results[key] = result;
taskComplete(key);
}
- }));
+ });
runningTasks++;
var taskFn = wrapAsync(task[task.length - 1]);
diff --git a/lib/internal/parallel.js b/lib/internal/parallel.js
index 70993d3..f4e9347 100644
--- a/lib/internal/parallel.js
+++ b/lib/internal/parallel.js
@@ -1,6 +1,6 @@
import noop from 'lodash/noop';
import isArrayLike from 'lodash/isArrayLike';
-import rest from './rest';
+import slice from './slice';
import wrapAsync from './wrapAsync';
export default function _parallel(eachfn, tasks, callback) {
@@ -8,13 +8,13 @@ export default function _parallel(eachfn, tasks, callback) {
var results = isArrayLike(tasks) ? [] : {};
eachfn(tasks, function (task, key, callback) {
- wrapAsync(task)(rest(function (err, args) {
- if (args.length <= 1) {
- args = args[0];
+ wrapAsync(task)(function (err, result) {
+ if (arguments.length > 2) {
+ result = slice(arguments, 1);
}
- results[key] = args;
+ results[key] = result;
callback(err);
- }));
+ });
}, function (err) {
callback(err, results);
});
diff --git a/lib/internal/slice.js b/lib/internal/slice.js
new file mode 100644
index 0000000..cd2e5b3
--- /dev/null
+++ b/lib/internal/slice.js
@@ -0,0 +1,9 @@
+export default function slice(arrayLike, start) {
+ start = start|0;
+ var newLen = Math.max(arrayLike.length - start, 0);
+ var newArr = Array(newLen);
+ for(var idx = 0; idx < newLen; idx++) {
+ newArr[idx] = arrayLike[start + idx];
+ }
+ return newArr;
+}
diff --git a/lib/waterfall.js b/lib/waterfall.js
index 24befac..bfcf7a4 100644
--- a/lib/waterfall.js
+++ b/lib/waterfall.js
@@ -2,6 +2,7 @@ import isArray from 'lodash/isArray';
import noop from 'lodash/noop';
import once from './internal/once';
import rest from './internal/rest';
+import slice from './internal/slice';
import onlyOnce from './internal/onlyOnce';
import wrapAsync from './internal/wrapAsync';
@@ -74,12 +75,13 @@ export default function(tasks, callback) {
return callback.apply(null, [null].concat(args));
}
- var taskCallback = onlyOnce(rest(function(err, args) {
+ var taskCallback = onlyOnce(function(err/*, cbArgs...*/) {
+ var cbArgs = slice(arguments, 1);
if (err) {
- return callback.apply(null, [err].concat(args));
+ return callback.apply(null, [err].concat(cbArgs));
}
- nextTask(args);
- }));
+ nextTask(cbArgs);
+ });
args.push(taskCallback);