+22
-21
@@ -284,29 +284,30 @@ var request = require('request'); | ||
| function myRequest(url,callBac,output){ | ||
| var timeOut=true,retry= 0; | ||
| var timeOut=true,retry= 0,timer; | ||
| var main=function(){ | ||
| request(url,function(error,response){ | ||
| if(!timeOut)return; | ||
| timeOut=false; | ||
| if (!error) { | ||
| if(response.statusCode==200){ | ||
| cacheFuc.doCallBac(url,false,output); | ||
| var reader=request(url,function(error,response){ | ||
| clearTimeout(timer); | ||
| if(!timeOut)return; | ||
| timeOut=false; | ||
| if (!error) { | ||
| if(response.statusCode!=200){ | ||
| myError="获取"+url+"失败!请检查"; | ||
| } | ||
| }else{ | ||
| fs.unlink(output); | ||
| cacheFuc.doCallBac(url,"获取"+url+"失败!请检查",output); | ||
| myError="获取"+url+"远端服务器异常"; | ||
| } | ||
| }else{ | ||
| fs.unlink(output); | ||
| cacheFuc.doCallBac(url,"获取"+url+"远端服务器异常",output); | ||
| } | ||
| }).pipe(fs.createWriteStream(output)); | ||
| }), | ||
| writer=fs.createWriteStream(output),myError=false; | ||
| writer.on("finish",function(){ | ||
| if(myError)fs.unlink(output); | ||
| cacheFuc.doCallBac(url,myError,output); | ||
| }); | ||
| reader.pipe(writer); | ||
| checkTimeout(); | ||
| }; | ||
| var checkTimeout=function(){ | ||
| setTimeout(function(){ | ||
| if(timeOut){ | ||
| if((retry++)>=3){ | ||
| if(callBac)callBac("获取"+url+"超时且超过最大重试次数!请检查",output); | ||
| }else{ | ||
| main(); | ||
| } | ||
| timer=setTimeout(function(){ | ||
| if((retry++)>=3){ | ||
| if(callBac)callBac("获取"+url+"超时且超过最大重试次数!请检查",output); | ||
| }else{ | ||
| main(); | ||
| } | ||
@@ -313,0 +314,0 @@ },5000); |
+1
-1
| { | ||
| "name": "sealoader", | ||
| "version": "2.0.6", | ||
| "version": "2.0.7", | ||
| "description": "seajs前端开发解决方案", | ||
@@ -5,0 +5,0 @@ "main": "main.js", |
+5
-1
@@ -221,2 +221,6 @@ # sealoader 插件加载器—seajs前端开发解决方案 | ||
| 修复加载线上模块不加载其依赖的bug(-online) | ||
| 更新readMe中的附录 | ||
| 更新readMe中的附录 | ||
| 2.0.7(2016.04.14) | ||
| 修复文件加载可能不完整的bug | ||
| 优化超时处理 |
24944
0.55%315
0.32%225
1.81%