From b6eed6d756eb4f4f76ca3ac14ce822a3dacf7f38 Mon Sep 17 00:00:00 2001 From: Diogo Golovanevsky Monteiro Date: Sat, 20 Oct 2012 20:11:20 -0400 Subject: [PATCH] Added exitChain function. ExitChain function stop the execution of a Step chain of callbacks. --- lib/step.js | 4 ++++ test/exitChain.js | 25 +++++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 test/exitChain.js diff --git a/lib/step.js b/lib/step.js index b524a6a..fbe4840 100755 --- a/lib/step.js +++ b/lib/step.js @@ -118,6 +118,10 @@ function Step() { }; }; + next.exitChain = function () { + steps = new Array(); + } + // Start the engine an pass nothing to the first step. next(); } diff --git a/test/exitChain.js b/test/exitChain.js new file mode 100644 index 0000000..c3bf7a2 --- /dev/null +++ b/test/exitChain.js @@ -0,0 +1,25 @@ +require('./helper'); + +var selfText = fs.readFileSync(__filename, 'utf8'); + +// This example tests stopping a step chain before running all the registered steps + +expect('one'); +expect('two'); +Step( + function readSelf() { + fulfill("one"); + fs.readFile(__filename, 'utf8', this); + }, + function capitalize(err, text) { + fulfill("two"); + if (err) throw err; + assert.equal(selfText, text, "Text Loaded"); + return this.exitChain(); + }, + function showIt(err, newText) { + expect("three"); + if (err) throw err; + assert.equal(selfText.toUpperCase(), newText, "Text Uppercased"); + } +);