Skip to content

Commit 800209c

Browse files
committed
Allow store publisher to be used as async sequence.
1 parent 5638930 commit 800209c

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

Sources/ComposableArchitecture/Store.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Combine
2+
import CombineSchedulers
23
import Foundation
34
import SwiftUI
45

@@ -375,7 +376,7 @@ public final class Store<State, Action>: _Store {
375376
public var publisher: StorePublisher<State> {
376377
StorePublisher(
377378
store: self,
378-
upstream: self.core.didSet.map { self.currentState }
379+
upstream: self.core.didSet.receive(on: UIScheduler.shared).map { self.currentState }
379380
)
380381
}
381382

Tests/ComposableArchitectureTests/StoreTests.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,6 +1175,12 @@ final class StoreTests: BaseTCATestCase {
11751175
XCTAssertNil(weakStore)
11761176
}
11771177

1178+
@MainActor
1179+
func testPublisherAsyncSequence() async {
1180+
let store = Store<Void, Void>(initialState: ()) {}
1181+
_ = await store.publisher.values.first { @Sendable _ in true }
1182+
}
1183+
11781184
@MainActor
11791185
func testSharedMutation() async {
11801186
XCTTODO(

0 commit comments

Comments
 (0)