Skip to content

Commit

Permalink
Minor tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Feb 22, 2025
1 parent 6740756 commit cc938ec
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Sources/Defaults/Defaults+iCloud.swift
Original file line number Diff line number Diff line change
Expand Up @@ -236,12 +236,12 @@ final class iCloudSynchronizer {
/**
A thread-safe `keys` that manage the keys to be synced.
*/
@Atomic(value: []) private(set) var keys: Set<Defaults.Keys>
@_DefaultsAtomic(value: []) private(set) var keys: Set<Defaults.Keys>

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

// TODO: Replace it with async stream when Swift supports custom executors.
private lazy var localKeysMonitor: Defaults.CompositeDefaultsObservation = .init { [weak self] pair, _ in
Expand Down
7 changes: 4 additions & 3 deletions Sources/Defaults/Defaults.swift
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ extension Defaults {
_ key: Key<Value>,
initial: Bool = true
) -> AsyncStream<Value> { // TODO: Make this `some AsyncSequence<Value>` when targeting macOS 15.
.init { continuation in
AsyncStream { continuation in
let observation = DefaultsObservation(object: key.suite, key: key.name) { _, change in
// TODO: Use the `.deserialize` method directly.
let value = KeyChange(change: change, defaultValue: key.defaultValue).newValue
Expand Down Expand Up @@ -306,11 +306,12 @@ extension Defaults {
}
```
*/
@_disfavoredOverload
public static func updates<each Value: Serializable>(
_ keys: repeat Key<each Value>,
initial: Bool = true
) -> AsyncStream<(repeat each Value)> {
.init { continuation in
AsyncStream { continuation in
func getCurrentValues() -> (repeat each Value) {
(repeat self[each keys])
}
Expand Down Expand Up @@ -364,7 +365,7 @@ extension Defaults {
_ keys: [_AnyKey],
initial: Bool = true
) -> AsyncStream<Void> { // TODO: Make this `some AsyncSequence<Void>` when targeting macOS 15.
.init { continuation in
AsyncStream { continuation in
let observations = keys.indexed().map { index, key in
let observation = DefaultsObservation(object: key.suite, key: key.name) { _, _ in
continuation.yield()
Expand Down
2 changes: 1 addition & 1 deletion Sources/Defaults/Observation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ extension Defaults {

let key = preventPropagationThreadDictionaryKey
let updatingValuesFlag = (Thread.current.threadDictionary[key] as? Bool) ?? false
if updatingValuesFlag {
guard !updatingValuesFlag else {
return
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/Defaults/UserDefaults.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ extension UserDefaults {
return Value.toValue(anyObject)
}

func _set<Value: Defaults.Serializable>(_ key: String, to value: Value) {
func _set<Value: Defaults.Serializable>(_ key: String, to value: Value) {
if (value as? (any _DefaultsOptionalProtocol))?._defaults_isNil == true {
removeObject(forKey: key)
return
Expand Down
2 changes: 1 addition & 1 deletion Sources/Defaults/Utilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ final class TaskQueue {

// 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
@propertyWrapper
final class Atomic<Value> {
final class _DefaultsAtomic<Value> {
private let lock: Lock = .make()
private var _value: Value

Expand Down

0 comments on commit cc938ec

Please sign in to comment.