IntermediateCoroutines
coroutineScope
Wait for child coroutines with coroutineScope.
Dependency required:
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.9.0")kotlin
import kotlinx.coroutines.*
fun main() = runBlocking {
coroutineScope {
launch { delay(100); println("A") }
launch { delay(50); println("B") }
}
println("Done")
}Output
B
A
Done
Explanation
coroutineScope waits for all children before continuing to Done.