Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
fun main() {
runBlocking {
val coroutineX = GlobalScope.launch {
val result1 = n1(5)
println("Hello I'll print after n1 is over")
println("Result1: $result1")
val result2 = n2(5)
println("Hello I'll print after n2 is over")
println("Result2: $result2")
suspend fun n1(a: Int): Int {
return a
suspend fun n2(a: Int): Int {
val coroutineY = GlobalScope.async (Dispatchers.IO) {
// same as Thread.sleep() but for coroutines
return@async a*a
return coroutineY.await()
Hello I'll print after n1 is over
Result1: 5
Hello I'll print after n2 is over
Result2: 25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment