Mark the `SDAsyncBlockOperation` safe using the lock and correct override method

This commit is contained in:
DreamPiggy 2020-04-30 19:19:55 +08:00
parent 974c3ff4ad
commit f51992cfd6
1 changed files with 39 additions and 19 deletions

View File

@ -35,35 +35,55 @@
} }
- (void)start { - (void)start {
if (self.isCancelled) { @synchronized (self) {
return; if (self.isCancelled) {
} self.finished = YES;
return;
}
[self willChangeValueForKey:@"isExecuting"]; [self willChangeValueForKey:@"isExecuting"];
self.executing = YES; self.executing = YES;
[self didChangeValueForKey:@"isExecuting"]; [self didChangeValueForKey:@"isExecuting"];
if (self.executionBlock) { if (self.executionBlock) {
self.executionBlock(self); self.executionBlock(self);
} else { } else {
[self complete]; self.executing = NO;
self.finished = YES;
}
} }
} }
- (void)cancel { - (void)cancel {
[super cancel]; @synchronized (self) {
if (self.isExecuting) { [super cancel];
[self complete]; if (self.isExecuting) {
self.executing = NO;
self.finished = YES;
}
} }
} }
- (void)complete { - (void)complete {
[self willChangeValueForKey:@"isExecuting"]; @synchronized (self) {
if (self.isExecuting) {
self.executing = NO;
self.finished = YES;
}
}
}
- (void)setFinished:(BOOL)finished {
[self willChangeValueForKey:@"isFinished"]; [self willChangeValueForKey:@"isFinished"];
self.executing = NO; _finished = finished;
self.finished = YES;
[self didChangeValueForKey:@"isExecuting"];
[self didChangeValueForKey:@"isFinished"]; [self didChangeValueForKey:@"isFinished"];
} }
- (void)setExecuting:(BOOL)executing {
[self willChangeValueForKey:@"isExecuting"];
_executing = executing;
[self didChangeValueForKey:@"isExecuting"];
}
@end @end