|
14 | 14 | #import "SDImageCacheDefine.h"
|
15 | 15 | #import "SDCallbackQueue.h"
|
16 | 16 |
|
| 17 | +BOOL SDWebImageDownloaderOperationGetCompleted(id<SDWebImageDownloaderOperation> operation); // Private currently, mark open if needed |
| 18 | + |
17 | 19 | // A handler to represent individual request
|
18 | 20 | @interface SDWebImageDownloaderOperationToken : NSObject
|
19 | 21 |
|
@@ -74,7 +76,6 @@ @interface SDWebImageDownloaderOperation ()
|
74 | 76 | @property (strong, nonatomic, readwrite, nullable) NSURLSessionTaskMetrics *metrics API_AVAILABLE(macosx(10.12), ios(10.0), watchos(3.0), tvos(10.0));
|
75 | 77 |
|
76 | 78 | @property (strong, nonatomic, nonnull) dispatch_queue_t coderQueue; // the serial operation queue to do image decoding
|
77 |
| -@property (assign, readwrite) BOOL isTransferFinished; // Whether current operation's network transfer is finished (actually, `didCompleteWithError` already been called) |
78 | 79 |
|
79 | 80 | @property (strong, nonatomic, nonnull) NSMapTable<SDImageCoderOptions *, UIImage *> *imageMap; // each variant of image is weak-referenced to avoid too many re-decode during downloading
|
80 | 81 | #if SD_UIKIT
|
@@ -472,7 +473,7 @@ - (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)data
|
472 | 473 | return;
|
473 | 474 | }
|
474 | 475 | // When cancelled or transfer finished (`didCompleteWithError`), cancel the progress callback, only completed block is called and enough
|
475 |
| - if (self.isCancelled || self.isTransferFinished) { |
| 476 | + if (self.isCancelled || SDWebImageDownloaderOperationGetCompleted(self)) { |
476 | 477 | return;
|
477 | 478 | }
|
478 | 479 | UIImage *image = SDImageLoaderDecodeProgressiveImageData(imageData, self.request.URL, NO, self, [[self class] imageOptionsFromDownloaderOptions:self.options], self.context);
|
@@ -512,7 +513,6 @@ - (void)URLSession:(NSURLSession *)session
|
512 | 513 | - (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error {
|
513 | 514 | // If we already cancel the operation or anything mark the operation finished, don't callback twice
|
514 | 515 | if (self.isFinished) return;
|
515 |
| - self.isTransferFinished = YES; |
516 | 516 |
|
517 | 517 | NSArray<SDWebImageDownloaderOperationToken *> *tokens;
|
518 | 518 | @synchronized (self) {
|
@@ -599,16 +599,13 @@ - (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didComp
|
599 | 599 | });
|
600 | 600 | }
|
601 | 601 | // call [self done] after all completed block was dispatched
|
602 |
| - dispatch_barrier_async(self.coderQueue, ^{ |
| 602 | + dispatch_async(self.coderQueue, ^{ |
603 | 603 | @strongify(self);
|
604 | 604 | if (!self) {
|
605 | 605 | return;
|
606 | 606 | }
|
607 | 607 | [self done];
|
608 | 608 | });
|
609 |
| - dispatch_async(self.coderQueue, ^{ |
610 |
| - [self done]; |
611 |
| - }); |
612 | 609 | }
|
613 | 610 | } else {
|
614 | 611 | [self callCompletionBlocksWithError:[NSError errorWithDomain:SDWebImageErrorDomain code:SDWebImageErrorBadImageData userInfo:@{NSLocalizedDescriptionKey : @"Image data is nil"}]];
|
|
0 commit comments