https://kotlinlang.org logo
#stdlib
Title
# stdlib
d

Derek Peirce

10/23/2023, 7:18 PM
I'd like to see a
sleep(Duration)
method or even
Duration.sleep()
in Kotlin (similar to the
TimeUnit.sleep
method), instead of having to use
Thread.sleep(duration.inWholeMilliseconds)
. The less anyone has to make assumptions about the system's default time unit, the better.
j

Joffrey

10/23/2023, 7:22 PM
You can use a non-blocking
delay(duration)
instead from the coroutines library
d

Derek Peirce

10/23/2023, 7:25 PM
In my case, I'm not in a coroutine, so I'm unable to call
delay
directly.
k

kevin.cianfarini

10/23/2023, 7:27 PM
Write an extension function? I personally havent had the need to sleep threads directly since using coroutines so I feel the use case might be small
1
d

Derek Peirce

10/23/2023, 7:46 PM
I intend to add an extension method if I need it again (I just converted a Java file to Kotlin and did some
Duration
conversions, coming across the issue).