Back to questions
JuniorTheoryCommon
What does the program print (lines separated by spaces)?
import kotlinx.coroutines.*
fun main() = runBlocking {
launch {
delay(100)
println("A")
}
println("B")
}B A
- Expecting
A B: thinkinglaunchruns its block to the end before moving on. It only starts the coroutine, andmainprintsBbefore the coroutine runs a single line. - Expecting only
B: thinking the program ends with the last line ofmain.runBlockingdoes not finish until every coroutine it started is done.
- What does the program print if
delay(100)is removed? - How would
join()makeAprint beforeB?