Simple coroutine that delays 1 second without blocking

suggest change

(from the official guide; CommonPool in that guide is now Dispatchers.Default)

import kotlinx.coroutines.*

fun main() = runBlocking {
    launch(Dispatchers.Default) { // was launch(CommonPool)
        delay(1000L) // non-blocking delay for 1 second (default time unit is ms)
        println("World!") // print after delay
    }
    println("Hello,") // main function continues while the coroutine is delayed
    delay(2000L) // suspend instead of blocking, long enough for World! to print
}

result

Hello,
World!

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents