Use default dispatcher for phoenix-shared coroutine scopes#780
Merged
Conversation
This replaces MainScope which uses the UI dispatcher.
robbiehanson
approved these changes
Nov 10, 2025
Contributor
robbiehanson
left a comment
There was a problem hiding this comment.
Looks good. And the iOS app feels more responsive now.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
We've been used the
MainScopeuntil now for all our coroutines, a scope that relies on the UI dispatcher. This is not suited for many of the phoenix-shared coroutines which are doing background stuff and should not run on the UI thread. I believe it was done this way for historical reasons, back when kotlin multiplatform had issues with background operations on iOS, but that was fixed when we adopted the new memory model (see #299).This PR defines a
defaultScopemethod that uses the predefinedDefaultdispatcher:There's also a
Dispatcher.IOdispatcher that could be used for coroutines doing I/O operations.Note: we've been already using
Dispatchers.Defaultfor database queries, but we did that by explicitly switching context withwithContext. @robbiehanson I think that this PR could allow us to remove those switches and simplify code (and also ensure we're not doing db stuff on the Main thread).