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

廉价感情. 提交于 2020-12-30 09:37:04

问题


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.


回答1:


This can be done using coroutines.

For example:

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


来源:https://stackoverflow.com/questions/55223336/how-to-make-a-delay-in-kotlin-multiplatform-pure-kotlin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!