AFNetworking/AFNetworking — Issue #206: AFHTTPRequestOperation reported as finished before executing its success block
Author: duanefields
Created: 2012-02-12 16:04:17+00:00
State: open

If you have an AFHTTPRequestOperation, it will change its state to "Finished" before it executes the success block. This seems unexpected to me, especially when you consider behavior in a batch. For example.

I'm creating a single bitmap from a series of image tiles. I create 10 requests operations, each getting a map tile from the server - in their completion blocks they write their map tile image onto a bitmap they share. Then, I put all of these into a batch with a completion block that turns the bitmap into a final image. My expected flow would be:

- request operation 1 completes and calls its completion block
- request operation 2 completes and calls its completion block
- request operation 3 completes and calls its completion block
and so on...

then, when all of the operations have been completed - the batch's completion block would be called.

It's actually backwards - the operations signal that they are "finished", which causes the batch operation to call its completion block, then the completion block for each request gets called.

It's not just the batch operation here - the issue seems to be in when AFURLConnectionOperation sets it's Finished flag, because I see the same behavior if I just stick the request operations in my own queue and "wait until all completed".