Improved readability in `SDWebImageManager` by creating `safelyRemoveOperationFromRunning:` method
This commit is contained in:
parent
fdb8b2c1c6
commit
265ace4a24
|
@ -145,10 +145,7 @@
|
||||||
|
|
||||||
operation.cacheOperation = [self.imageCache queryCacheOperationForKey:key done:^(UIImage *cachedImage, NSData *cachedData, SDImageCacheType cacheType) {
|
operation.cacheOperation = [self.imageCache queryCacheOperationForKey:key done:^(UIImage *cachedImage, NSData *cachedData, SDImageCacheType cacheType) {
|
||||||
if (operation.isCancelled) {
|
if (operation.isCancelled) {
|
||||||
@synchronized (self.runningOperations) {
|
[self safelyRemoveOperationFromRunning:operation];
|
||||||
[self.runningOperations removeObject:operation];
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -242,22 +239,13 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
if (finished) {
|
if (finished) {
|
||||||
@synchronized (self.runningOperations) {
|
[self safelyRemoveOperationFromRunning:strongOperation];
|
||||||
if (strongOperation) {
|
|
||||||
[self.runningOperations removeObject:strongOperation];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}];
|
}];
|
||||||
operation.cancelBlock = ^{
|
operation.cancelBlock = ^{
|
||||||
[self.imageDownloader cancel:subOperation];
|
[self.imageDownloader cancel:subOperation];
|
||||||
|
__strong __typeof(weakOperation) strongOperation = weakOperation;
|
||||||
@synchronized (self.runningOperations) {
|
[self safelyRemoveOperationFromRunning:strongOperation];
|
||||||
__strong __typeof(weakOperation) strongOperation = weakOperation;
|
|
||||||
if (strongOperation) {
|
|
||||||
[self.runningOperations removeObject:strongOperation];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
} else if (cachedImage) {
|
} else if (cachedImage) {
|
||||||
dispatch_main_async_safe(^{
|
dispatch_main_async_safe(^{
|
||||||
|
@ -266,9 +254,7 @@
|
||||||
completedBlock(cachedImage, cachedData, nil, cacheType, YES, url);
|
completedBlock(cachedImage, cachedData, nil, cacheType, YES, url);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@synchronized (self.runningOperations) {
|
[self safelyRemoveOperationFromRunning:operation];
|
||||||
[self.runningOperations removeObject:operation];
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// Image not in cache and download disallowed by delegate
|
// Image not in cache and download disallowed by delegate
|
||||||
dispatch_main_async_safe(^{
|
dispatch_main_async_safe(^{
|
||||||
|
@ -277,9 +263,7 @@
|
||||||
completedBlock(nil, nil, nil, SDImageCacheTypeNone, YES, url);
|
completedBlock(nil, nil, nil, SDImageCacheTypeNone, YES, url);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@synchronized (self.runningOperations) {
|
[self safelyRemoveOperationFromRunning:operation];
|
||||||
[self.runningOperations removeObject:operation];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}];
|
}];
|
||||||
|
|
||||||
|
@ -303,12 +287,20 @@
|
||||||
|
|
||||||
- (BOOL)isRunning {
|
- (BOOL)isRunning {
|
||||||
BOOL isRunning = NO;
|
BOOL isRunning = NO;
|
||||||
@synchronized(self.runningOperations) {
|
@synchronized (self.runningOperations) {
|
||||||
isRunning = (self.runningOperations.count > 0);
|
isRunning = (self.runningOperations.count > 0);
|
||||||
}
|
}
|
||||||
return isRunning;
|
return isRunning;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)safelyRemoveOperationFromRunning:(nullable SDWebImageCombinedOperation*)operation {
|
||||||
|
@synchronized (self.runningOperations) {
|
||||||
|
if (operation) {
|
||||||
|
[self.runningOperations removeObject:operation];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue