Skip to content

Commit

Permalink
Use Task MainActor to queue up set call (#118)
Browse files Browse the repository at this point in the history
* Use Task MainActor to queue up set call

* Revert back old code, but keep Task { @mainactor
  • Loading branch information
0xLeif authored Oct 25, 2024
1 parent 13b3481 commit 5d174b9
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions Sources/AppState/Application/Types/State/Application+State.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,27 @@ extension Application {
)
else {
defer {
shared.cache.set(
value: Application.State(
type: .state,
initial: _value,
scope: scope
),
forKey: scope.key
)
let setValue = {
shared.cache.set(
value: Application.State(
type: .state,
initial: _value,
scope: scope
),
forKey: scope.key
)
}
#if (!os(Linux) && !os(Windows))
if NSClassFromString("XCTest") == nil {
Task { @MainActor in
setValue()
}
} else {
setValue()
}
#else
setValue()
#endif
}
return _value
}
Expand Down

0 comments on commit 5d174b9

Please sign in to comment.