I have a for loop that consists of looping towards infinity and inside that for loop, there is a Thread.sleep(T)function, the sleeping time varies from 50ms to 1s. I know there are performance and user experience costs for using a sleep function inside a loop.
So what are the Kotlin alternatives ? (I found answers but all of them are in Java, I wanna know the best alternatives in Kotlin)
Thread.sleepblocks the thread its running on, which might be what you want. If you're on a UI/input processing thread, then it's almost certainly not what you want because it locks up the interface. Kotlin provides coroutines as an easy way to add delays to code execution without blocking a thread, but it's a huge topic to cover in an answer here.