Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added drop method to baton to cancel workflow execution

  • Loading branch information...
commit 87bc7e67c94223ac138fb5a1c10e416333f4355e 1 parent 7d89868
@gtanner gtanner authored
View
13 README.rdoc
@@ -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>
View
2  Rakefile
@@ -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
View
3  jworkflow-min-0.6.0.js
@@ -1,3 +0,0 @@
-var jWorkflow=function(){return{order:function(j,k){var f=[],h,g=null,i=function(){var a=false;return{take:function(){a=true},pass:function(b){var c;a=false;h.length?(c=h.shift(),b=c.func.apply(c.context,[b,i]),a||i.pass(b)):g.func&&g.func.apply(g.context,[b])}}}(),e={andThen:function(a,b){if(typeof a.andThen==="function"&&typeof a.start==="function"&&typeof a.chill==="function")f.push({func:function(c,d){d.take();a.start({callback:function(a){d.pass(a)},context:b,initialValue:c})},context:b});else if(a.map&&
-a.reduce)f.push({func:function(b,d){d.take();var f=a.length,g=function(){return--f||d.pass()};a.forEach(function(a){jWorkflow.order(a).start(g)})},context:b});else{if(typeof a!=="function")throw"expected function but was "+typeof a;f.push({func:a,context:b})}return e},chill:function(a){return e.andThen(function(b,c){c.take();setTimeout(function(){c.pass(b)},a)})},start:function(a,b){var c,d,e;a&&typeof a==="object"?(c=a.callback,d=a.context,e=a.initialValue):(c=a,d=b);g={func:c,context:d};h=f.slice();
-i.pass(e)}};return j?e.andThen(j,k):e}}}();if(typeof module==="object"&&typeof require==="function")module.exports=jWorkflow;
View
3  jworkflow-min-0.7.0.js
@@ -0,0 +1,3 @@
+var jWorkflow=function(){return{order:function(j,k){var f=[],g,h=null,i=function(){var a=false;return{take:function(){a=true},pass:function(b){var c;a=false;g.length?(c=g.shift(),b=c.func.apply(c.context,[b,i]),a||i.pass(b)):h.func&&h.func.apply(h.context,[b])},drop:function(b){a=true;g=[];setTimeout(function(){i.pass(b)},1)}}}(),e={andThen:function(a,b){if(typeof a.andThen==="function"&&typeof a.start==="function"&&typeof a.chill==="function")f.push({func:function(c,d){d.take();a.start({callback:function(a){d.pass(a)},
+context:b,initialValue:c})},context:b});else if(a.map&&a.reduce)f.push({func:function(b,d){d.take();var f=a.length,g=function(){return--f||d.pass()};a.forEach(function(a){jWorkflow.order(a).start(g)})},context:b});else{if(typeof a!=="function")throw"expected function but was "+typeof a;f.push({func:a,context:b})}return e},chill:function(a){return e.andThen(function(b,c){c.take();setTimeout(function(){c.pass(b)},a)})},start:function(a,b){var c,d,e;a&&typeof a==="object"?(c=a.callback,d=a.context,e=
+a.initialValue):(c=a,d=b);h={func:c,context:d};g=f.slice();i.pass(e)}};return j?e.andThen(j,k):e}}}();if(typeof module==="object"&&typeof require==="function")module.exports=jWorkflow;
View
8 lib/jWorkflow.js
@@ -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);
}
};
}()),
View
2  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",
View
30 test/test_jworkflow.js
@@ -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);
+ }
+ });
+ });
});
Please sign in to comment.
Something went wrong with that request. Please try again.