Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/auto.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,11 @@ export default function auto(tasks, concurrency, callback) {
readyToCheck.push(key);
return;
}
uncheckedDependencies[key] = remainingDependencies;
// count each dependency once, because getDependents() reports a
// dependent once even when it lists the same dependency twice
uncheckedDependencies[key] = dependencies.filter(
(name, index) => dependencies.indexOf(name) === index
).length;

dependencies.forEach(dependencyName => {
if (!tasks[dependencyName]) {
Expand Down
32 changes: 32 additions & 0 deletions test/auto.js
Original file line number Diff line number Diff line change
Expand Up @@ -489,4 +489,36 @@ describe('auto', () => {
});
});

it('auto with a dependency listed more than once', (done) => {
var callOrder = [];
async.auto({
task1(callback) {
callOrder.push('task1');
callback(null, 1);
},
task2: ['task1', 'task1', function(results, callback) {
callOrder.push('task2');
callback(null, results.task1 + 1);
}],
task3: ['task2', 'task1', 'task2', function(results, callback) {
callOrder.push('task3');
callback(null, results.task2 + 1);
}]
}, (err, results) => {
expect(err).to.equal(null);
expect(results).to.eql({task1: 1, task2: 2, task3: 3});
expect(callOrder).to.eql(['task1', 'task2', 'task3']);
done();
});
});

it('auto still detects a cycle when a dependency is listed more than once', () => {
expect(() => {
async.auto({
task1: ['task2', 'task2', function(results, callback) { callback(null); }],
task2: ['task1', function(results, callback) { callback(null); }]
});
}).to.throw(/recursive dependency/);
});

});