Created
June 1, 2024 17:50
-
-
Save robertmryan/3ac998cf72afda940aed0187f4ca37ec to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@discardableResult | |
public func send(_ action: Action) async throws -> State { | |
try Task.checkCancellation() | |
let effect = await reducer.reduce(into: &viewState, action: action) | |
if let nextAction = await effect.run() { | |
return try await send(nextAction) | |
} | |
return viewState | |
} | |
func testSend() async throws { | |
let state = try await store.send(.increment) | |
XCTAssertEqual(viewState.counter, 1) | |
} |
Note, I’ve removed the MainActor.run {…}
. If it needs to run on the main actor, isolate the Reducer
, itself, to the main actor:
@MainActor
final class Reducer { … }
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The idea is:
Task {…}
.testXxx
function anasync throws
function);@discardableResult
if you don’t need this functionality within your app; and