Skip to content

Commit

Permalink
handle no-dependency array tasks in auto/autoInject. Closes #1147
Browse files Browse the repository at this point in the history
  • Loading branch information
aearly committed May 9, 2016
1 parent eaba68f commit e235125
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
5 changes: 3 additions & 2 deletions lib/auto.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,10 @@ export default function (tasks, concurrency, callback) {

var dependencies = task.slice(0, task.length - 1);
var remainingDependencies = dependencies.length;
if (!remainingDependencies) {
enqueueTask(key, [task]);
if (remainingDependencies === 0) {
enqueueTask(key, task);
readyToCheck.push(key);
return;
}
uncheckedDependencies[key] = remainingDependencies;

Expand Down
2 changes: 1 addition & 1 deletion lib/autoInject.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export default function autoInject(tasks, callback) {
params = clone(taskFn);
taskFn = params.pop();

newTasks[key] = params.concat(newTask);
newTasks[key] = params.concat(params.length > 0 ? newTask : taskFn);
} else if (taskFn.length === 0) {
throw new Error("autoInject task functions require explicit parameters.");
} else if (taskFn.length === 1) {
Expand Down
12 changes: 12 additions & 0 deletions mocha_test/auto.js
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,18 @@ describe('auto', function () {
}).to.throw();
});

it('should handle array tasks with just a function', function (done) {
async.auto({
a: [function (cb) {
cb(null, 1);
}],
b: ["a", function (results, cb) {
expect(results.a).to.equal(1);
cb();
}]
}, done)
});

it("should avoid unncecessary deferrals", function (done) {
var isSync = true;

Expand Down
12 changes: 12 additions & 0 deletions mocha_test/autoInject.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,16 @@ describe('autoInject', function () {
});
});

it('should handle array tasks with just a function', function (done) {
async.autoInject({
a: [function (cb) {
cb(null, 1);
}],
b: ["a", function (a, cb) {
expect(a).to.equal(1);
cb();
}]
}, done)
});

});

0 comments on commit e235125

Please sign in to comment.