Skip to content

Commit

Permalink
Merge pull request onevcat#1394 from bguidolim/fix-state-race-condition
Browse files Browse the repository at this point in the history
Fixes race condition for State of CacheCallbackCoordinator
  • Loading branch information
onevcat authored Feb 26, 2020
2 parents 8458ae1 + 83b7756 commit 7eee705
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion Sources/General/KingfisherManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -627,12 +627,19 @@ class CacheCallbackCoordinator {

private let shouldWaitForCache: Bool
private let shouldCacheOriginal: Bool
private let stateQueue: DispatchQueue
private var threadSafeState: State = .idle

private (set) var state: State = .idle
private (set) var state: State {
set { stateQueue.sync { threadSafeState = newValue } }
get { stateQueue.sync { threadSafeState } }
}

init(shouldWaitForCache: Bool, shouldCacheOriginal: Bool) {
self.shouldWaitForCache = shouldWaitForCache
self.shouldCacheOriginal = shouldCacheOriginal
let stateQueueName = "com.onevcat.Kingfisher.CacheCallbackCoordinator.stateQueue.\(UUID().uuidString)"
self.stateQueue = DispatchQueue(label: stateQueueName)
}

func apply(_ action: Action, trigger: () -> Void) {
Expand Down

0 comments on commit 7eee705

Please sign in to comment.