2
0
Эх сурвалжийг харах

Fixes race condition for State property

Bruno Guidolim 6 жил өмнө
parent
commit
271bf50b93

+ 12 - 1
Sources/General/KingfisherManager.swift

@@ -628,11 +628,22 @@ class CacheCallbackCoordinator {
     private let shouldWaitForCache: Bool
     private let shouldCacheOriginal: Bool
 
-    private (set) var state: State = .idle
+    private let stateQueue: DispatchQueue
+    private (set) var state: State {
+        set {
+            stateQueue.sync { threadSafeState = newValue }
+        }
+        get {
+            stateQueue.sync { threadSafeState }
+        }
+    }
+    private var threadSafeState: State = .idle
 
     init(shouldWaitForCache: Bool, shouldCacheOriginal: Bool) {
         self.shouldWaitForCache = shouldWaitForCache
         self.shouldCacheOriginal = shouldCacheOriginal
+        let stateQueueName = "com.onevcat.Kingfisher.KingfisherManager.stateQueue.\(UUID().uuidString)"
+        self.stateQueue = DispatchQueue(label: stateQueueName)
     }
 
     func apply(_ action: Action, trigger: () -> Void) {