Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Background thread publishing changes when using RouteSteps #27

Closed
utahwithak opened this issue May 23, 2022 · 4 comments
Closed

Background thread publishing changes when using RouteSteps #27

utahwithak opened this issue May 23, 2022 · 4 comments

Comments

@utahwithak
Copy link

This issue doesn't appear to happen when using the binding modifiers. I'm not sure why. But when using:

        RouteSteps.withDelaysIfUnsupported(self, \.routes) {
            $0.goBackToRoot()
        }

if there are more than one steps it will print out the following:

FlowStacksApp[55359:4275326] [SwiftUI] Publishing changes from background threads is not allowed; make sure to publish values from the main thread (via operators like receive(on:)) on model updates.

It appears that inside scheduleRemainingSteps when it does a Task.sleep when it comes back it will no longer be on the main thread and all remaining operations will execute on a random background thread pool thread.

Marking scheduleRemainingSteps as @MainActor solves this issue, though may have other implications.

This was tested on iOS 15 and 15.5 on simulators. Same thread changing behavior can be seen with a playground as well,

@DavidKmn
Copy link
Contributor

Good catch, yes annotating the scheduleRemainingSteps to run on the main actor would be the correct solution. Will submit a PR shortly and attach to the thread.

@DavidKmn
Copy link
Contributor

PR created #28

@johnpatrickmorgan
Copy link
Owner

Thanks @utahwithak for raising this issue and @DavidKmn for the quick fix!

@johnpatrickmorgan
Copy link
Owner

Merged and released in V0.2.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants