Authored by Bogdan Poplauschi

Fixed an issue with the `SDWebImageDownloaderOperation` : `cancelInternal` was n…

…ot 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
@@ -39,7 +39,6 @@ typedef NSMutableDictionary<NSString *, id> SDCallbacksDictionary; @@ -39,7 +39,6 @@ typedef NSMutableDictionary<NSString *, id> SDCallbacksDictionary;
39 39
40 @property (strong, nonatomic, readwrite, nullable) NSURLSessionTask *dataTask; 40 @property (strong, nonatomic, readwrite, nullable) NSURLSessionTask *dataTask;
41 41
42 -@property (strong, atomic, nullable) NSThread *thread;  
43 @property (SDDispatchQueueSetterSementics, nonatomic, nullable) dispatch_queue_t barrierQueue; 42 @property (SDDispatchQueueSetterSementics, nonatomic, nullable) dispatch_queue_t barrierQueue;
44 43
45 #if SD_UIKIT 44 #if SD_UIKIT
@@ -164,7 +163,6 @@ typedef NSMutableDictionary<NSString *, id> SDCallbacksDictionary; @@ -164,7 +163,6 @@ typedef NSMutableDictionary<NSString *, id> SDCallbacksDictionary;
164 163
165 self.dataTask = [session dataTaskWithRequest:self.request]; 164 self.dataTask = [session dataTaskWithRequest:self.request];
166 self.executing = YES; 165 self.executing = YES;
167 - self.thread = [NSThread currentThread];  
168 } 166 }
169 167
170 [self.dataTask resume]; 168 [self.dataTask resume];
@@ -197,20 +195,10 @@ typedef NSMutableDictionary<NSString *, id> SDCallbacksDictionary; @@ -197,20 +195,10 @@ typedef NSMutableDictionary<NSString *, id> SDCallbacksDictionary;
197 195
198 - (void)cancel { 196 - (void)cancel {
199 @synchronized (self) { 197 @synchronized (self) {
200 - if (self.thread) {  
201 - [self performSelector:@selector(cancelInternalAndStop) onThread:self.thread withObject:nil waitUntilDone:NO];  
202 - }  
203 - else {  
204 - [self cancelInternal];  
205 - } 198 + [self cancelInternal];
206 } 199 }
207 } 200 }
208 201
209 -- (void)cancelInternalAndStop {  
210 - if (self.isFinished) return;  
211 - [self cancelInternal];  
212 -}  
213 -  
214 - (void)cancelInternal { 202 - (void)cancelInternal {
215 if (self.isFinished) return; 203 if (self.isFinished) return;
216 [super cancel]; 204 [super cancel];
@@ -242,7 +230,6 @@ typedef NSMutableDictionary<NSString *, id> SDCallbacksDictionary; @@ -242,7 +230,6 @@ typedef NSMutableDictionary<NSString *, id> SDCallbacksDictionary;
242 }); 230 });
243 self.dataTask = nil; 231 self.dataTask = nil;
244 self.imageData = nil; 232 self.imageData = nil;
245 - self.thread = nil;  
246 if (self.ownedSession) { 233 if (self.ownedSession) {
247 [self.ownedSession invalidateAndCancel]; 234 [self.ownedSession invalidateAndCancel];
248 self.ownedSession = nil; 235 self.ownedSession = nil;
@@ -423,7 +410,6 @@ didReceiveResponse:(NSURLResponse *)response @@ -423,7 +410,6 @@ didReceiveResponse:(NSURLResponse *)response
423 - (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error { 410 - (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error {
424 NSArray<id> *completionBlocks = [[self callbacksForKey:kCompletedCallbackKey] copy]; 411 NSArray<id> *completionBlocks = [[self callbacksForKey:kCompletedCallbackKey] copy];
425 @synchronized(self) { 412 @synchronized(self) {
426 - self.thread = nil;  
427 self.dataTask = nil; 413 self.dataTask = nil;
428 dispatch_async(dispatch_get_main_queue(), ^{ 414 dispatch_async(dispatch_get_main_queue(), ^{
429 [[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadStopNotification object:self]; 415 [[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadStopNotification object:self];