Kotlin Coroutines Sleep

July 24, 2020
delay

Use delay.

Delay is a special suspending function that does not block a thread, but suspends the coroutine, and it can be only used from a coroutine.

GlobalScope.launch {
    delay(1000L)
    println("Hello")
}

Thread.sleep is blocking.

Causes the currently executing thread to sleep (temporarily cease execution) for the specified number of milliseconds plus the specified number of nanoseconds, subject to the precision and accuracy of system timers and schedulers. The thread does not lose ownership of any monitors.

This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.