From 692f01b84b2f4e528514c3b1513c88585c8a1afe Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Mon, 2 Mar 2020 13:06:09 +0800 Subject: [PATCH] Fix the rare case when call `SDWebImageDownloaderOperation.cancel`, the completion block will callback twice --- SDWebImage/Core/SDWebImageDownloaderOperation.m | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/SDWebImage/Core/SDWebImageDownloaderOperation.m b/SDWebImage/Core/SDWebImageDownloaderOperation.m index 9411dcac..67d1a8e2 100644 --- a/SDWebImage/Core/SDWebImageDownloaderOperation.m +++ b/SDWebImage/Core/SDWebImageDownloaderOperation.m @@ -245,9 +245,10 @@ typedef NSMutableDictionary SDCallbacksDictionary; // maintain the isFinished and isExecuting flags. if (self.isExecuting) self.executing = NO; if (!self.isFinished) self.finished = YES; + } else { + // Operation cancelled by user during sending the request + [self callCompletionBlocksWithError:[NSError errorWithDomain:SDWebImageErrorDomain code:SDWebImageErrorCancelled userInfo:@{NSLocalizedDescriptionKey : @"Operation cancelled by user during sending the request"}]]; } - // Operation cancelled by user during sending the request - [self callCompletionBlocksWithError:[NSError errorWithDomain:SDWebImageErrorDomain code:SDWebImageErrorCancelled userInfo:@{NSLocalizedDescriptionKey : @"Operation cancelled by user during sending the request"}]]; [self reset]; }