Move block before sending to the main queue
This can avoid some life cycle issue and increase performance
This commit is contained in:
parent
384b2d7c8b
commit
736f3f41f7
|
@ -40,12 +40,13 @@
|
|||
}
|
||||
self.cancelled = YES;
|
||||
|
||||
dispatch_main_async_safe(^{
|
||||
if (self.doneBlock) {
|
||||
self.doneBlock(nil, nil, SDImageCacheTypeNone);
|
||||
self.doneBlock = nil;
|
||||
}
|
||||
});
|
||||
SDImageCacheQueryCompletionBlock doneBlock = self.doneBlock;
|
||||
self.doneBlock = nil;
|
||||
if (doneBlock) {
|
||||
dispatch_main_async_safe(^{
|
||||
doneBlock(nil, nil, SDImageCacheTypeNone);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -158,11 +158,11 @@
|
|||
[self.callbackTokens removeObjectIdenticalTo:token];
|
||||
}
|
||||
SDWebImageDownloaderCompletedBlock completedBlock = ((SDWebImageDownloaderOperationToken *)token).completedBlock;
|
||||
dispatch_main_async_safe(^{
|
||||
if (completedBlock) {
|
||||
if (completedBlock) {
|
||||
dispatch_main_async_safe(^{
|
||||
completedBlock(nil, nil, [NSError errorWithDomain:SDWebImageErrorDomain code:SDWebImageErrorCancelled userInfo:@{NSLocalizedDescriptionKey : @"Operation cancelled by user during sending the request"}], YES);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
return shouldCancel;
|
||||
}
|
||||
|
@ -697,11 +697,12 @@ didReceiveResponse:(NSURLResponse *)response
|
|||
tokens = [self.callbackTokens copy];
|
||||
}
|
||||
for (SDWebImageDownloaderOperationToken *token in tokens) {
|
||||
dispatch_main_async_safe(^{
|
||||
if (token.completedBlock) {
|
||||
token.completedBlock(image, imageData, error, finished);
|
||||
}
|
||||
});
|
||||
SDWebImageDownloaderCompletedBlock completedBlock = token.completedBlock;
|
||||
if (completedBlock) {
|
||||
dispatch_main_async_safe(^{
|
||||
completedBlock(image, imageData, error, finished);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -710,11 +711,12 @@ didReceiveResponse:(NSURLResponse *)response
|
|||
imageData:(nullable NSData *)imageData
|
||||
error:(nullable NSError *)error
|
||||
finished:(BOOL)finished {
|
||||
dispatch_main_async_safe(^{
|
||||
if (token.completedBlock) {
|
||||
token.completedBlock(image, imageData, error, finished);
|
||||
}
|
||||
});
|
||||
SDWebImageDownloaderCompletedBlock completedBlock = token.completedBlock;
|
||||
if (completedBlock) {
|
||||
dispatch_main_async_safe(^{
|
||||
completedBlock(image, imageData, error, finished);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -672,11 +672,11 @@ static id<SDImageLoader> _defaultImageLoader;
|
|||
cacheType:(SDImageCacheType)cacheType
|
||||
finished:(BOOL)finished
|
||||
url:(nullable NSURL *)url {
|
||||
dispatch_main_async_safe(^{
|
||||
if (completionBlock) {
|
||||
if (completionBlock) {
|
||||
dispatch_main_async_safe(^{
|
||||
completionBlock(image, data, error, cacheType, finished, url);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL)shouldBlockFailedURLWithURL:(nonnull NSURL *)url
|
||||
|
|
|
@ -229,12 +229,12 @@ const int64_t SDWebImageProgressUnitCountUnknown = 1LL;
|
|||
#if SD_UIKIT || SD_MAC
|
||||
[self sd_stopImageIndicator];
|
||||
#endif
|
||||
dispatch_main_async_safe(^{
|
||||
if (completedBlock) {
|
||||
if (completedBlock) {
|
||||
dispatch_main_async_safe(^{
|
||||
NSError *error = [NSError errorWithDomain:SDWebImageErrorDomain code:SDWebImageErrorInvalidURL userInfo:@{NSLocalizedDescriptionKey : @"Image url is nil"}];
|
||||
completedBlock(nil, nil, error, SDImageCacheTypeNone, YES, url);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return operation;
|
||||
|
|
Loading…
Reference in New Issue