Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a delay in Kotlin Multiplatform (pure kotlin)

Is there an equivalent to JVM's Thread.sleep() in pure Kotlin for use on MPP projects? This could be implemented on each platform using expected, but I am asking about a solution that does not use that method.

like image 634
Patrick Avatar asked Mar 18 '19 14:03

Patrick


1 Answers

This can be done using coroutines.

For example:

runBlocking {
    println("Wait for 5sec")
    delay(5000)
    println("Done waiting for 5sec")
}
like image 109
Alexander Egger Avatar answered Oct 04 '22 07:10

Alexander Egger