How IOS resolves concurrent requests, accepting only the results returned by the last request

Source: Internet
Author: User

The general meaning is that although nsoperation cancel cannot cancel the request, the nsoperation can be flagged. When the Cancel property is Yes, it indicates that Nsoperation has executed and returned the result, but I don't need it now. Then we cancel the last operation every time we execute the request, and then in completion block we judge if operation Cancel, and if Cancel does not return the value of response.
1+ (Afhttprequestoperation *) Requestsellerwithcompletion: (requestfinishedcompletionblock) Successblock2 {3Afhttprequestoperationmanager *manager =[Afhttprequestoperationmanager manager];4 5afhttprequestoperation * operation = [manager get:krequestsellerurl parameters:nil success:^ (AFHTTPRequestOperation * Operation,IDresponseobject) {6  7         if(operation.iscancelled) {8          //If the operation has been cancel, the return data will not be processed9NSLog (@"operation is Canceled");Ten}Else{ One      //Normal data parsing if no cancel is removed ANsarray *sellerarray = [Mtljsonadapter modelsofclass:[sellerclass] Fromjsonarray:responseobject[@"Data"] Error:nil]; -             if(successblock) { -               //NSLog (@ "Current operation Count is%d", [Manager.operationqueue operations].count); the Successblock (sellerarray); -             } -         } -  +  -} failure:^ (Afhttprequestoperation *operation, Nserror *error) { +  A}];

then do so in the for loop.  for (int1; i++) {        if  (operation) {            [operation Cancel];        }       = [Seller requestsellerwithcompletion:^ (IDObject) {            NSLog (@ "finished download%d", I);        }];    }

Run a look at the console.

See ye isolated City an article, and now summarize it myself as above

How IOS resolves concurrent requests, accepting only the results returned by the last request

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.