Take the following two samples of code (taken from the Kotlin documentation and from the Coroutines library README respectively):
import kotlinx.coroutines.*
fun main() = runBlocking {
launch {
delay(2000)
println("World")
}
println("Hello")
}
In Kotlin >= 1.3.0 one can mark the main() function as suspendable and use a coroutineScope directly.
import kotlinx.coroutines.*
suspend fun main() = coroutineScope {
launch {
delay(2000)
println("World")
}
println("Hello")
}
Both produce the same output:
Hello
World
Are there any functional differences between the two approaches? If yes, what are they?