-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Cause a failure when an operation is cancelled #693
Conversation
After giving it a lot of thought, I have to agree with your assessment of all of this. Yes—canceling and operation should trigger the failure callback. Indeed, canceling the operation cancels the Because this is a potentially breaking change, I'll be tagging this as part of a new release of AFNetworking later today. Thanks again for putting up with my stubbornness about this—I'm not exactly used to being conservative about much in my everyday life, so reconciling that with my code stewardship habits is something I'm still trying to figure out :p |
Thanks for putting up with mine and @danielctull's stubbornness too! |
Just want to chime in disagreeing with this. I think merging the concept of failure & cancellation leads to extra code for the developer. For instance, if a UIViewController uses AFN to load some data, but that view is poppe & dealloced before the success/failure blocks can be handled. Currently it seems the best solution is to keep an set of current operations, and #cancel them on dealloc. With this change, all failure blocks now have to check and see if this was truly a failure, or if this 'failed' because it was explicitly cancelled. (So there has to be an if/else branch in the failure block, which seems prone to ... 😎 ....failure. YEAHHHHHH!!!) If it was cancelled, it's done explicitly, and the dev can explicitly handle that case right where the operation was cancelled. Couldn't this be handled by posting a notification instead? Interested parties can just listen for that notification. (AFOperationCancelledNotification) |
@iwarshak you could also |
@iwarshak At most, it's 2 extra lines to return early if |
No, canceling a NSURLConnection just cancels the connection without producing any error. As per -[NSURLConnection cancel] documentation:
Actually, the error is explicitly constructed and assigned in -[AFURLConnectionOperation cancelConnection] I’d like to join @iwarshak and ask you to reconsider this decision. I think it doesn’t make sense to get an error with |
Maybe not a good idea in the 1.x branch but I'd love to see that change reversed in the 2.0 branch. |
This bit me today - took me a while to realize why my connections were "failing" after I was properly canceling them. It feels like Apple's classes (such as |
At present, when an operation is cancelled there is no decent way to handle that within the scope of AFNetworking. This change uses the existing error created when a
cancel
is called and uses that as the error for the operation. This causes the failure block to be executed.Fixes issue #657.