Erik
09/10/2020, 5:41 PMsuspend fun main()
for the first time. Where is it documented? How does it work?wasyl
09/10/2020, 6:13 PMfun main(args: Array<String>) = runBlocking { ... }
Zach Klippenstein (he/him) [MOD]
09/10/2020, 6:49 PMsuspend fun main
uses the Default dispatcherErik
09/10/2020, 6:50 PMrunBlocking
under the hood. As this is a suspend fun
I'm blind to the coroutine scope and context, right? So it's not within my power to know and control whether or not my coroutines run blocking or are backed by many threads?Zach Klippenstein (he/him) [MOD]
09/10/2020, 6:55 PMwithContext
to be explicit about that anyway though.Erik
09/10/2020, 6:57 PMrunBlocking
that way? 😎 I'll have to try that some time soonErik
09/10/2020, 6:58 PMGlobalSope.launch
Zach Klippenstein (he/him) [MOD]
09/10/2020, 7:07 PMSo I can escape the synchrony of runBlocking that way?Not really. Regardless of which dispatchers your coroutines are running on,
main
has to block at some point or your program will just exit immediately without running any coroutines.wasyl
09/10/2020, 7:28 PM// signature ([Ljava/lang/String;Lkotlin/coroutines/Continuation<-Lkotlin/Unit;>;)Ljava/lang/Object;
// declaration: main(java.lang.String[], kotlin.coroutines.Continuation<? super kotlin.Unit>)
public final static main([Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
Then there’s synthetic method:
// $FF: synthetic method
public static void main(String[] var0) {
RunSuspendKt.runSuspend(new AppKt$$$main(var0));
}
And the RunSuspend
class uses empty coroutine context:
private class RunSuspend : Continuation<Unit> {
override val context: CoroutineContext
get() = EmptyCoroutineContext
gildor
09/10/2020, 11:45 PM