Refactory, remove the `cancel:` method on SDWebImageDownloader. This does the same thing as `token.downloadOperationCancelToken` since 5.1.0 we can always ensure `cancel will trigger a callback`

This commit is contained in:
DreamPiggy 2019-09-30 02:18:46 +08:00
parent 1096075ccb
commit a3a0260253
1 changed files with 1 additions and 25 deletions

View File

@ -26,7 +26,6 @@ static void * SDWebImageDownloaderContext = &SDWebImageDownloaderContext;
@property (nonatomic, strong, nullable, readwrite) NSURLResponse *response;
@property (nonatomic, weak, nullable, readwrite) id downloadOperationCancelToken;
@property (nonatomic, weak, nullable) NSOperation<SDWebImageDownloaderOperation> *downloadOperation;
@property (nonatomic, weak, nullable) SDWebImageDownloader *downloader;
@property (nonatomic, assign, getter=isCancelled) BOOL cancelled;
- (nonnull instancetype)init NS_UNAVAILABLE;
@ -253,7 +252,6 @@ static void * SDWebImageDownloaderContext = &SDWebImageDownloaderContext;
token.url = url;
token.request = operation.request;
token.downloadOperationCancelToken = downloadOperationCancelToken;
token.downloader = self;
return token;
}
@ -331,22 +329,6 @@ static void * SDWebImageDownloaderContext = &SDWebImageDownloaderContext;
return operation;
}
- (void)cancel:(nullable SDWebImageDownloadToken *)token {
NSURL *url = token.url;
if (!url) {
return;
}
SD_LOCK(self.operationsLock);
NSOperation<SDWebImageDownloaderOperation> *operation = [self.URLOperations objectForKey:url];
if (operation) {
BOOL canceled = [operation cancel:token.downloadOperationCancelToken];
if (canceled) {
[self.URLOperations removeObjectForKey:url];
}
}
SD_UNLOCK(self.operationsLock);
}
- (void)cancelAllDownloads {
[self.downloadQueue cancelAllOperations];
}
@ -506,13 +488,7 @@ didReceiveResponse:(NSURLResponse *)response
return;
}
self.cancelled = YES;
if (self.downloader) {
// Downloader is alive, cancel token
[self.downloader cancel:self];
} else {
// Downloader is dealloced, only cancel download operation
[self.downloadOperation cancel:self.downloadOperationCancelToken];
}
[self.downloadOperation cancel:self.downloadOperationCancelToken];
self.downloadOperationCancelToken = nil;
}
}