Skip to content

Commit cc938ec

Browse files
committed
Minor tweaks
1 parent 6740756 commit cc938ec

File tree

5 files changed

+9
-8
lines changed

5 files changed

+9
-8
lines changed

Sources/Defaults/Defaults+iCloud.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -236,12 +236,12 @@ final class iCloudSynchronizer {
236236
/**
237237
A thread-safe `keys` that manage the keys to be synced.
238238
*/
239-
@Atomic(value: []) private(set) var keys: Set<Defaults.Keys>
239+
@_DefaultsAtomic(value: []) private(set) var keys: Set<Defaults.Keys>
240240

241241
/**
242242
A thread-safe synchronization status monitor for `keys`.
243243
*/
244-
@Atomic(value: []) private var remoteSyncingKeys: Set<Defaults.Keys>
244+
@_DefaultsAtomic(value: []) private var remoteSyncingKeys: Set<Defaults.Keys>
245245

246246
// TODO: Replace it with async stream when Swift supports custom executors.
247247
private lazy var localKeysMonitor: Defaults.CompositeDefaultsObservation = .init { [weak self] pair, _ in

Sources/Defaults/Defaults.swift

+4-3
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ extension Defaults {
274274
_ key: Key<Value>,
275275
initial: Bool = true
276276
) -> AsyncStream<Value> { // TODO: Make this `some AsyncSequence<Value>` when targeting macOS 15.
277-
.init { continuation in
277+
AsyncStream { continuation in
278278
let observation = DefaultsObservation(object: key.suite, key: key.name) { _, change in
279279
// TODO: Use the `.deserialize` method directly.
280280
let value = KeyChange(change: change, defaultValue: key.defaultValue).newValue
@@ -306,11 +306,12 @@ extension Defaults {
306306
}
307307
```
308308
*/
309+
@_disfavoredOverload
309310
public static func updates<each Value: Serializable>(
310311
_ keys: repeat Key<each Value>,
311312
initial: Bool = true
312313
) -> AsyncStream<(repeat each Value)> {
313-
.init { continuation in
314+
AsyncStream { continuation in
314315
func getCurrentValues() -> (repeat each Value) {
315316
(repeat self[each keys])
316317
}
@@ -364,7 +365,7 @@ extension Defaults {
364365
_ keys: [_AnyKey],
365366
initial: Bool = true
366367
) -> AsyncStream<Void> { // TODO: Make this `some AsyncSequence<Void>` when targeting macOS 15.
367-
.init { continuation in
368+
AsyncStream { continuation in
368369
let observations = keys.indexed().map { index, key in
369370
let observation = DefaultsObservation(object: key.suite, key: key.name) { _, _ in
370371
continuation.yield()

Sources/Defaults/Observation.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ extension Defaults {
218218

219219
let key = preventPropagationThreadDictionaryKey
220220
let updatingValuesFlag = (Thread.current.threadDictionary[key] as? Bool) ?? false
221-
if updatingValuesFlag {
221+
guard !updatingValuesFlag else {
222222
return
223223
}
224224

Sources/Defaults/UserDefaults.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ extension UserDefaults {
99
return Value.toValue(anyObject)
1010
}
1111

12-
func _set<Value: Defaults.Serializable>(_ key: String, to value: Value) {
12+
func _set<Value: Defaults.Serializable>(_ key: String, to value: Value) {
1313
if (value as? (any _DefaultsOptionalProtocol))?._defaults_isNil == true {
1414
removeObject(forKey: key)
1515
return

Sources/Defaults/Utilities.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ final class TaskQueue {
381381

382382
// TODO: Replace with Swift 6 native Atomics support: https://github.com/apple/swift-evolution/blob/main/proposals/0258-property-wrappers.md?rgh-link-date=2024-03-29T14%3A14%3A00Z#changes-from-the-accepted-proposal
383383
@propertyWrapper
384-
final class Atomic<Value> {
384+
final class _DefaultsAtomic<Value> {
385385
private let lock: Lock = .make()
386386
private var _value: Value
387387

0 commit comments

Comments
 (0)