It is also possible to have a custom function called immediately, in addition
to the function that is queued:

chainit.add(obj,'method1',functionqueued1(sub, cb){

//... the actual method

},functionnow1(sub){

this.chainState ={ one:true};

});

chainit.add(obj,'method2',functionqueued2(var1, var2, cb){

},functionnow2(var1, var2){

if(!this.chainState ||!this.chainState.one)thrownewError("method2 must be called after method1");

this.chainState.one =false;

});

// this works

obj.method1(a, b).method2(a, b)// ok

obj.method1(a, b,function(){

this.method2(a, b);// ok

this.method2(a, b);// not allowed by that simple state machine

});

The first function is pushed to the queue, the second function is called
immediately.

The second function can set this.chainState = someObject and the queued
function will be able to access that object.

this.chainState reference is copied to the next queued (and immediate if any)
functions: this behavior allows queued functions to get information about
which functions were queued before or after them.