From 800209c4253918b541ea0363569683fd2f705065 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Fri, 29 Aug 2025 12:43:08 -0500 Subject: [PATCH 1/3] Allow store publisher to be used as async sequence. --- Sources/ComposableArchitecture/Store.swift | 3 ++- Tests/ComposableArchitectureTests/StoreTests.swift | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Sources/ComposableArchitecture/Store.swift b/Sources/ComposableArchitecture/Store.swift index 9e15b0060418..b16c179d13b8 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.currentState } ) } diff --git a/Tests/ComposableArchitectureTests/StoreTests.swift b/Tests/ComposableArchitectureTests/StoreTests.swift index 3df6642aed52..482dd72939ba 100644 --- a/Tests/ComposableArchitectureTests/StoreTests.swift +++ b/Tests/ComposableArchitectureTests/StoreTests.swift @@ -1175,6 +1175,12 @@ final class StoreTests: BaseTCATestCase { XCTAssertNil(weakStore) } + @MainActor + func testPublisherAsyncSequence() async { + let store = Store(initialState: ()) {} + _ = await store.publisher.values.first { @Sendable _ in true } + } + @MainActor func testSharedMutation() async { XCTTODO( From 0c88797ec7165af0889f21ed9dbd6f80e550697a Mon Sep 17 00:00:00 2001 From: Stephen Celis Date: Fri, 29 Aug 2025 11:01:18 -0700 Subject: [PATCH 2/3] Update StoreTests.swift --- Tests/ComposableArchitectureTests/StoreTests.swift | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Tests/ComposableArchitectureTests/StoreTests.swift b/Tests/ComposableArchitectureTests/StoreTests.swift index 482dd72939ba..efd15ed960c4 100644 --- a/Tests/ComposableArchitectureTests/StoreTests.swift +++ b/Tests/ComposableArchitectureTests/StoreTests.swift @@ -1177,8 +1177,10 @@ final class StoreTests: BaseTCATestCase { @MainActor func testPublisherAsyncSequence() async { - let store = Store(initialState: ()) {} - _ = await store.publisher.values.first { @Sendable _ in true } + if #available(iOS 15, macOS 12, tvOS 15, watchOS 8, *) { + let store = Store(initialState: ()) {} + _ = await store.publisher.values.first { @Sendable _ in true } + } } @MainActor From 004dcbd4104af6cff4d6fc5e4b71eb36e346631c Mon Sep 17 00:00:00 2001 From: Stephen Celis Date: Fri, 29 Aug 2025 11:03:43 -0700 Subject: [PATCH 3/3] Update publisher to use withState for currentState --- Sources/ComposableArchitecture/Store.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/ComposableArchitecture/Store.swift b/Sources/ComposableArchitecture/Store.swift index b16c179d13b8..4d60f5946f5a 100644 --- a/Sources/ComposableArchitecture/Store.swift +++ b/Sources/ComposableArchitecture/Store.swift @@ -376,7 +376,7 @@ public final class Store: _Store { public var publisher: StorePublisher { StorePublisher( store: self, - upstream: self.core.didSet.receive(on: UIScheduler.shared).map { self.currentState } + upstream: self.core.didSet.receive(on: UIScheduler.shared).map { self.withState(\.self) } ) }