Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 171 lines (114 sloc) 4.96 kB
525c5f6 rake building and better documentation
Gord Tanner authored
1 =jWorkflow
2 Dude, where is my workflow?
3
4 jWorkflow is a workflow engine for JavaScript that provides the ability to
5 create workflows to chain methods together in an easy to understand syntax:
6
7 var fooodOrder = jWorkflow.order(garlicChicken)
8 .andThen(whiteRice)
9 .andThen(wontonSoup)
10 .andThen(cookiesFortune)
11 .andThen(noAndThen)
12 .andThen(noAndThen)
13 .andThen(noAndThen)
14 .andThen(noAndThen);
15
16 fooodOrder.start();
17
7822aa2 added npm install docs
Gord Tanner (Laptop) authored
18 =Install
19
20 jWorkflow can be used in node or included in the browser. It can be installed with npm
21
22 npm install jWorkflow
23
24 and used
25
26 var jWorkflow = require("jWorkflow");
27
28 or just include jWorkflow.js in your webpage and use window.jWorkflow.
29
525c5f6 rake building and better documentation
Gord Tanner authored
30 =Usage
31
32 jWorkflow orders are started with a call to jWorkflow.order:
33
34 function dude() {
35 // some of the best code in the world will live here
36 }
37
38 var order = jWorkflow.order(dude);
39
093b42b allow configuring of workflows with no initial task in order
Gord Tanner authored
40 // orders can also be started with no initial function
41 var pizzacoli = jWorkflow.order();
42
525c5f6 rake building and better documentation
Gord Tanner authored
43 jWorkflow tasks at the root are just functions that will be invoked in the order they are built.
44 Any number of tasks can be then appended to the order:
45
46 order.andThen(sweet).andThen(dude).andThen(sweet);
47
48 The functions passed into the order will not be invoked until you call:
49
50 order.start();
51
d41feb0 forgot to update docs
Gord Tanner (Laptop) authored
52 The context to be used when invoking the functions can be passed in while creating the order:
53
54 order.andThen(transfunctioner.photonAcceleratorAnnihilationBeam, transfunctioner);
55
73f6a41 added support for subworkflows, initialValue and passing of final res…
Gord Tanner (Laptop) authored
56 An initial value can be passed into the start method to seed the first function:
57
58 order.start({
59 initialValue: 10
60 });
61
525c5f6 rake building and better documentation
Gord Tanner authored
62 =Passing Values between tasks
63
64 jWorkflow tasks can access the return value of the previous task with the previous parameter:
65
66 function meaningOfLife() {
67 //find the meaning of life
68 return 42;
69 }
70
71 function writeBook(previous) {
72 console.log("the meaning of life is " + previous);
73 }
74
75 var guide = jWorkflow.order(meaningOfLife).andThen(writeBook);
76 guide.start();
77
78 =Handling Async calls
79
80 Sometimes(probably all the time) you will need to do something async when working with
81 tasks, jWorkflow provides the ability to control the execution of the workflow via a
82 baton that is passed to the task
83
84 function procrastinate(previous, baton) {
85 //take the baton, this means the next task will not run until you pass the baton
86 baton.take();
87
88 window.setTimeout(function() {
89 //do some stuff
90
91 //please be nice and always remember to pass the baton!
92 baton.pass();
93 }, 1000);
94 }
95
fdf4a50 added ability to pass values from async functions and cleaned up code…
Gord Tanner (Laptop) authored
96 If you want to pass a return value to the next task you can pass it along with the
97 baton.
98
99 NOTE: if you did take the baton, the return value from your function will NOT be passed to
100 the next task:
101
102 function awesometown(previous, baton) {
103 baton.take();
104
105 window.setTimeout(function() {
106
107 //do stuff
108
109 baton.pass(420); //This value will be passed to the next task
110 }, 100);
111
112 return 50; // this will NOT be passed to the next function since you took the baton.
113 }
114
115
73f6a41 added support for subworkflows, initialValue and passing of final res…
Gord Tanner (Laptop) authored
116 the start method provides a callback to execute when the workflow is finished. The final
117 return value is also passed to the callback:
525c5f6 rake building and better documentation
Gord Tanner authored
118
73f6a41 added support for subworkflows, initialValue and passing of final res…
Gord Tanner (Laptop) authored
119 order.start({
120 callback: function(review) {
121 console.log("dude!, your car is behind that mail truck!");
122 expect(review).toBe("two thumbs up");
123 }
124 });
84aa77e added context to start callback and tightened up the baton interface
Gord Tanner authored
125
126 you can also pass context to use for the callback:
127
73f6a41 added support for subworkflows, initialValue and passing of final res…
Gord Tanner (Laptop) authored
128 order.start({
129 callback: function() {
130 //do stuff
131 },
132 context: transfunctioner
133 });
525c5f6 rake building and better documentation
Gord Tanner authored
134
8470223 added chill method, linting and fixed node detection
Gord Tanner (Laptop) authored
135 =Waiting between tasks
136
137 If you ever need to take a break and reflect on the moment you can add some time(in ms) to chill between tasks:
138
139 jWorkflow.order(seeDoubleRainbow)
140 .chill(1000)
141 .andThen(omg)
142 .andThen(omg)
143 .andThen(omg)
144 .chill(1000)
145 .andThen(freakOut);
525c5f6 rake building and better documentation
Gord Tanner authored
146
7d89868 @gtanner added parallel tasks and updated version to 0.6.0
gtanner authored
147 =Handling Parallel tasks
148
149 If you need to handle some tasks and don't care about when they are done you can pass in an array of functions and / or other workflows to execute
150 at the same time.
151
152 jWorkflow.order([man, man, halfMan])
153 .andThen([jWorkflow.order([guy, guy]).andThen(girl), pizzaPlace]);
154
87bc7e6 @gtanner added drop method to baton to cancel workflow execution
gtanner authored
155 =Canceling Workflows
156
157 To cancel the execution of the workflow you can call the drop method on the baton:
158
159 function (previous, baton) {
160 //the value passed to drop will be passed onto the final callback if it exists
161 baton.drop("I dropped the soap");
162 //this value will NOT be passed to the next workflow step
163 return 10;
164 }
165
166 NOTE: This will force the workflow into async mode.
167
525c5f6 rake building and better documentation
Gord Tanner authored
168 =Contributers:
169
170 Gord Tanner <gord@tinyhippos.com>
Something went wrong with that request. Please try again.