search

Home  >  Q&A  >  body text

objective-c - I now have 10,000 network requests. How can I return a result in the first request, the second request, and so on?

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.

PHPzPHPz2772 days ago818

reply all(2)I'll reply

  • 世界只因有你

    世界只因有你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.

    reply
    0
  • phpcn_u1582

    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);
        });
    }

    reply
    0
  • Cancelreply