Permalink
Browse files

Merge pull request #311 from sebreh/master

Detect cancelled parent operation in download operation callback
  • Loading branch information...
2 parents 05dd3f4 + d57b92c commit 95337c47e91c40bb2db808e1b0ffc03a9312bd83 @rs committed Feb 26, 2013
Showing with 6 additions and 1 deletion.
  1. +6 −1 SDWebImage/SDWebImageManager.m
@@ -76,6 +76,7 @@ - (NSString *)cacheKeyForURL:(NSURL *)url
}
__block SDWebImageCombinedOperation *operation = SDWebImageCombinedOperation.new;
+ __weak SDWebImageCombinedOperation *weakOperation = operation;
if (!url || !completedBlock || (!(options & SDWebImageRetryFailed) && [self.failedURLs containsObject:url]))
{
@@ -108,7 +109,11 @@ - (NSString *)cacheKeyForURL:(NSURL *)url
if (options & SDWebImageProgressiveDownload) downloaderOptions |= SDWebImageDownloaderProgressiveDownload;
__block id<SDWebImageOperation> subOperation = [self.imageDownloader downloadImageWithURL:url options:downloaderOptions progress:progressBlock completed:^(UIImage *downloadedImage, NSData *data, NSError *error, BOOL finished)
{
- if (error)
+ if (weakOperation.cancelled)
+ {
+ completedBlock(nil, nil, SDImageCacheTypeNone, finished);
+ }
+ else if (error)
{
completedBlock(nil, error, SDImageCacheTypeNone, finished);

0 comments on commit 95337c4

Please sign in to comment.