Skip to content

Commit 0d433b9

Browse files
authored
Isolate override closures on main actor (#134)
1 parent 240aafd commit 0d433b9

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

Sources/Atoms/AtomRoot.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public struct AtomRoot<Content: View>: View {
128128
/// - value: A value to be used instead of the atom's value.
129129
///
130130
/// - Returns: The self instance.
131-
public func override<Node: Atom>(_ atom: Node, with value: @escaping @Sendable (Node) -> Node.Produced) -> Self {
131+
public func override<Node: Atom>(_ atom: Node, with value: @escaping @MainActor @Sendable (Node) -> Node.Produced) -> Self {
132132
mutating(self) { $0.overrides[OverrideKey(atom)] = Override(isScoped: false, getValue: value) }
133133
}
134134

@@ -144,7 +144,7 @@ public struct AtomRoot<Content: View>: View {
144144
/// - value: A value to be used instead of the atom's value.
145145
///
146146
/// - Returns: The self instance.
147-
public func override<Node: Atom>(_ atomType: Node.Type, with value: @escaping @Sendable (Node) -> Node.Produced) -> Self {
147+
public func override<Node: Atom>(_ atomType: Node.Type, with value: @escaping @MainActor @Sendable (Node) -> Node.Produced) -> Self {
148148
mutating(self) { $0.overrides[OverrideKey(atomType)] = Override(isScoped: false, getValue: value) }
149149
}
150150
}

Sources/Atoms/AtomScope.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public struct AtomScope<Content: View>: View {
129129
/// - value: A value to be used instead of the atom's value.
130130
///
131131
/// - Returns: The self instance.
132-
public func scopedOverride<Node: Atom>(_ atom: Node, with value: @escaping @Sendable (Node) -> Node.Produced) -> Self {
132+
public func scopedOverride<Node: Atom>(_ atom: Node, with value: @escaping @MainActor @Sendable (Node) -> Node.Produced) -> Self {
133133
mutating(self) { $0.overrides[OverrideKey(atom)] = Override(isScoped: true, getValue: value) }
134134
}
135135

@@ -147,7 +147,7 @@ public struct AtomScope<Content: View>: View {
147147
/// - value: A value to be used instead of the atom's value.
148148
///
149149
/// - Returns: The self instance.
150-
public func scopedOverride<Node: Atom>(_ atomType: Node.Type, with value: @escaping @Sendable (Node) -> Node.Produced) -> Self {
150+
public func scopedOverride<Node: Atom>(_ atomType: Node.Type, with value: @escaping @MainActor @Sendable (Node) -> Node.Produced) -> Self {
151151
mutating(self) { $0.overrides[OverrideKey(atomType)] = Override(isScoped: true, getValue: value) }
152152
}
153153
}

Sources/Atoms/Core/Override.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@ internal protocol OverrideProtocol: Sendable {
33
associatedtype Node: Atom
44

55
var isScoped: Bool { get }
6-
var getValue: @Sendable (Node) -> Node.Produced { get }
6+
var getValue: @MainActor @Sendable (Node) -> Node.Produced { get }
77
}
88

99
@usableFromInline
1010
internal struct Override<Node: Atom>: OverrideProtocol {
1111
@usableFromInline
1212
let isScoped: Bool
1313
@usableFromInline
14-
let getValue: @Sendable (Node) -> Node.Produced
14+
let getValue: @MainActor @Sendable (Node) -> Node.Produced
1515

1616
@usableFromInline
17-
init(isScoped: Bool, getValue: @escaping @Sendable (Node) -> Node.Produced) {
17+
init(isScoped: Bool, getValue: @escaping @MainActor @Sendable (Node) -> Node.Produced) {
1818
self.isScoped = isScoped
1919
self.getValue = getValue
2020
}

Sources/Atoms/Deprecated.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ public extension AtomScope {
5959
}
6060

6161
@available(*, deprecated, renamed: "scopedOverride(_:with:)")
62-
func override<Node: Atom>(_ atom: Node, with value: @escaping @Sendable (Node) -> Node.Produced) -> Self {
62+
func override<Node: Atom>(_ atom: Node, with value: @escaping @MainActor @Sendable (Node) -> Node.Produced) -> Self {
6363
scopedOverride(atom, with: value)
6464
}
6565

6666
@available(*, deprecated, renamed: "scopedOverride(_:with:)")
67-
func override<Node: Atom>(_ atomType: Node.Type, with value: @escaping @Sendable (Node) -> Node.Produced) -> Self {
67+
func override<Node: Atom>(_ atomType: Node.Type, with value: @escaping @MainActor @Sendable (Node) -> Node.Produced) -> Self {
6868
scopedOverride(atomType, with: value)
6969
}
7070
}

0 commit comments

Comments
 (0)