• Tasker example with 5 taks 0..4, where task 1 and 3 fail (emulated) twice and once and succeed in 3rd and 2nd try, respectively.

    // Setup of 5 task: t0..t4
    
    var t0 = function(done) { // task0
      console.log("t0 started");
      setTimeout(function(){
        done(true);
      },5000);
    };
    
    var t1 = function(done,trie) {
      console.log("t1 started");
      setTimeout(function(){
        var ok = trie >= 3; // emulating failure on 1st & 2nd try
        console.log("t1 " + trie + " ok: " + ok);
        done(ok,3); // allow 3 tries
      },2000);
    };
    
    var t2 = function(done) {
      console.log("t2 started");
      setTimeout(function(){
        done(true);
      },15000);
    };
    var t3 = function(done,trie) {
      console.log("t3 started");
      var ok = trie >= 2;
      console.log("t1 " + trie + " ok: " + ok);
      setTimeout(function(){
        done(ok,2);
      },2500);
    };
    var t4 = function(done) {
      console.log("t4 started");
      setTimeout(function(){
        done(true);
      },12500);
    };
    
    // define ok function - application
    var ok = function(oks,sts,tries,tasks) {
      console.log("All " + oks + 
        " tasks successfully executed.");
    };
    
    // define err function
    var err = function(oks,sts,tries,tasks) {
        console.log("Only " + oks + " tasks of " + 
          sts.length + " successfully executed.");
    };
    
    
    // Execute the tasks 
    new Tasker([t0,t1,t2,t3,t4],ok,err,true);
    

    The console output reads as follows:

     1v71 Copyright 2014 G.Williams
    >echo(0);
    Task 0 kickoff 1
    Task 1 kickoff 1
    Task 2 kickoff 1
    Task 3 kickoff 1
    Task 4 kickoff 1
    =undefined
    t0 started
    t1 started
    t2 started
    t3 started
    t1 1 ok: false
    t4 started
    t1 1 ok: false
    Task 1 try 1 ok: false
    Task 1 kickoff 2
    t1 started
    Task 3 try 1 ok: false
    Task 3 kickoff 2
    t3 started
    t1 2 ok: true
    t1 2 ok: false
    Task 1 try 2 ok: false
    Task 1 kickoff 3
    t1 started
    Task 0 try 1 ok: true
    Task 3 try 2 ok: true
    t1 3 ok: true
    Task 1 try 3 ok: true
    Task 4 try 1 ok: true
    Task 2 try 1 ok: true
    All 5 tasks successfully executed.
    > 
    
About

Avatar for allObjects @allObjects started