Fixed an issue with the `SDWebImageDownloaderOperation` : `cancelInternal` was not called because of the old mechanism rellying on the `thread` property - probably because that thread did not have a runloop. Removed that and now cancelInternal is called as expected

This commit is contained in:
Bogdan Poplauschi 2016-09-23 20:46:30 +03:00
parent 84be05b867
commit f4bdae6870
1 changed files with 1 additions and 15 deletions

View File

@ -39,7 +39,6 @@ typedef NSMutableDictionary<NSString *, id> SDCallbacksDictionary;
@property (strong, nonatomic, readwrite, nullable) NSURLSessionTask *dataTask; @property (strong, nonatomic, readwrite, nullable) NSURLSessionTask *dataTask;
@property (strong, atomic, nullable) NSThread *thread;
@property (SDDispatchQueueSetterSementics, nonatomic, nullable) dispatch_queue_t barrierQueue; @property (SDDispatchQueueSetterSementics, nonatomic, nullable) dispatch_queue_t barrierQueue;
#if SD_UIKIT #if SD_UIKIT
@ -164,7 +163,6 @@ typedef NSMutableDictionary<NSString *, id> SDCallbacksDictionary;
self.dataTask = [session dataTaskWithRequest:self.request]; self.dataTask = [session dataTaskWithRequest:self.request];
self.executing = YES; self.executing = YES;
self.thread = [NSThread currentThread];
} }
[self.dataTask resume]; [self.dataTask resume];
@ -197,20 +195,10 @@ typedef NSMutableDictionary<NSString *, id> SDCallbacksDictionary;
- (void)cancel { - (void)cancel {
@synchronized (self) { @synchronized (self) {
if (self.thread) { [self cancelInternal];
[self performSelector:@selector(cancelInternalAndStop) onThread:self.thread withObject:nil waitUntilDone:NO];
}
else {
[self cancelInternal];
}
} }
} }
- (void)cancelInternalAndStop {
if (self.isFinished) return;
[self cancelInternal];
}
- (void)cancelInternal { - (void)cancelInternal {
if (self.isFinished) return; if (self.isFinished) return;
[super cancel]; [super cancel];
@ -242,7 +230,6 @@ typedef NSMutableDictionary<NSString *, id> SDCallbacksDictionary;
}); });
self.dataTask = nil; self.dataTask = nil;
self.imageData = nil; self.imageData = nil;
self.thread = nil;
if (self.ownedSession) { if (self.ownedSession) {
[self.ownedSession invalidateAndCancel]; [self.ownedSession invalidateAndCancel];
self.ownedSession = nil; self.ownedSession = nil;
@ -423,7 +410,6 @@ didReceiveResponse:(NSURLResponse *)response
- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error { - (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error {
NSArray<id> *completionBlocks = [[self callbacksForKey:kCompletedCallbackKey] copy]; NSArray<id> *completionBlocks = [[self callbacksForKey:kCompletedCallbackKey] copy];
@synchronized(self) { @synchronized(self) {
self.thread = nil;
self.dataTask = nil; self.dataTask = nil;
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
[[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadStopNotification object:self]; [[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadStopNotification object:self];