Search code examples
kotlinkotlin-multiplatform

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.


Solution

  • This can be done using coroutines.

    For example:

    runBlocking {
        println("Wait for 5sec")
        delay(5000)
        println("Done waiting for 5sec")
    }