Skip to content

Commit

Permalink
Merge pull request AFNetworking#4246 from bbeversdorf/master
Browse files Browse the repository at this point in the history
Safely get mergedTasks On responseQueue
  • Loading branch information
SlaunchaMan authored Jul 13, 2018
2 parents 009e3bb + 342653f commit d135b74
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion UIKit+AFNetworking/AFImageDownloader.m
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ - (nullable AFImageDownloadReceipt *)downloadImageForURLRequest:(NSURLRequest *)
completionHandler:^(NSURLResponse * _Nonnull response, id _Nullable responseObject, NSError * _Nullable error) {
dispatch_async(self.responseQueue, ^{
__strong __typeof__(weakSelf) strongSelf = weakSelf;
AFImageDownloaderMergedTask *mergedTask = strongSelf.mergedTasks[URLIdentifier];
AFImageDownloaderMergedTask *mergedTask = [strongSelf safelyGetMergedTask:URLIdentifier];
if ([mergedTask.identifier isEqual:mergedTaskIdentifier]) {
mergedTask = [strongSelf safelyRemoveMergedTaskWithURLIdentifier:URLIdentifier];
if (error) {
Expand Down Expand Up @@ -404,6 +404,14 @@ - (BOOL)isActiveRequestCountBelowMaximumLimit {
return self.activeRequestCount < self.maximumActiveDownloads;
}

- (AFImageDownloaderMergedTask *)safelyGetMergedTask:(NSString *)URLIdentifier {
__block AFImageDownloaderMergedTask *mergedTask;
dispatch_sync(self.synchronizationQueue, ^(){
mergedTask = self.mergedTasks[URLIdentifier];
});
return mergedTask;
}

@end

#endif

0 comments on commit d135b74

Please sign in to comment.