فهرست منبع

Retrieving image now schedule the callback on main

onevcat 6 سال پیش
والد
کامیت
10d0edbf9a
2فایلهای تغییر یافته به همراه7 افزوده شده و 12 حذف شده
  1. 0 5
      Kingfisher.xcodeproj/xcshareddata/xcschemes/Kingfisher.xcscheme
  2. 7 7
      Sources/Cache/ImageCache.swift

+ 0 - 5
Kingfisher.xcodeproj/xcshareddata/xcschemes/Kingfisher.xcscheme

@@ -48,11 +48,6 @@
                BlueprintName = "KingfisherTests"
                ReferencedContainer = "container:Kingfisher.xcodeproj">
             </BuildableReference>
-            <SkippedTests>
-               <Test
-                  Identifier = "ImagePrefetcherTests">
-               </Test>
-            </SkippedTests>
          </TestableReference>
       </Testables>
    </TestAction>

+ 7 - 7
Sources/Cache/ImageCache.swift

@@ -448,7 +448,7 @@ open class ImageCache {
 
     func retrieveImage(forKey key: String,
                        options: KingfisherParsedOptionsInfo,
-                       callbackQueue: CallbackQueue = .untouch,
+                       callbackQueue: CallbackQueue = .mainCurrentOrAsync,
                        completionHandler: ((Result<ImageCacheResult, KingfisherError>) -> Void)?)
     {
         // No completion handler. No need to start working and early return.
@@ -461,16 +461,16 @@ open class ImageCache {
         } else if options.fromMemoryCacheOrRefresh {
             callbackQueue.execute { completionHandler(.success(.none)) }
         } else {
+
             // Begin to disk search.
             self.retrieveImageInDiskCache(forKey: key, options: options, callbackQueue: callbackQueue) {
                 result in
-                // The callback queue is already correct in this closure.
                 switch result {
                 case .success(let image):
 
                     guard let image = image else {
                         // No image found in disk storage.
-                        completionHandler(.success(.none))
+                        callbackQueue.execute { completionHandler(.success(.none)) }
                         return
                     }
 
@@ -487,10 +487,10 @@ open class ImageCache {
                         toDisk: false)
                     {
                         _ in
-                        completionHandler(.success(.disk(finalImage)))
+                        callbackQueue.execute { completionHandler(.success(.disk(finalImage))) }
                     }
                 case .failure(let error):
-                    completionHandler(.failure(error))
+                    callbackQueue.execute { completionHandler(.failure(error)) }
                 }
             }
         }
@@ -503,14 +503,14 @@ open class ImageCache {
     /// - Parameters:
     ///   - key: The key used for caching the image.
     ///   - options: The `KingfisherOptionsInfo` options setting used for retrieving the image.
-    ///   - callbackQueue: The callback queue on which `completionHandler` is invoked. Default is `.untouch`.
+    ///   - callbackQueue: The callback queue on which `completionHandler` is invoked. Default is `.mainCurrentOrAsync`.
     ///   - completionHandler: A closure which is invoked when the image getting operation finishes. If the
     ///                        image retrieving operation finishes without problem, an `ImageCacheResult` value
     ///                        will be sent to this closure as result. Otherwise, a `KingfisherError` result
     ///                        with detail failing reason will be sent.
     open func retrieveImage(forKey key: String,
                                options: KingfisherOptionsInfo? = nil,
-                        callbackQueue: CallbackQueue = .untouch,
+                        callbackQueue: CallbackQueue = .mainCurrentOrAsync,
                      completionHandler: ((Result<ImageCacheResult, KingfisherError>) -> Void)?)
     {
         retrieveImage(