Refactoring -cancel and -isCancelled
This commit is contained in:
parent
1c606919fc
commit
68c572ae32
1 changed files with 7 additions and 12 deletions
|
|
@ -82,7 +82,6 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat
|
||||||
|
|
||||||
@interface AFURLConnectionOperation ()
|
@interface AFURLConnectionOperation ()
|
||||||
@property (readwrite, nonatomic, assign) AFOperationState state;
|
@property (readwrite, nonatomic, assign) AFOperationState state;
|
||||||
@property (readwrite, nonatomic, assign, getter = isCancelled) BOOL cancelled;
|
|
||||||
@property (readwrite, nonatomic, retain) NSRecursiveLock *lock;
|
@property (readwrite, nonatomic, retain) NSRecursiveLock *lock;
|
||||||
@property (readwrite, nonatomic, assign) NSURLConnection *connection;
|
@property (readwrite, nonatomic, assign) NSURLConnection *connection;
|
||||||
@property (readwrite, nonatomic, retain) NSURLRequest *request;
|
@property (readwrite, nonatomic, retain) NSURLRequest *request;
|
||||||
|
|
@ -101,7 +100,6 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat
|
||||||
|
|
||||||
@implementation AFURLConnectionOperation
|
@implementation AFURLConnectionOperation
|
||||||
@synthesize state = _state;
|
@synthesize state = _state;
|
||||||
@synthesize cancelled = _cancelled;
|
|
||||||
@synthesize connection = _connection;
|
@synthesize connection = _connection;
|
||||||
@synthesize runLoopModes = _runLoopModes;
|
@synthesize runLoopModes = _runLoopModes;
|
||||||
@synthesize request = _request;
|
@synthesize request = _request;
|
||||||
|
|
@ -247,14 +245,6 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat
|
||||||
[self.lock unlock];
|
[self.lock unlock];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setCancelled:(BOOL)cancelled {
|
|
||||||
[self.lock lock];
|
|
||||||
[self willChangeValueForKey:@"isCancelled"];
|
|
||||||
_cancelled = cancelled;
|
|
||||||
[self didChangeValueForKey:@"isCancelled"];
|
|
||||||
[self.lock unlock];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (NSString *)responseString {
|
- (NSString *)responseString {
|
||||||
[self.lock lock];
|
[self.lock lock];
|
||||||
if (!_responseString && self.response && self.responseData) {
|
if (!_responseString && self.response && self.responseData) {
|
||||||
|
|
@ -284,6 +274,10 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat
|
||||||
return self.state == AFHTTPOperationFinishedState;
|
return self.state == AFHTTPOperationFinishedState;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (BOOL)isCancelled {
|
||||||
|
return _cancelled;
|
||||||
|
}
|
||||||
|
|
||||||
- (BOOL)isConcurrent {
|
- (BOOL)isConcurrent {
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
@ -325,8 +319,8 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat
|
||||||
if (![self isFinished] && ![self isCancelled]) {
|
if (![self isFinished] && ![self isCancelled]) {
|
||||||
[super cancel];
|
[super cancel];
|
||||||
|
|
||||||
self.cancelled = YES;
|
[self willChangeValueForKey:@"isCancelled"];
|
||||||
|
_cancelled = YES;
|
||||||
if (self.connection) {
|
if (self.connection) {
|
||||||
[self.connection cancel];
|
[self.connection cancel];
|
||||||
|
|
||||||
|
|
@ -334,6 +328,7 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat
|
||||||
NSDictionary *userInfo = [NSDictionary dictionaryWithObject:[self.request URL] forKey:NSURLErrorFailingURLErrorKey];
|
NSDictionary *userInfo = [NSDictionary dictionaryWithObject:[self.request URL] forKey:NSURLErrorFailingURLErrorKey];
|
||||||
[self performSelector:@selector(connection:didFailWithError:) withObject:self.connection withObject:[NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorCancelled userInfo:userInfo]];
|
[self performSelector:@selector(connection:didFailWithError:) withObject:self.connection withObject:[NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorCancelled userInfo:userInfo]];
|
||||||
}
|
}
|
||||||
|
[self didChangeValueForKey:@"isCancelled"];
|
||||||
}
|
}
|
||||||
[self.lock unlock];
|
[self.lock unlock];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue