Don't execute completion block if cancelled

This commit is contained in:
Mattt Thompson 2011-10-04 00:41:32 -05:00
parent 561df45eb7
commit b85c59516d
3 changed files with 13 additions and 1 deletions

View file

@ -38,6 +38,10 @@
{ {
AFHTTPRequestOperation *operation = [[[self alloc] initWithRequest:urlRequest] autorelease]; AFHTTPRequestOperation *operation = [[[self alloc] initWithRequest:urlRequest] autorelease];
operation.completionBlock = ^ { operation.completionBlock = ^ {
if ([operation isCancelled]) {
return;
}
if (operation.error) { if (operation.error) {
if (failure) { if (failure) {
dispatch_async(dispatch_get_main_queue(), ^(void) { dispatch_async(dispatch_get_main_queue(), ^(void) {

View file

@ -53,6 +53,10 @@ static dispatch_queue_t image_request_operation_processing_queue() {
AFImageRequestOperation *operation = [[[AFImageRequestOperation alloc] initWithRequest:urlRequest] autorelease]; AFImageRequestOperation *operation = [[[AFImageRequestOperation alloc] initWithRequest:urlRequest] autorelease];
operation.completionBlock = ^ { operation.completionBlock = ^ {
if ([operation isCancelled]) {
return;
}
dispatch_async(image_request_operation_processing_queue(), ^(void) { dispatch_async(image_request_operation_processing_queue(), ^(void) {
if (operation.error) { if (operation.error) {
if (failure) { if (failure) {

View file

@ -274,6 +274,10 @@ static inline BOOL AFOperationStateTransitionIsValid(AFOperationState from, AFOp
} }
- (void)cancel { - (void)cancel {
if ([self isFinished]) {
return;
}
[super cancel]; [super cancel];
self.cancelled = YES; self.cancelled = YES;
@ -282,7 +286,7 @@ static inline BOOL AFOperationStateTransitionIsValid(AFOperationState from, AFOp
} }
- (void)finish { - (void)finish {
self.state = AFHTTPOperationFinishedState; self.state = AFHTTPOperationFinishedState;
} }
#pragma mark - NSURLConnectionDelegate #pragma mark - NSURLConnectionDelegate