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,7 +35,9 @@
}
- (void)start {
@synchronized (self) {
if (self.isCancelled) {
self.finished = YES;
return;
}
@ -46,24 +48,42 @@
if (self.executionBlock) {
self.executionBlock(self);
} else {
[self complete];
self.executing = NO;
self.finished = YES;
}
}
}
- (void)cancel {
@synchronized (self) {
[super cancel];
if (self.isExecuting) {
[self complete];
self.executing = NO;
self.finished = YES;
}
}
}
- (void)complete {
[self willChangeValueForKey:@"isExecuting"];
[self willChangeValueForKey:@"isFinished"];
@synchronized (self) {
if (self.isExecuting) {
self.executing = NO;
self.finished = YES;
[self didChangeValueForKey:@"isExecuting"];
}
}
}
- (void)setFinished:(BOOL)finished {
[self willChangeValueForKey:@"isFinished"];
_finished = finished;
[self didChangeValueForKey:@"isFinished"];
}
- (void)setExecuting:(BOOL)executing {
[self willChangeValueForKey:@"isExecuting"];
_executing = executing;
[self didChangeValueForKey:@"isExecuting"];
}
@end