Skip to content

Commit

Permalink
added drop method to baton to cancel workflow execution
Browse files Browse the repository at this point in the history
  • Loading branch information
gtanner committed Feb 14, 2012
1 parent 7d89868 commit 87bc7e6
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 5 deletions.
13 changes: 13 additions & 0 deletions README.rdoc
Expand Up @@ -152,6 +152,19 @@ at the same time.
jWorkflow.order([man, man, halfMan])
.andThen([jWorkflow.order([guy, guy]).andThen(girl), pizzaPlace]);

=Canceling Workflows

To cancel the execution of the workflow you can call the drop method on the baton:

function (previous, baton) {
//the value passed to drop will be passed onto the final callback if it exists
baton.drop("I dropped the soap");
//this value will NOT be passed to the next workflow step
return 10;
}

NOTE: This will force the workflow into async mode.

=Contributers:

Gord Tanner <gord@tinyhippos.com>
2 changes: 1 addition & 1 deletion Rakefile
Expand Up @@ -7,6 +7,6 @@ desc "Use the Closure Compiler to compress jWorkflow.js"
task :build do
js = File.open('lib/jWorkflow.js', 'r')
min = Closure::Compiler.new.compile(js)
File.open('jworkflow-min-0.6.0.js', 'w') {|f| f.write(min) }
File.open('jworkflow-min-0.7.0.js', 'w') {|f| f.write(min) }
end

3 changes: 0 additions & 3 deletions jworkflow-min-0.6.0.js

This file was deleted.

3 changes: 3 additions & 0 deletions jworkflow-min-0.7.0.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions lib/jWorkflow.js
Expand Up @@ -49,6 +49,14 @@ var jWorkflow = (function () {
_callback.func.apply(_callback.context, [result]);
}
}
},

drop: function (result) {
_taken = true;
_tasks = [];
setTimeout(function () {
_baton.pass(result);
}, 1);
}
};
}()),
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "jWorkflow",
"version" : "0.6.0",
"version" : "0.7.0",
"description" : "dude, wheres my workflow?",
"homepage": "https://github.com/tinyhippos/jWorkflow",
"author": "gtanner",
Expand Down
30 changes: 30 additions & 0 deletions test/test_jworkflow.js
Expand Up @@ -488,4 +488,34 @@ $(document).ready(function () {
equals(x, "sweeet");
});
});

asyncTest("jWorkflow, we can stop execution of a workflow with baton.drop", function () {
expect(2);

var inc = function (prev, baton) {
if (prev >= 3) {
baton.drop(prev);
}
return ++prev;
},
protected = false;

jWorkflow.order(inc)
.andThen(inc)
.andThen(inc)
.andThen(inc)
.andThen(inc)
.andThen(inc)
.andThen(function (prev) {
protected = true;
return prev;
}).start({
initialValue: 0,
callback: function (result) {
start();
equals(protected, false);
equals(result, 3);
}
});
});
});

0 comments on commit 87bc7e6

Please sign in to comment.