使用runblocking函数+async
``
import kotlinx.coroutines.*
fun nonSuspendFunction(): String {
return runBlocking {
val deferredResult = async {
// 调用 suspend 函数
suspendFunction()
}
deferredResult.await() // 等待结果
}
}
suspend fun suspendFunction(): String {
delay(1000) // 模拟耗时操作
return "Result from suspend function"
}
``