From 45e4d8c73c35401ac2c9eb2d600ac3a5c4e82fc9 Mon Sep 17 00:00:00 2001 From: Alexander Early Date: Sat, 27 Feb 2016 16:40:24 -0800 Subject: stop running tasks after an error. fixes #1023 --- lib/auto.js | 5 ++++- mocha_test/auto.js | 31 ++++++++++++++++++++++++------- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/lib/auto.js b/lib/auto.js index 21fbb08..0e9d108 100644 --- a/lib/auto.js +++ b/lib/auto.js @@ -72,6 +72,7 @@ export default function (tasks, concurrency, callback) { }); safeResults[k] = args; hasError = true; + listeners = []; callback(err, safeResults); } @@ -106,7 +107,9 @@ export default function (tasks, concurrency, callback) { } function ready() { - return runningTasks < concurrency && !baseHas(results, k) && + return runningTasks < concurrency && + !baseHas(results, k) && + !hasError && arrayEvery(requires, function (x) { return baseHas(results, x); }); diff --git a/mocha_test/auto.js b/mocha_test/auto.js index cc80aed..c6b7150 100644 --- a/mocha_test/auto.js +++ b/mocha_test/auto.js @@ -1,8 +1,8 @@ var async = require('../lib'); var expect = require('chai').expect; -var _ = require("lodash"); +var _ = require('lodash'); -describe("auto", function () { +describe('auto', function () { it('auto', function(done){ var callOrder = []; @@ -235,7 +235,7 @@ describe("auto", function () { // Error throwing final callback. This should only run once function() { finalCallCount++; - var e = new Error("An error"); + var e = new Error('An error'); e._test_error = true; throw e; }); @@ -249,12 +249,12 @@ describe("auto", function () { it('auto calls callback multiple times with parallel functions', function(done) { async.auto({ - task1: function(callback) { setTimeout(callback,0,"err"); }, - task2: function(callback) { setTimeout(callback,0,"err"); } + task1: function(callback) { setTimeout(callback,0,'err'); }, + task2: function(callback) { setTimeout(callback,0,'err'); } }, // Error throwing final callback. This should only run once function(err) { - expect(err).to.equal("err"); + expect(err).to.equal('err'); done(); }); }); @@ -266,7 +266,7 @@ describe("auto", function () { task1: function(callback){ callback(null, 'task1'); }, - task2: ["task1", function(results, callback){ + task2: ['task1', function(results, callback){ results.inserted = true; setTimeout(function(){ callback(null, 'task2'); @@ -327,4 +327,21 @@ describe("auto", function () { }); }); + it('ignores results after an error', function (done) { + async.auto({ + task1: function (cb) { + setTimeout(cb, 25, 'error'); + }, + task2: function (cb) { + setTimeout(cb, 30, null); + }, + task3: ['task2', function () { + throw new Error("task should not have been called"); + }] + }, function (err) { + expect(err).to.equal('error'); + setTimeout(done, 25, null); + }); + }); + }); -- cgit v1.2.1