Class zebkit.DoIt <zebkit>

Promise-like sequential tasks runner (D-then). Allows developers to execute number of steps (async and sync) in the exact order they have been called with the class instance. The idea of the runner implementation is making the code more readable and plain nevertheless it includes asynchronous parts:

Constructor:
zebkit.DoIt ([ignore])

Parameters:
  • [ignore] <Boolean>

    flag to rule error ignorance


Example:
var r = new zebkit.DoIt();

// step 1
r.then(function() {
    // call three asynchronous HTTP GET requests to read three files
    // pass join to every async. method to be notified when the async.
    // part is completed
    asyncHttpCall("http://test.com/a.txt", this.join());
    asyncHttpCall("http://test.com/b.txt", this.join());
    asyncHttpCall("http://test.com/c.txt", this.join());
})
.  // step 2
then(function(r1, r2, r3) {
    // handle completely read on previous step files
    r1.responseText  // "a.txt" file content
    r2.responseText  // "b.txt" file content
    r3.responseText  // "c.txt" file content
})
. // handle error
catch(function(e) {
    // called when an exception has occurred
    ...
});



public void catch ([body])
public void error ([e])
public <Function> join ( )
public void restart ( )
public void then (body)
public void throw ( )
public void till (r)

public chainable catch ([body])

Method to catch error that has occurred during the doit sequence execution.


Parameters:
  • [body] <Function>

    a callback to handle the error. The method gets an error that has happened as its argument. If there is no argument the error will be printed in output. If passed argument is null then no error output is expected.

public chainable error ([e])

Force to fire error.


Parameters:
  • [e] <Error>

    an error to be fired

public <Function> join ( )

Returns join callback for asynchronous parts of the doit. The callback has to be requested and called by an asynchronous method to inform the doit the given method is completed.


Returns: <Function>

a method to notify doit the given asynchronous part has been completed. The passed to the method arguments will be passed to the next step of the runner. *


Example:
 var d = new DoIt().then(function() {
     // imagine we call ajax HTTP requests
     ajaxCall("http://test.com/data1", this.join());
     ajaxCall("http://test.com/data2", this.join());
 }).then(function(res1, res2) {
     // handle results of ajax requests from previous step
     ...
 });
public chainable restart ( )

Restart the do it object to clear error that has happened and continue tasks that has not been run yet because of the error.

public chainable then (body)

Run the given method as one of the sequential step of the doit execution.


Parameters:
  • body <Function>

    a method to be executed. The method can get results of previous step execution as its arguments. The method is called in context of a DoIt instance.

public chainable throw ( )

Throw an exception if an error has happened before the method call, otherwise do nothing.

public chainable till (r)

Wait for the given doit redness.


Parameters:
Example:
 var async = new DoIt().then(function() {
     // imagine we do asynchronous ajax call
     ajaxCall("http://test.com/data", this.join());
 });

 var doit = new DoIt().till(async).then(function(res) {
     // handle result that has been fetched
     // by "async" do it
     ...
 });

private <Boolean> $ignoreError

Indicates if the error has to be ignored