|
@@ -51,20 +51,11 @@
|
|
|
_manager = manager;
|
|
_manager = manager;
|
|
|
_runningTokens = [NSMutableSet set];
|
|
_runningTokens = [NSMutableSet set];
|
|
|
_options = SDWebImageLowPriority;
|
|
_options = SDWebImageLowPriority;
|
|
|
- _prefetcherQueue = dispatch_get_main_queue();
|
|
|
|
|
- self.maxConcurrentDownloads = 3;
|
|
|
|
|
|
|
+ _delegateQueue = dispatch_get_main_queue();
|
|
|
}
|
|
}
|
|
|
return self;
|
|
return self;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-- (void)setMaxConcurrentDownloads:(NSUInteger)maxConcurrentDownloads {
|
|
|
|
|
- self.manager.imageDownloader.maxConcurrentDownloads = maxConcurrentDownloads;
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-- (NSUInteger)maxConcurrentDownloads {
|
|
|
|
|
- return self.manager.imageDownloader.maxConcurrentDownloads;
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
#pragma mark - Prefetch
|
|
#pragma mark - Prefetch
|
|
|
- (nullable SDWebImagePrefetchToken *)prefetchURLs:(nullable NSArray<NSURL *> *)urls {
|
|
- (nullable SDWebImagePrefetchToken *)prefetchURLs:(nullable NSArray<NSURL *> *)urls {
|
|
|
return [self prefetchURLs:urls progress:nil completed:nil];
|
|
return [self prefetchURLs:urls progress:nil completed:nil];
|
|
@@ -138,9 +129,11 @@
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
BOOL shouldCallDelegate = [self.delegate respondsToSelector:@selector(imagePrefetcher:didPrefetchURL:finishedCount:totalCount:)];
|
|
BOOL shouldCallDelegate = [self.delegate respondsToSelector:@selector(imagePrefetcher:didPrefetchURL:finishedCount:totalCount:)];
|
|
|
- dispatch_queue_async_safe(self.prefetcherQueue, ^{
|
|
|
|
|
|
|
+ NSUInteger finishedCount = [self tokenFinishedCount];
|
|
|
|
|
+ NSUInteger totalCount = [self tokenTotalCount];
|
|
|
|
|
+ dispatch_async(self.delegateQueue, ^{
|
|
|
if (shouldCallDelegate) {
|
|
if (shouldCallDelegate) {
|
|
|
- [self.delegate imagePrefetcher:self didPrefetchURL:url finishedCount:[self tokenFinishedCount] totalCount:[self tokenTotalCount]];
|
|
|
|
|
|
|
+ [self.delegate imagePrefetcher:self didPrefetchURL:url finishedCount:finishedCount totalCount:totalCount];
|
|
|
}
|
|
}
|
|
|
if (token.progressBlock) {
|
|
if (token.progressBlock) {
|
|
|
token.progressBlock((NSUInteger)token->_finishedCount, (NSUInteger)token.totalCount);
|
|
token.progressBlock((NSUInteger)token->_finishedCount, (NSUInteger)token.totalCount);
|
|
@@ -153,9 +146,11 @@
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
BOOL shoulCallDelegate = [self.delegate respondsToSelector:@selector(imagePrefetcher:didFinishWithTotalCount:skippedCount:)] && ([self countOfRunningTokens] == 1); // last one
|
|
BOOL shoulCallDelegate = [self.delegate respondsToSelector:@selector(imagePrefetcher:didFinishWithTotalCount:skippedCount:)] && ([self countOfRunningTokens] == 1); // last one
|
|
|
- dispatch_queue_async_safe(self.prefetcherQueue, ^{
|
|
|
|
|
|
|
+ NSUInteger totalCount = [self tokenTotalCount];
|
|
|
|
|
+ NSUInteger skippedCount = [self tokenSkippedCount];
|
|
|
|
|
+ dispatch_async(self.delegateQueue, ^{
|
|
|
if (shoulCallDelegate) {
|
|
if (shoulCallDelegate) {
|
|
|
- [self.delegate imagePrefetcher:self didFinishWithTotalCount:[self tokenTotalCount] skippedCount:[self tokenSkippedCount]];
|
|
|
|
|
|
|
+ [self.delegate imagePrefetcher:self didFinishWithTotalCount:totalCount skippedCount:skippedCount];
|
|
|
}
|
|
}
|
|
|
if (token.completionBlock) {
|
|
if (token.completionBlock) {
|
|
|
token.completionBlock((NSUInteger)token->_finishedCount, (NSUInteger)token->_skippedCount);
|
|
token.completionBlock((NSUInteger)token->_finishedCount, (NSUInteger)token->_skippedCount);
|