Kotlin Coroutines Sleep

Jul 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.

❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.