我现在的需求就是有10000条网络请求,让他们按照顺序执行,第一天请求完数据之后,存到数据库,让后在请求第二条,一次类题,不知到大家有没有好的方法。
世界只因有你2017-05-02 09:34:54
If your requests are regular, for example, the IDs are consecutive, you can process the ID in the callback or proxy of each successful request before initiating the next request.
A relatively simple and crude way:
Use NSOperationQueue, then set maxConcurrentOperationCount to 1, and add all 10,000 requests. If the executed request has no result, the queue is canceled. However, this saves code but not memory.
phpcn_u15822017-05-02 09:34:54
function apiCall (i){
var i = i || 0 ;
$http.get(i++).then(function(response){
if(response.status=='ok'){
apiCall(i);
}
},function(error){
console.log(error);
});
}