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

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

主站蜘蛛池模板: 苍南县| 扎囊县| 高阳县| 庆城县| 巫山县| 沧州市| 德兴市| 尚志市| 绍兴市| 望都县| 兴业县| 高邑县| 内江市| 大名县| 佛教| 洞口县| 平武县| 杭锦后旗| 沾益县| 赤水市| 台东县| 哈巴河县| 浦江县| 苍南县| 中西区| 和林格尔县| 西昌市| 方城县| 磐安县| 格尔木市| 武夷山市| 任丘市| 望奎县| 尼玛县| 辽源市| 潜山县| 临沭县| 万安县| 湖南省| 雷山县| 马龙县|