-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Fail-fast when trying to do runBlocking
from Android UI thread
#227
Comments
Can I request this apply to JavaFX also? |
It indeed makes sense for all UI dispatchers. |
@elizarov is this up for grabs? I'd be interested in working on this |
@deva666 You can try to work out solution. I have not though too deep about possible implementation strategies, so I don't know if it will turn out to be simple or not. |
I have to say I like the Idea. But why only forbid And actually, even if I like very much the Idea I have some fears about our usage. In our codebase we are slowly adding coroutines and improving our code base to block as less often as possible. But we have to live with an existing code base which has legacy code blocking the UI (without using coroutine). And problems arise when we convert some code or add new code using coroutines. Even if we try as much as possible to make the code not blocking the UI anymore, it is sometime to much work and we simply put the suspending code in But if kotlinx.coroutines sudently start to throw exceptions when we use |
@jcornaz You raised an important issue, thank you In general, blocking UI thread is a no go, so we prefer to have this check enabled by default. |
Yes I thought about that too. It would be great. |
Shall we open a separate issue for a property, since this issue already sits on the release train and will be closed soon? |
I have a bit of coroutine code that needs to be run in a blocking fashion when my Android application starts. For instance in my How do I solve this use case now? |
Let's discuss a solution in #464 |
Android UI thread does not generally allow blocking operations and vaiours things like doing network IO from UI thread throws an exception on Android. Similarly, using
runBlocking
from Android UI thread shall throw an exception to fail-fast and prevent hard-to-diagnose bugs when the code just "happens to run fast" during testing but can in fact hang the UI in production.The text was updated successfully, but these errors were encountered: