WukongRework.exe
01/26/2021, 7:17 AMimport kotlinx.coroutines.*
fun main() = runBlocking {
launch {
delay(100)
println("@ launch")
}
withContext(newSingleThreadContext("new Context")) {
delay(200)
println("@ withContext")
}
println("@ runBlocking")
}
// Outputs
@ launch
@ withContext
@ runBlocking
but
import kotlinx.coroutines.*
fun main() = runBlocking {
launch {
delay(100)
println("@ launch")
}
launch(newSingleThreadContext("new Context")) {
delay(200)
println("@ withContext")
}
println("@ runBlocking")
}
// Outputs
@ runBlocking
@ launch
@ withContext
could someone please explain this?Tijl
01/26/2021, 8:17 AMwithContext
as opposed to launch
andylamax
01/26/2021, 2:39 PMwithContext
suspends the coroutine until all of its children completes