import kotlinx.coroutines.*
fun log(msg: String) = println("[${Thread.currentThread().name}] $msg")
fun main() = runBlocking<Unit> {
val a = async {
log("I'm computing a piece of the answer")
6
}
val b = async {
log("I'm computing another piece of the answer")
7
}
log("The answer is ${a.await() * b.await()}")
}科特林文献
主@coroutine#2我正在计算答案的一部分主@coroutine#3我正在计算答案的另一部分主@coroutine#1答案是42
Intellij IDEA和Android的IDE
我正在计算一个答案主,我正在计算另一个答案主,答案是42
如何显示"@coroutine#2“、"@coroutine#3”、“@coroutine#1”?
发布于 2020-09-05 10:04:20
打开运行/调试配置窗口,并将-Dkotlinx.coroutines.debug添加到VM选项中

这样做之后,您将得到以下输出:
[main @coroutine#2] I'm computing a piece of the answer
[main @coroutine#3] I'm computing another piece of the answer
[main @coroutine#1] : The answer is 42https://stackoverflow.com/questions/63752105
复制相似问题