Could there be any reason why the code in `launch(...
# coroutines
d
Could there be any reason why the code in
launch(UI)
is not reached at all after it was run? And the screen in Android device goes black... I tried putting logs there, reducing it to doing almost nothing (only
Log
...)... the screen just blanks out
m
Can you try just post task to handler with main looper in launch body? It works? Without UI context.
g
yeah this, this is a teachabl emoment, IMHO the use for
runBlocking
is almost exclusively for `@Test fun`'s.
d
Yea, even when teaching other programmers in the company... the 'easy way out' ends up getting abused... 🤕
e
Shall we failfast? I.e. immediately throw an exception when
runBlocking
is invoked from Android UI thread?
d
@elizarov Probably a good idea, as long as there's a stack trace to nail down where it failed from, but... When migrating from java to kotlin and coroutines (which was our case...).
runBlocking
could be temporarily used to surround some suspending operation that will for sure return quickly in certain circumstances (like api that will for sure be pulling a value from a cache at certain points). In that case, maybe a compiler warning might be warrented instead of failfast, as a reminder to not keep the code that way... That was the devs mistake, an operation that was migrated took too long... and making major changes to adapt to coroutines best practices all in one shot was trying to be avoided at that point... Maybe opt-out failfast, with warning option?
e
I’m not sure how to make it that flexible.
d
I guess the default behaviour could be failfast, but there could maybe be an extra unsafe param to runBlocking or UnsafeUI context for the warning @elizarov? If this seems all to complex for such a use case, at least a compiler (or runtime) warning or IDE hint would be great...