Skip to content

Commit fee95ed

Browse files
committed
Format
1 parent 9712d1c commit fee95ed

File tree

2 files changed

+58
-58
lines changed

2 files changed

+58
-58
lines changed

Sources/Atoms/Core/SubscriberState.swift

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,45 +4,45 @@ import Foundation
44
internal final class SubscriberState {
55
let token = SubscriberKey.Token()
66

7-
#if compiler(>=6)
8-
nonisolated(unsafe) var subscribing = Set<AtomKey>()
9-
nonisolated(unsafe) var unsubscribe: ((Set<AtomKey>) -> Void)?
7+
#if compiler(>=6)
8+
nonisolated(unsafe) var subscribing = Set<AtomKey>()
9+
nonisolated(unsafe) var unsubscribe: ((Set<AtomKey>) -> Void)?
1010

11-
// TODO: Use isolated synchronous deinit once it's available.
12-
// 0371-isolated-synchronous-deinit
13-
deinit {
14-
if Thread.isMainThread {
15-
unsubscribe?(subscribing)
16-
}
17-
else {
18-
Task { @MainActor [unsubscribe, subscribing] in
11+
// TODO: Use isolated synchronous deinit once it's available.
12+
// 0371-isolated-synchronous-deinit
13+
deinit {
14+
if Thread.isMainThread {
1915
unsubscribe?(subscribing)
2016
}
17+
else {
18+
Task { @MainActor [unsubscribe, subscribing] in
19+
unsubscribe?(subscribing)
20+
}
21+
}
2122
}
22-
}
23-
#else
24-
private var _subscribing = UnsafeUncheckedSendable(Set<AtomKey>())
25-
private var _unsubscribe = UnsafeUncheckedSendable<((Set<AtomKey>) -> Void)?>(nil)
26-
27-
var subscribing: Set<AtomKey> {
28-
_read { yield _subscribing.value }
29-
_modify { yield &_subscribing.value }
30-
}
23+
#else
24+
private var _subscribing = UnsafeUncheckedSendable(Set<AtomKey>())
25+
private var _unsubscribe = UnsafeUncheckedSendable<((Set<AtomKey>) -> Void)?>(nil)
3126

32-
var unsubscribe: ((Set<AtomKey>) -> Void)? {
33-
_read { yield _unsubscribe.value }
34-
_modify { yield &_unsubscribe.value }
35-
}
27+
var subscribing: Set<AtomKey> {
28+
_read { yield _subscribing.value }
29+
_modify { yield &_subscribing.value }
30+
}
3631

37-
deinit {
38-
if Thread.isMainThread {
39-
_unsubscribe.value?(_subscribing.value)
32+
var unsubscribe: ((Set<AtomKey>) -> Void)? {
33+
_read { yield _unsubscribe.value }
34+
_modify { yield &_unsubscribe.value }
4035
}
41-
else {
42-
Task { @MainActor [_unsubscribe, _subscribing] in
36+
37+
deinit {
38+
if Thread.isMainThread {
4339
_unsubscribe.value?(_subscribing.value)
4440
}
41+
else {
42+
Task { @MainActor [_unsubscribe, _subscribing] in
43+
_unsubscribe.value?(_subscribing.value)
44+
}
45+
}
4546
}
46-
}
47-
#endif
47+
#endif
4848
}

Sources/Atoms/Modifier/ChangesOfModifier.swift

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,19 @@ public extension Atom {
2222
/// - Parameter keyPath: A key path for the property of the original atom value.
2323
///
2424
/// - Returns: An atom that provides the partial property of the original atom value.
25-
#if hasFeature(InferSendableFromCaptures)
26-
func changes<T: Equatable>(
27-
of keyPath: KeyPath<Produced, T> & Sendable
28-
) -> ModifiedAtom<Self, ChangesOfModifier<Produced, T>> {
29-
modifier(ChangesOfModifier(keyPath: keyPath))
30-
}
31-
#else
32-
func changes<T: Equatable>(
33-
of keyPath: KeyPath<Produced, T>
34-
) -> ModifiedAtom<Self, ChangesOfModifier<Produced, T>> {
35-
modifier(ChangesOfModifier(keyPath: keyPath))
36-
}
37-
#endif
25+
#if hasFeature(InferSendableFromCaptures)
26+
func changes<T: Equatable>(
27+
of keyPath: KeyPath<Produced, T> & Sendable
28+
) -> ModifiedAtom<Self, ChangesOfModifier<Produced, T>> {
29+
modifier(ChangesOfModifier(keyPath: keyPath))
30+
}
31+
#else
32+
func changes<T: Equatable>(
33+
of keyPath: KeyPath<Produced, T>
34+
) -> ModifiedAtom<Self, ChangesOfModifier<Produced, T>> {
35+
modifier(ChangesOfModifier(keyPath: keyPath))
36+
}
37+
#endif
3838
}
3939

4040
/// A modifier that derives a partial property with the specified key path from the original atom
@@ -57,22 +57,22 @@ public struct ChangesOfModifier<Base, Produced: Equatable>: AtomModifier {
5757
}
5858
}
5959

60-
#if hasFeature(InferSendableFromCaptures)
61-
private let keyPath: KeyPath<Base, Produced> & Sendable
60+
#if hasFeature(InferSendableFromCaptures)
61+
private let keyPath: KeyPath<Base, Produced> & Sendable
6262

63-
internal init(keyPath: KeyPath<Base, Produced> & Sendable) {
64-
self.keyPath = keyPath
65-
}
66-
#else
67-
private let _keyPath: UnsafeUncheckedSendable<KeyPath<Base, Produced>>
68-
private var keyPath: KeyPath<Base, Produced> {
69-
_keyPath.value
70-
}
63+
internal init(keyPath: KeyPath<Base, Produced> & Sendable) {
64+
self.keyPath = keyPath
65+
}
66+
#else
67+
private let _keyPath: UnsafeUncheckedSendable<KeyPath<Base, Produced>>
68+
private var keyPath: KeyPath<Base, Produced> {
69+
_keyPath.value
70+
}
7171

72-
internal init(keyPath: KeyPath<Base, Produced>) {
73-
_keyPath = UnsafeUncheckedSendable(keyPath)
74-
}
75-
#endif
72+
internal init(keyPath: KeyPath<Base, Produced>) {
73+
_keyPath = UnsafeUncheckedSendable(keyPath)
74+
}
75+
#endif
7676

7777
/// A unique value used to identify the modifier internally.
7878
public var key: Key {

0 commit comments

Comments
 (0)