diff options
author | Alexander Early <alexander.early@gmail.com> | 2018-06-03 17:44:18 -0700 |
---|---|---|
committer | Alexander Early <alexander.early@gmail.com> | 2018-06-03 17:44:18 -0700 |
commit | e56fea9f6f69ab03161a3b33a7369cdab3117134 (patch) | |
tree | 8da352d6587707d4b48ed115ad33b11a5f55560d | |
parent | 6d61acf4fb5e6f7ecee7e012ccd068b7d3a51616 (diff) | |
download | async-e56fea9f6f69ab03161a3b33a7369cdab3117134.tar.gz |
cancelable waterfall
-rw-r--r-- | lib/waterfall.js | 1 | ||||
-rw-r--r-- | test/parallel.js | 26 | ||||
-rw-r--r-- | test/waterfall.js | 22 |
3 files changed, 49 insertions, 0 deletions
diff --git a/lib/waterfall.js b/lib/waterfall.js index 3e71d2c..7f5c12e 100644 --- a/lib/waterfall.js +++ b/lib/waterfall.js @@ -75,6 +75,7 @@ export default function(tasks, callback) { } function next(err/*, ...args*/) { + if (err === null) return // canceled if (err || taskIndex === tasks.length) { return callback.apply(null, arguments); } diff --git a/test/parallel.js b/test/parallel.js index 2b07822..e4af6f8 100644 --- a/test/parallel.js +++ b/test/parallel.js @@ -191,6 +191,32 @@ describe('parallel', function() { }); }); + it('parallel limit canceled', function(done) { + const call_order = [] + async.parallelLimit([ + function(callback){ + call_order.push(1) + callback(); + }, + function(callback){ + call_order.push(2) + callback(false); + }, + function(callback){ + call_order.push(3) + callback('error', 2); + } + ], + 1, + function(err){ + throw new Error('should not get here') + }); + setTimeout(() => { + expect(call_order).to.eql([1, 2]); + done() + }, 25); + }); + it('parallel call in another context @nycinvalid @nodeonly', function(done) { var vm = require('vm'); var sandbox = { diff --git a/test/waterfall.js b/test/waterfall.js index 78b11bb..901d59b 100644 --- a/test/waterfall.js +++ b/test/waterfall.js @@ -90,6 +90,28 @@ describe("waterfall", function () { }); }); + + it('canceled', function(done){ + const call_order = [] + async.waterfall([ + function(callback){ + call_order.push(1) + callback(null); + }, + function(callback){ + call_order.push(2) + assert(false, 'next function should not be called'); + callback(); + } + ], function(err){ + throw new Error('should not get here') + }); + setTimeout(() => { + expect(call_order).to.eql([1]) + done() + }, 10) + }); + it('multiple callback calls', function(){ var arr = [ function(callback){ |