mayojava
10/12/2018, 9:52 AMfun main(args: Array<String>) = runBlocking { // this: CoroutineScope
launch {
delay(200L)
println("Task from runBlocking")
}
coroutineScope { // Creates a new coroutine scope
launch {
delay(500L)
println("Task from nested launch")
}
delay(100L)
println("Task from coroutine scope") // This line will be printed before nested launch
}
println("Coroutine scope is over") // This line is not printed until nested launch completes
}
elizarov
10/12/2018, 10:05 AMcoroutineScope { ... }
to complete, but the thread is not blocked and can do other activities (you can verify that by launching yet another coroutine at the top that prints a dot every 10ms).dave08
10/12/2018, 11:22 AMjoin()
, wouldn't main exit while the children are still running?mayojava
10/12/2018, 12:55 PMdave08
10/13/2018, 8:23 PM