Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tag: 0.2.0
Fetching contributors…

Cannot retrieve contributors at this time

114 lines (74 sloc) 3.305 kb


Dude, where is my workflow?

jWorkflow is a workflow engine for JavaScript that provides the ability to create workflows to chain methods together in an easy to understand syntax:

var fooodOrder = jWorkflow.order(garlicChicken)



jWorkflow orders are started with a call to jWorkflow.order:

function dude() {
    // some of the best code in the world will live here

var order = jWorkflow.order(dude);

// orders can also be started with no initial function
var pizzacoli = jWorkflow.order();

jWorkflow tasks at the root are just functions that will be invoked in the order they are built. Any number of tasks can be then appended to the order:


The functions passed into the order will not be invoked until you call:


The context to be used when invoking the functions can be passed in while creating the order:

order.andThen(transfunctioner.photonAcceleratorAnnihilationBeam, transfunctioner);

Passing Values between tasks

jWorkflow tasks can access the return value of the previous task with the previous parameter:

function meaningOfLife() {
   //find the meaning of life
   return 42; 

function writeBook(previous) {
   console.log("the meaning of life is " + previous);

var guide = jWorkflow.order(meaningOfLife).andThen(writeBook);

Handling Async calls

Sometimes(probably all the time) you will need to do something async when working with tasks, jWorkflow provides the ability to control the execution of the workflow via a baton that is passed to the task

function procrastinate(previous, baton) {
    //take the baton, this means the next task will not run until you pass the baton

    window.setTimeout(function() {
        //do some stuff

        //please be nice and always remember to pass the baton!
    }, 1000);

If you want to pass a return value to the next task you can pass it along with the baton.

NOTE: if you did take the baton, the return value from your function will NOT be passed to the next task:

function awesometown(previous, baton) {

    window.setTimeout(function() {

        //do stuff

        baton.pass(420);    //This value will be passed to the next task
    }, 100);

    return 50; // this will NOT be passed to the next function since you took the baton.

the start method provides a callback to execute when the workflow is finished:

order.start(function() {
    console.log("dude!, your car is behind that mail truck!");

you can also pass context to use for the callback:

order.start(function() {
    //do stuff
}, transfunctioner);


Gord Tanner <>
Jump to Line
Something went wrong with that request. Please try again.