Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

Commit

Permalink
Ensure state is updated on MainActor (#20)
Browse files Browse the repository at this point in the history
* Run task on main actor

* No need for this
  • Loading branch information
reddavis authored May 3, 2022
1 parent 9be06fa commit 83e2a2b
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions RedUx/Source/ViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,15 @@ public final class ViewModel<State: Equatable, Event>: ObservableObject {
self.state = store.state
self._send = { store.send($0) }
self.stateTask = Task { [weak self] in
guard let self = self else { return }

do {
self?.state = store.state
await MainActor.run {
self.state = store.state
}

for try await state in store.stateSequence.removeDuplicates() {
guard
let self = self,
!Task.isCancelled else { break }
guard !Task.isCancelled else { break }

await MainActor.run {
self.state = state
Expand Down

0 comments on commit 83e2a2b

Please sign in to comment.