简体   繁体   English

如何在Kotlin Multiplatform(纯kotlin)中延迟

[英]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? 在纯Kotlin中是否有相当于JVM的Thread.sleep()用于MPP项目? This could be implemented on each platform using expected , but I am asking about a solution that does not use that method. 这可以在每个平台上使用expected ,但我问的是一个不使用该方法的解决方案。

This can be done using coroutines. 这可以使用协程来完成。

For example: 例如:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM