Merge pull request #1046 from hoppenichu/fix_downloader
Fix SDWebImageDownloader threading issue
This commit is contained in:
commit
0f157d4332
|
@ -135,7 +135,10 @@ static NSString *const kCompletedCallbackKey = @"completed";
|
|||
progress:^(NSInteger receivedSize, NSInteger expectedSize) {
|
||||
SDWebImageDownloader *sself = wself;
|
||||
if (!sself) return;
|
||||
NSArray *callbacksForURL = [sself callbacksForURL:url];
|
||||
__block NSArray *callbacksForURL;
|
||||
dispatch_sync(sself.barrierQueue, ^{
|
||||
callbacksForURL = sself.URLCallbacks[url];
|
||||
});
|
||||
for (NSDictionary *callbacks in callbacksForURL) {
|
||||
SDWebImageDownloaderProgressBlock callback = callbacks[kProgressCallbackKey];
|
||||
if (callback) callback(receivedSize, expectedSize);
|
||||
|
@ -144,10 +147,13 @@ static NSString *const kCompletedCallbackKey = @"completed";
|
|||
completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) {
|
||||
SDWebImageDownloader *sself = wself;
|
||||
if (!sself) return;
|
||||
NSArray *callbacksForURL = [sself callbacksForURL:url];
|
||||
if (finished) {
|
||||
[sself removeCallbacksForURL:url];
|
||||
}
|
||||
__block NSArray *callbacksForURL;
|
||||
dispatch_barrier_sync(sself.barrierQueue, ^{
|
||||
callbacksForURL = sself.URLCallbacks[url];
|
||||
if (finished) {
|
||||
[sself.URLCallbacks removeObjectForKey:url];
|
||||
}
|
||||
});
|
||||
for (NSDictionary *callbacks in callbacksForURL) {
|
||||
SDWebImageDownloaderCompletedBlock callback = callbacks[kCompletedCallbackKey];
|
||||
if (callback) callback(image, data, error, finished);
|
||||
|
@ -156,7 +162,9 @@ static NSString *const kCompletedCallbackKey = @"completed";
|
|||
cancelled:^{
|
||||
SDWebImageDownloader *sself = wself;
|
||||
if (!sself) return;
|
||||
[sself removeCallbacksForURL:url];
|
||||
dispatch_barrier_async(sself.barrierQueue, ^{
|
||||
[sself.URLCallbacks removeObjectForKey:url];
|
||||
});
|
||||
}];
|
||||
|
||||
if (wself.username && wself.password) {
|
||||
|
@ -210,20 +218,6 @@ static NSString *const kCompletedCallbackKey = @"completed";
|
|||
});
|
||||
}
|
||||
|
||||
- (NSArray *)callbacksForURL:(NSURL *)url {
|
||||
__block NSArray *callbacksForURL;
|
||||
dispatch_sync(self.barrierQueue, ^{
|
||||
callbacksForURL = self.URLCallbacks[url];
|
||||
});
|
||||
return [callbacksForURL copy];
|
||||
}
|
||||
|
||||
- (void)removeCallbacksForURL:(NSURL *)url {
|
||||
dispatch_barrier_async(self.barrierQueue, ^{
|
||||
[self.URLCallbacks removeObjectForKey:url];
|
||||
});
|
||||
}
|
||||
|
||||
- (void)setSuspended:(BOOL)suspended {
|
||||
[self.downloadQueue setSuspended:suspended];
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ xcodeproj 'SDWebImage Tests'
|
|||
workspace '../SDWebImage'
|
||||
|
||||
def import_pods
|
||||
pod 'Expecta' # A Matcher Framework for Objective-C/Cocoa
|
||||
pod 'Expecta', '<=0.3.1' # A Matcher Framework for Objective-C/Cocoa
|
||||
pod 'SDWebImage', :path => '../'
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue