Skip to content

Commit d57b92c

Browse files
author
Sebastian Rehnby
committed
Detect parent operation cancellation in download operation completion block
1 parent 05dd3f4 commit d57b92c

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

SDWebImage/SDWebImageManager.m

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ - (NSString *)cacheKeyForURL:(NSURL *)url
7676
}
7777

7878
__block SDWebImageCombinedOperation *operation = SDWebImageCombinedOperation.new;
79+
__weak SDWebImageCombinedOperation *weakOperation = operation;
7980

8081
if (!url || !completedBlock || (!(options & SDWebImageRetryFailed) && [self.failedURLs containsObject:url]))
8182
{
@@ -108,7 +109,11 @@ - (NSString *)cacheKeyForURL:(NSURL *)url
108109
if (options & SDWebImageProgressiveDownload) downloaderOptions |= SDWebImageDownloaderProgressiveDownload;
109110
__block id<SDWebImageOperation> subOperation = [self.imageDownloader downloadImageWithURL:url options:downloaderOptions progress:progressBlock completed:^(UIImage *downloadedImage, NSData *data, NSError *error, BOOL finished)
110111
{
111-
if (error)
112+
if (weakOperation.cancelled)
113+
{
114+
completedBlock(nil, nil, SDImageCacheTypeNone, finished);
115+
}
116+
else if (error)
112117
{
113118
completedBlock(nil, error, SDImageCacheTypeNone, finished);
114119

0 commit comments

Comments
 (0)