一、进入SDWebImageDownloader.m文件
1.再进入到该方法
2.先检查url,然后再根据url获取operation,如果operation存在可以避免重复下载操作
NSOperation<SDWebImageDownloaderOperation> *operation = [self.URLOperations objectForKey:url];
查看SDWebImageDownloaderOperation,发现它实现了NSURLSessionTaskDelegate, NSURLSessionDataDelegate协议
再查看URLOperations
@property** (strong,nonatomic, nonnull) NSMutableDictionary<NSURL *, NSOperation<SDWebImageDownloaderOperation> *> *URLOperations;
(1)当我们重用下载操作来附加更多回调时,可能会出现线程安全问题,因为回调的getter可能位于另一个队列中(解码队列或委托队列) 因此,我们在这里锁定操作,在“SDWebImageDownloaderOperation”中,我们使用“@synchonzied(self)”,以确保这两个类之间的线程安全。
3,如果(operation不存在)|| (任务被取消) || (任务已完成),调用 createDownloaderOperationWithUrl:options:context: 创建出新的 operation
(1)查看createDownloaderOperationWithUrl:options:context:方法,