0

I am using ASIHTTPRequest (I know, I know, it is not being maintained - that doesn't matter; it works and it is what my app is built on) to run a series of HTTP requests through ASINetworkQueue.

The problem is that my queue will have many requests (thousands), and it will take a while to run. In the time that it is running, some of the data in the app may have changed which would make some of the request unnecessary. I would like to run a validation method on each request right before it runs, and if the validation method does not check out, then it will cancel that request and go on to the next one.

Right now, I am using the following code to create my ASIHTTPRequests:

ASINetworkQueue *myQueue = [ASINetworkQueue queue];
NSURL *URL = [NSURL URLWithString:@"http://mywebsite.com"];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setStartedBlock:^{
    NSLog(@"Request started: %@", request.url.absoluteString);
}];
[request setCompletionBlock:^{
    NSLog(@"Request completed: %@", request.url.absoluteString);
    // do some code here to clean up since it's finished
}];
[myQueue addOperation:request];

My current thinking is to put something into the startedBlock, so it would do:

[request setStartedBlock:^{
    NSLog(@"Request started");
    if (![self myValidationMethod]) {
        [request cancel]; // <----------
    }
}];

However when I do this, I get the following warning from Xcode: "Capturing 'request' strongly in this block is likely to lead to a retain cycle."

First, is this the right method to go about doing this? I can't seem to find a way to remove a specific ASIHTTPRequest from an ASINetworkQueue. Second, is this warning from Xcode something that I will need to worry about?

Jason
  • 14,517
  • 25
  • 92
  • 153
  • ans here: http://stackoverflow.com/questions/8859649/asihttprequest-asiformdatarequest-referencing-request-object-within-blocks-u/8874812#8874812 – Bob Jan 18 '13 at 04:18

1 Answers1

0

About the warning you capture the blocks 'container' and form a cycle... just say:

__weak ASIHTTPRequest *rw = request;

and use that in the block.

as for the started block approach. doesnt sound perfect to me but I dont know a better approach...

Mick MacCallum
  • 129,200
  • 40
  • 280
  • 281
Daij-Djan
  • 49,552
  • 17
  • 113
  • 135