Skip to content

Commit

Permalink
ensure that the key is synchronized after being added
Browse files Browse the repository at this point in the history
  • Loading branch information
hank121314 committed Dec 29, 2023
1 parent 6d51e58 commit fe9a371
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions Sources/Defaults/Defaults+iCloud.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ extension Defaults {
for key in keys {
localKeysMonitor.addObserver(key)
}
self.syncWithoutWaiting(keys)
}

/**
Expand Down Expand Up @@ -131,10 +132,13 @@ extension Defaults {
*/
func syncWithoutWaiting(_ keys: [Defaults.Keys] = [], _ source: DataSource? = nil) {
let keys = keys.isEmpty ? Array(self.keys) : keys
let latest = source ?? latestDataSource()

for key in keys {
backgroundQueue.async {
backgroundQueue.async { [weak self] in
guard let self else {
return
}
let latest = source ?? latestDataSource()
await self.syncKey(key, latest)
}
}
Expand Down

0 comments on commit fe9a371

Please sign in to comment.