Browse Source

Add `waitForCache` option

Yigitcan Yurtsever 7 years ago
parent
commit
1f9cb20491
1 changed files with 9 additions and 0 deletions
  1. 9 0
      Sources/KingfisherOptionsInfo.swift

+ 9 - 0
Sources/KingfisherOptionsInfo.swift

@@ -80,6 +80,9 @@ public enum KingfisherOptionsInfoItem {
     ///  If set, `Kingfisher` will only cache the value in memory but not in disk.
     case cacheMemoryOnly
     
+    ///  If set, `Kingfisher` will wait for caching operation to be completed before calling the completion block.
+    case waitForCache
+    
     /// If set, `Kingfisher` will only try to retrieve the image from cache not from network.
     case onlyFromCache
     
@@ -165,6 +168,7 @@ func <== (lhs: KingfisherOptionsInfoItem, rhs: KingfisherOptionsInfoItem) -> Boo
     case (.fromMemoryCacheOrRefresh, .fromMemoryCacheOrRefresh): return true
     case (.forceTransition, .forceTransition): return true
     case (.cacheMemoryOnly, .cacheMemoryOnly): return true
+    case (.waitForCache, .waitForCache): return true
     case (.onlyFromCache, .onlyFromCache): return true
     case (.backgroundDecode, .backgroundDecode): return true
     case (.callbackDispatchQueue(_), .callbackDispatchQueue(_)): return true
@@ -264,6 +268,11 @@ public extension Collection where Iterator.Element == KingfisherOptionsInfoItem
         return contains{ $0 <== .cacheMemoryOnly }
     }
     
+    /// Whether the caching operation will be waited or not.
+    public var waitForCache: Bool {
+        return contains{ $0 <== .waitForCache }
+    }
+    
     /// Whether only load the images from cache or not.
     public var onlyFromCache: Bool {
         return contains{ $0 <== .onlyFromCache }