In this official documentation, it says that coroutineScope just suspends, releasing the underlying thread for other usages.
But in example code, it looks it blocks the next process because println("Coroutine scope is over") is not executed until finishing the code block in coroutineScope.
import kotlinx.coroutines.*
fun main() = runBlocking { // this: CoroutineScope
launch {
delay(200L)
println("Task from runBlocking")
}
coroutineScope { // Creates a coroutine scope
launch {
delay(500L)
println("Task from nested launch")
}
delay(100L)
println("Task from coroutine scope") // This line will be printed before the nested launch
}
println("Coroutine scope is over") // This line is not printed until the nested launch completes
}
I know runBlocking waits until all its children to complete. So in my understanding, runBlocking should wait for coroutineScope to complete after executing println("Coroutine scope is over") line.
Why does coroutineScope block the thread in this example?