What is the difference between runBlocking and coroutineScope in Kotlin Coroutines?
Hello, colleagues! I started learning coroutines in Kotlin and came across two functions that seem very similar to me: runBlocking and coroutineScope. I read the documentation, but their behavior is still not obvious to me.
Here is an example I wrote:
fun main() = runBlocking {
launch {
delay(1000L)
println("World!")
}
println("Hello,")
}
And another one:
fun main() = runBlocking {
coroutineScope {
launch {
delay(1000L)
println("World!")
}
println("Hello,")
}
}
Both examples print "Hello," first, and then "World!" after a second. But I suspect there is a difference, and it is important. What is it?
No answers yet.
Log in to leave an answer