diff --git a/Sources/ComposableArchitecture/Store.swift b/Sources/ComposableArchitecture/Store.swift index 9e15b0060418..4d60f5946f5a 100644 --- a/Sources/ComposableArchitecture/Store.swift +++ b/Sources/ComposableArchitecture/Store.swift @@ -1,4 +1,5 @@ import Combine +import CombineSchedulers import Foundation import SwiftUI @@ -375,7 +376,7 @@ public final class Store: _Store { public var publisher: StorePublisher { StorePublisher( store: self, - upstream: self.core.didSet.map { self.currentState } + upstream: self.core.didSet.receive(on: UIScheduler.shared).map { self.withState(\.self) } ) } diff --git a/Tests/ComposableArchitectureTests/StoreTests.swift b/Tests/ComposableArchitectureTests/StoreTests.swift index 3df6642aed52..efd15ed960c4 100644 --- a/Tests/ComposableArchitectureTests/StoreTests.swift +++ b/Tests/ComposableArchitectureTests/StoreTests.swift @@ -1175,6 +1175,14 @@ final class StoreTests: BaseTCATestCase { XCTAssertNil(weakStore) } + @MainActor + func testPublisherAsyncSequence() async { + if #available(iOS 15, macOS 12, tvOS 15, watchOS 8, *) { + let store = Store(initialState: ()) {} + _ = await store.publisher.values.first { @Sendable _ in true } + } + } + @MainActor func testSharedMutation() async { XCTTODO(