Merge pull request #751 from robertmryan/master
Avoid premature completion of prefetcher if request fails
This commit is contained in:
commit
9dcd68d5ee
|
@ -127,8 +127,8 @@ static NSString *const kCompletedCallbackKey = @"completed";
|
||||||
operation = [[SDWebImageDownloaderOperation alloc] initWithRequest:request
|
operation = [[SDWebImageDownloaderOperation alloc] initWithRequest:request
|
||||||
options:options
|
options:options
|
||||||
progress:^(NSInteger receivedSize, NSInteger expectedSize) {
|
progress:^(NSInteger receivedSize, NSInteger expectedSize) {
|
||||||
if (!wself) return;
|
|
||||||
SDWebImageDownloader *sself = wself;
|
SDWebImageDownloader *sself = wself;
|
||||||
|
if (!sself) return;
|
||||||
NSArray *callbacksForURL = [sself callbacksForURL:url];
|
NSArray *callbacksForURL = [sself callbacksForURL:url];
|
||||||
for (NSDictionary *callbacks in callbacksForURL) {
|
for (NSDictionary *callbacks in callbacksForURL) {
|
||||||
SDWebImageDownloaderProgressBlock callback = callbacks[kProgressCallbackKey];
|
SDWebImageDownloaderProgressBlock callback = callbacks[kProgressCallbackKey];
|
||||||
|
@ -136,8 +136,8 @@ static NSString *const kCompletedCallbackKey = @"completed";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) {
|
completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) {
|
||||||
if (!wself) return;
|
|
||||||
SDWebImageDownloader *sself = wself;
|
SDWebImageDownloader *sself = wself;
|
||||||
|
if (!sself) return;
|
||||||
NSArray *callbacksForURL = [sself callbacksForURL:url];
|
NSArray *callbacksForURL = [sself callbacksForURL:url];
|
||||||
if (finished) {
|
if (finished) {
|
||||||
[sself removeCallbacksForURL:url];
|
[sself removeCallbacksForURL:url];
|
||||||
|
@ -148,8 +148,8 @@ static NSString *const kCompletedCallbackKey = @"completed";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cancelled:^{
|
cancelled:^{
|
||||||
if (!wself) return;
|
|
||||||
SDWebImageDownloader *sself = wself;
|
SDWebImageDownloader *sself = wself;
|
||||||
|
if (!sself) return;
|
||||||
[sself removeCallbacksForURL:url];
|
[sself removeCallbacksForURL:url];
|
||||||
}];
|
}];
|
||||||
|
|
||||||
|
|
|
@ -20,15 +20,15 @@
|
||||||
*
|
*
|
||||||
* @param imagePrefetcher The current image prefetcher
|
* @param imagePrefetcher The current image prefetcher
|
||||||
* @param imageURL The image url that was prefetched
|
* @param imageURL The image url that was prefetched
|
||||||
* @param finishedCount The total number of images that were prefetched
|
* @param finishedCount The total number of images that were prefetched (successful or not)
|
||||||
* @param totalCount The total number of images that need to be prefetched
|
* @param totalCount The total number of images that were to be prefetched
|
||||||
*/
|
*/
|
||||||
- (void)imagePrefetcher:(SDWebImagePrefetcher *)imagePrefetcher didPrefetchURL:(NSURL *)imageURL finishedCount:(NSUInteger)finishedCount totalCount:(NSUInteger)totalCount;
|
- (void)imagePrefetcher:(SDWebImagePrefetcher *)imagePrefetcher didPrefetchURL:(NSURL *)imageURL finishedCount:(NSUInteger)finishedCount totalCount:(NSUInteger)totalCount;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when all images are prefetched.
|
* Called when all images are prefetched.
|
||||||
* @param imagePrefetcher The current image prefetcher
|
* @param imagePrefetcher The current image prefetcher
|
||||||
* @param totalCount The total number of images that need to be prefetched
|
* @param totalCount The total number of images that were prefetched (whether successful or not)
|
||||||
* @param skippedCount The total number of images that were skipped
|
* @param skippedCount The total number of images that were skipped
|
||||||
*/
|
*/
|
||||||
- (void)imagePrefetcher:(SDWebImagePrefetcher *)imagePrefetcher didFinishWithTotalCount:(NSUInteger)totalCount skippedCount:(NSUInteger)skippedCount;
|
- (void)imagePrefetcher:(SDWebImagePrefetcher *)imagePrefetcher didFinishWithTotalCount:(NSUInteger)totalCount skippedCount:(NSUInteger)skippedCount;
|
||||||
|
@ -78,7 +78,7 @@
|
||||||
* and skips images for failed downloads and proceed to the next image in the list
|
* and skips images for failed downloads and proceed to the next image in the list
|
||||||
*
|
*
|
||||||
* @param urls list of URLs to prefetch
|
* @param urls list of URLs to prefetch
|
||||||
* @param progressBlock block to be called when progress updates
|
* @param progressBlock block to be called when progress updates; first parameter is the number of completed (successful or not) requests, second parameter is the total number of images originally requested to be prefetched
|
||||||
* @param completionBlock block to be called when prefetching is completed
|
* @param completionBlock block to be called when prefetching is completed
|
||||||
*/
|
*/
|
||||||
- (void)prefetchURLs:(NSArray *)urls progress:(void (^)(NSUInteger, NSUInteger))progressBlock completed:(void (^)(NSUInteger, NSUInteger))completionBlock;
|
- (void)prefetchURLs:(NSArray *)urls progress:(void (^)(NSUInteger, NSUInteger))progressBlock completed:(void (^)(NSUInteger, NSUInteger))completionBlock;
|
||||||
|
|
|
@ -88,7 +88,7 @@
|
||||||
[self startPrefetchingAtIndex:self.requestedCount];
|
[self startPrefetchingAtIndex:self.requestedCount];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else if (self.finishedCount + self.skippedCount == self.requestedCount) {
|
else if (self.finishedCount == self.requestedCount) {
|
||||||
[self reportStatus];
|
[self reportStatus];
|
||||||
if (self.completionBlock) {
|
if (self.completionBlock) {
|
||||||
self.completionBlock(self.finishedCount, self.skippedCount);
|
self.completionBlock(self.finishedCount, self.skippedCount);
|
||||||
|
|
Loading…
Reference in New Issue