Skip to content

Commit acd9bb8

Browse files
Allow store publisher to be used as async sequence. (#3763)
* Allow store publisher to be used as async sequence. * Update StoreTests.swift * Update publisher to use withState for currentState --------- Co-authored-by: Stephen Celis <[email protected]>
1 parent 4429f7b commit acd9bb8

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-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.withState(\.self) }
379380
)
380381
}
381382

Tests/ComposableArchitectureTests/StoreTests.swift

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

1178+
@MainActor
1179+
func testPublisherAsyncSequence() async {
1180+
if #available(iOS 15, macOS 12, tvOS 15, watchOS 8, *) {
1181+
let store = Store<Void, Void>(initialState: ()) {}
1182+
_ = await store.publisher.values.first { @Sendable _ in true }
1183+
}
1184+
}
1185+
11781186
@MainActor
11791187
func testSharedMutation() async {
11801188
XCTTODO(

0 commit comments

Comments
 (0)