1 'use strict';
  2 
  3 function Handler(name)
  4 {
  5     this.name  = name;
  6     this.array = [];
  7 
  8     this.add = function(func)
  9     {
 10         this.array.push(func);
 11         //console.out(this.name+":add [N="+this.array.length+"]");
 12     }
 13 
 14     this.run = function(timeout)
 15     {
 16         console.out(this.name+":start");
 17 
 18         var rc = [];
 19 
 20         var start = new Date();
 21         while (!timeout || (new Date()-start)<timeout)
 22         {
 23             var done = true;
 24 
 25             //rc = rc.map(this.array[i]);
 26             //
 27             //rc.forEach(function(el){ done &= el && el.length==0;);
 28 
 29             for (var i=0; i<this.array.length; i++)
 30             {
 31                 rc[i] = this.array[i](rc[i]);
 32                 if (rc[i]===undefined || rc[i].length>0)
 33                     done = false;
 34             }
 35 
 36             if (done)
 37             {
 38                 console.out(this.name+":success [time="+(new Date()-start)+"ms]");
 39                 return true;
 40             }
 41 
 42             v8.sleep();
 43         }
 44 
 45         console.out(this.name+":timeout ["+timeout+"ms]");
 46         return false;
 47     }
 48 }
 49