diff --git a/SDWebImage/Core/SDWebImageManager.h b/SDWebImage/Core/SDWebImageManager.h index ee90724e..fcac52ea 100644 --- a/SDWebImage/Core/SDWebImageManager.h +++ b/SDWebImage/Core/SDWebImageManager.h @@ -29,6 +29,9 @@ typedef void(^SDInternalCompletionBlock)(UIImage * _Nullable image, NSData * _Nu */ - (void)cancel; +/// Whether the operation has been cancelled. +@property (nonatomic, assign, readonly, getter=isCancelled) BOOL cancelled; + /** The cache operation from the image cache query */ diff --git a/SDWebImage/Core/SDWebImageManager.m b/SDWebImage/Core/SDWebImageManager.m index 3b29632d..99b83e55 100644 --- a/SDWebImage/Core/SDWebImageManager.m +++ b/SDWebImage/Core/SDWebImageManager.m @@ -803,12 +803,20 @@ static id _defaultImageLoader; @implementation SDWebImageCombinedOperation +- (BOOL)isCancelled { + // Need recursive lock (user's cancel block may check isCancelled), do not use SD_LOCK + @synchronized (self) { + return _cancelled; + } +} + - (void)cancel { + // Need recursive lock (user's cancel block may check isCancelled), do not use SD_LOCK @synchronized(self) { - if (self.isCancelled) { + if (_cancelled) { return; } - self.cancelled = YES; + _cancelled = YES; if (self.cacheOperation) { [self.cacheOperation cancel]; self.cacheOperation = nil;