Coroutine - Kotlin

PHOTO EMBED

Wed Apr 07 2021 10:27:00 GMT+0000 (UTC)

Saved by @GoodRequest.

fun main() = runBlocking {
    println("main starts")
    joinAll(
        async { coroutine(1, 500L) },
        async { coroutine(2, 300L) }
    )
    println("main ends")
}

private suspend fun coroutine(number: Int, t: Long) {
    println("Routine $number starts to work")
    delay(t)
    println("Routine $number finished")
}
content_copyCOPY