色尼玛亚洲综合影院,亚洲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模擬多線程,轉載需保留來源!

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

主站蜘蛛池模板: 墨玉县| 石台县| 陈巴尔虎旗| 池州市| 宜城市| 浑源县| 花垣县| 姜堰市| 德庆县| 菏泽市| 平遥县| 天气| 通道| 沙洋县| 南溪县| 井陉县| 称多县| 江永县| 会泽县| 收藏| 定结县| 尖扎县| 高雄县| 彰化市| 乌什县| 融水| 达日县| 密山市| 海兴县| 河曲县| 晴隆县| 济阳县| 大名县| 张家港市| 新巴尔虎右旗| 报价| 磴口县| 灵璧县| 宜州市| 榆树市| 定兴县|