diff --git a/Sources/AppState/Application/Types/State/Application+State.swift b/Sources/AppState/Application/Types/State/Application+State.swift index 68ee441..eab6779 100644 --- a/Sources/AppState/Application/Types/State/Application+State.swift +++ b/Sources/AppState/Application/Types/State/Application+State.swift @@ -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 }