Skip to content

Commit 5d174b9

Browse files
authored
Use Task MainActor to queue up set call (#118)
* Use Task MainActor to queue up set call * Revert back old code, but keep Task { @mainactor
1 parent 13b3481 commit 5d174b9

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

Sources/AppState/Application/Types/State/Application+State.swift

+21-8
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,27 @@ extension Application {
3434
)
3535
else {
3636
defer {
37-
shared.cache.set(
38-
value: Application.State(
39-
type: .state,
40-
initial: _value,
41-
scope: scope
42-
),
43-
forKey: scope.key
44-
)
37+
let setValue = {
38+
shared.cache.set(
39+
value: Application.State(
40+
type: .state,
41+
initial: _value,
42+
scope: scope
43+
),
44+
forKey: scope.key
45+
)
46+
}
47+
#if (!os(Linux) && !os(Windows))
48+
if NSClassFromString("XCTest") == nil {
49+
Task { @MainActor in
50+
setValue()
51+
}
52+
} else {
53+
setValue()
54+
}
55+
#else
56+
setValue()
57+
#endif
4558
}
4659
return _value
4760
}

0 commit comments

Comments
 (0)