Fix the rare case when cancel an async disk cache query may cause twice callback

One is sync and another is async
This commit is contained in:
DreamPiggy 2022-07-23 21:08:55 +08:00
parent cc1995b738
commit 0643cb81c3
1 changed files with 7 additions and 0 deletions

View File

@ -662,6 +662,13 @@ static NSString * _defaultDiskCacheDirectory;
}
if (doneBlock) {
dispatch_async(dispatch_get_main_queue(), ^{
// Dispatch from IO queue to main queue need time, user may call cancel during the dispatch timing
// This check is here to avoid double callback (one is from `SDImageCacheToken` in sync)
@synchronized (operation) {
if (operation.isCancelled) {
return;
}
}
doneBlock(diskImage, diskData, SDImageCacheTypeDisk);
});
}