https://kotlinlang.org logo
#coroutines
Title
# coroutines
d

dave08

02/05/2018, 4:36 PM
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

mansonheart

02/05/2018, 4:49 PM
Can you try just post task to handler with main looper in launch body? It works? Without UI context.
g

groostav

02/06/2018, 12:43 AM
yeah this, this is a teachabl emoment, IMHO the use for
runBlocking
is almost exclusively for `@Test fun`'s.
d

dave08

02/06/2018, 3:40 AM
Yea, even when teaching other programmers in the company... the 'easy way out' ends up getting abused... 🤕
e

elizarov

02/06/2018, 8:32 AM
Shall we failfast? I.e. immediately throw an exception when
runBlocking
is invoked from Android UI thread?
d

dave08

02/06/2018, 9:21 AM
@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

elizarov

02/06/2018, 9:26 AM
I’m not sure how to make it that flexible.
d

dave08

02/06/2018, 10:45 AM
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...
5 Views