diff options
author | Graeme Yeates <yeatesgraeme@gmail.com> | 2016-03-06 18:15:26 -0500 |
---|---|---|
committer | Graeme Yeates <yeatesgraeme@gmail.com> | 2016-03-06 18:15:26 -0500 |
commit | f75579366c69940dad5d4ee0b6b7070485701481 (patch) | |
tree | b2eeb570299083f6de1075ba15bb5f6a317860ba | |
parent | f38483cbccc16efe205b0bf1439c233e61a7f090 (diff) | |
parent | 4d825639606b8db83c8e4c9c46b8e8771499071b (diff) | |
download | async-f75579366c69940dad5d4ee0b6b7070485701481.tar.gz |
Merge pull request #1048 from caolan/auto-multiple-callback-defense
Defend against multiple callbacks in auto
-rw-r--r-- | lib/auto.js | 5 | ||||
-rw-r--r-- | mocha_test/auto.js | 14 |
2 files changed, 16 insertions, 3 deletions
diff --git a/lib/auto.js b/lib/auto.js index 0e9d108..ae3ecfc 100644 --- a/lib/auto.js +++ b/lib/auto.js @@ -10,6 +10,7 @@ import okeys from 'lodash/keys'; import noop from 'lodash/noop'; import once from 'lodash/once'; import rest from 'lodash/rest'; +import onlyOnce from './internal/onlyOnce'; import setImmediate from './internal/setImmediate'; @@ -60,7 +61,7 @@ export default function (tasks, concurrency, callback) { arrayEach(keys, function (k) { if (hasError) return; var task = isArray(tasks[k]) ? tasks[k]: [tasks[k]]; - var taskCallback = rest(function(err, args) { + var taskCallback = onlyOnce(rest(function(err, args) { runningTasks--; if (args.length <= 1) { args = args[0]; @@ -80,7 +81,7 @@ export default function (tasks, concurrency, callback) { results[k] = args; setImmediate(taskComplete); } - }); + })); var requires = task.slice(0, task.length - 1); diff --git a/mocha_test/auto.js b/mocha_test/auto.js index c6b7150..6b96be4 100644 --- a/mocha_test/auto.js +++ b/mocha_test/auto.js @@ -4,7 +4,7 @@ var _ = require('lodash'); describe('auto', function () { - it('auto', function(done){ + it('basics', function(done){ var callOrder = []; async.auto({ task1: ['task2', function(results, callback){ @@ -344,4 +344,16 @@ describe('auto', function () { }); }); + it("does not allow calling callbacks twice", function () { + expect(function () { + async.auto({ + bad: function (cb) { + cb(); + cb(); + } + }, function () {}); + + }).to.throw(); + }); + }); |