suspend 函数内部的 runBlocking 调用。
在 suspend 函数中使用 runBlocking 会阻塞调用线程,违背异步编程的目的。
该快速修复可以将 runBlocking 调用替换为以下备选项之一,具体取决于上下文:
run 调用。CoroutineContext 时的 withContext 调用。runBlocking 包装器的直接内联代码。示例:
suspend fun something() {
runBlocking {
code() // 线程在此处被阻塞
}
}
在应用快速修复后:
suspend fun something() {
code() // 异步运行
}
2025.1 的新功能