objective c - AFNetworking cancelAllOperations prevents batch completionBlock from firing -


i'm using enqueuebatchofhttprequestoperations submit batch of requests. if of requests fail, want cancel other requests still going. so, i'm setting failure callback on individual operations [client.operationqueue cancelalloperations];.

this seems cancel remaining operations, it's preventing overall completionblock of batch executing... here's code i'm trying test behavior (one of requests set fail on server).

afhttpclient *client = [afhttpclient clientwithbaseurl:[nsurl urlwithstring:@"http://arahlf.com"]];  nsmutablearray *requests = [[nsmutablearray alloc] init];  (int = 0; < 10; i++) {     nsurlrequest *request = [client requestwithmethod:@"get" path:@"echo.php" parameters:@{ @"sleep": @(i) }];     afhttprequestoperation *operation = [client httprequestoperationwithrequest:request success:nil failure:nil];     [operation setcompletionblockwithsuccess:nil failure:^(afhttprequestoperation *operation, nserror *error) {         nslog(@"request failed, cancelling operations.");         [client.operationqueue cancelalloperations];     }];      [requests addobject:operation]; }  [client enqueuebatchofhttprequestoperations:requests progressblock:^(nsuinteger numberoffinishedoperations, nsuinteger totalnumberofoperations) {     nslog(@"progress: %i/%i", numberoffinishedoperations, totalnumberofoperations);  } completionblock:^(nsarray *operations) {     nslog(@"all done!"); }]; 

for me, completionblock never executed. also, since 1 failing request cancels remaining (which fires failure block), cancelalloperations getting executed many times actually.

is there better way achieve effect?

when operationqueue cancelalloperations, canceling dependent operation fires on batch completion, in addition of other operations.

that say, in example, 11 operations cancelled: 10 network operations + dependent batch completion operation.

the following change in setcompletionblock:... allows batch completion fire expected:

[[client.operationqueue.operations filteredarrayusingpredicate:[nspredicate predicatewithblock:^bool(id evaluatedobject, nsdictionary *bindings) {   return [evaluatedobject iskindofclass:[afhttprequestoperation class]]; }]] makeobjectsperformselector:@selector(cancel)]; 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -