色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

JS模擬多線程

var Thread = {
 runNum : 0,  //當前正式運行的線程數
 maxNum : 10, //最大同時執行的線程數 -1表示不限
 commandList : new Array(), 
 start : function(){
  //window.status = this.runNum; 
  if(this.maxNum != -1 && this.runNum >= this.maxNum){   
   return; 
  }
  if(this.commandList.length <= 0){  
   this.runNum = 0;
   return false; 
  }  
  this.runNum++;
  var _this =this;  
  var tFun = function(){
   if(!_this.commandList[0]) return;
   var command = _this.commandList[0].shift();   
   command.apply(_this,_this.commandList[0].concat(
    function(){  //alert(2)     
     if(_this.runNum > 0)_this.runNum--; 
     setTimeout(function(){_this.start.apply(_this)},1);     
    }));
   _this.commandList.shift(); 
  }
  setTimeout(tFun,1);  
  setTimeout(function(){_this.start.apply(_this)},10);
 }
}

<script src="prototype.js"></script>
<script type="text/Javascript" defer="defer">
function test(obj,info,callback){ 
 callback = callback || new Function();
 new Ajax.Request('test.xml',{method:'get',
  onSuccess:function(o){

   $(obj).innerHTML += info + '完成<br>';
   callback('完成');
  },
  onFailure : function(o){
   $(obj).innerHTML += info + '失敗<br>';
   callback('失敗');
  },
  onComplete : function(o){
   document.body.scrollTop = 9999;
  }
 });
}

var Thread = {
 runNum : 0,  //當前正式運行的線程數
 maxNum : 5, //最大同時執行的線程數 -1表示不限
 commandList : new Array(), 
 start : function(){
  //window.status = this.runNum; 
  if(this.maxNum != -1 && this.runNum >= this.maxNum){   
   return; 
  }
  if(this.commandList.length <= 0){  
   this.runNum = 0;
   return false; 
  }  
  this.runNum++;
  var _this =this;  
  var tFun = function(){
   if(!_this.commandList[0]) return;
   var command = _this.commandList[0].shift();   
   command.apply(_this,_this.commandList[0].concat(
    function(){  //alert(2)     
     if(_this.runNum > 0)_this.runNum--; 
     setTimeout(function(){_this.start.apply(_this)},1);     
    }));
   _this.commandList.shift(); 
  }
  setTimeout(tFun,1);  
  setTimeout(function(){_this.start.apply(_this)},10);
 }
}

for(var i = 0; i < 100 ; i++){
 Thread.commandList.push(new Array(test,document.body,i+1));
};
Thread.start();
</script>
<body>
</body>

JavaScript技術JS模擬多線程,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 常熟市| 彩票| 石棉县| 阿尔山市| 扶余县| 罗平县| 阳朔县| 景泰县| 临沂市| 安新县| 保定市| 桃园市| 邵阳县| 蒙自县| 长沙市| 汤原县| 太仆寺旗| 凤阳县| 江津市| 夹江县| 裕民县| 伊宁县| 鄯善县| 云浮市| 株洲县| 富锦市| 青田县| 迁西县| 东光县| 蓬安县| 乡宁县| 洛川县| 奈曼旗| 比如县| 鹤岗市| 来凤县| 阳城县| 道孚县| 伊吾县| 庆阳市| 错那县|