My current need is to have 10,000 network requests and have them be executed in order. After requesting the data on the first day, save it to the database, and then request the second one, a one-time question. I wonder if anyone has any ideas? method.
世界只因有你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);
});
}