Browse Source

Adjusted dispatch_async logic

Kevin Harwood 10 years ago
parent
commit
641f342fad
1 changed files with 4 additions and 6 deletions
  1. 4 6
      UIKit+AFNetworking/AFImageDownloader.m

+ 4 - 6
UIKit+AFNetworking/AFImageDownloader.m

@@ -199,11 +199,11 @@
             case NSURLRequestReturnCacheDataDontLoad: {
             case NSURLRequestReturnCacheDataDontLoad: {
                 UIImage *cachedImage = [self.imageCache imageforRequest:request withAdditionalIdentifier:nil];
                 UIImage *cachedImage = [self.imageCache imageforRequest:request withAdditionalIdentifier:nil];
                 if (cachedImage != nil) {
                 if (cachedImage != nil) {
-                    dispatch_async(dispatch_get_main_queue(), ^{
-                        if (success) {
+                    if (success) {
+                        dispatch_async(dispatch_get_main_queue(), ^{
                             success(request, nil, cachedImage);
                             success(request, nil, cachedImage);
-                        }
-                    });
+                        });
+                    }
                     return;
                     return;
                 }
                 }
                 break;
                 break;
@@ -222,7 +222,6 @@
                            dispatch_async(self.responseQueue, ^{
                            dispatch_async(self.responseQueue, ^{
                                __strong typeof(weakSelf) strongSelf = weakSelf;
                                __strong typeof(weakSelf) strongSelf = weakSelf;
                                AFImageDownloaderMergedTask *mergedTask = [strongSelf safelyRemoveMergedTaskWithIdentifier:identifier];
                                AFImageDownloaderMergedTask *mergedTask = [strongSelf safelyRemoveMergedTaskWithIdentifier:identifier];
-
                                [strongSelf.imageCache addImage:responseObject forRequest:task.originalRequest withAdditionalIdentifier:nil];
                                [strongSelf.imageCache addImage:responseObject forRequest:task.originalRequest withAdditionalIdentifier:nil];
 
 
                                for (AFImageDownloaderResponseHandler *handler in mergedTask.responseHandlers) {
                                for (AFImageDownloaderResponseHandler *handler in mergedTask.responseHandlers) {
@@ -363,7 +362,6 @@
     return self.activeRequestCount < self.maximumActiveDownloads;
     return self.activeRequestCount < self.maximumActiveDownloads;
 }
 }
 
 
-
 @end
 @end
 
 
 #endif
 #endif