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:

zebkit.DoIt ([ignore])

  • [ignore] <Boolean>

    flag to rule error ignorance

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("", this.join());
    asyncHttpCall("", this.join());
    asyncHttpCall("", 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.

  • [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.

  • [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. *

 var d = new DoIt().then(function() {
     // imagine we call ajax HTTP requests
     ajaxCall("", this.join());
     ajaxCall("", 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.

  • 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.

 var async = new DoIt().then(function() {
     // imagine we do asynchronous ajax call
     ajaxCall("", 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