gpt4 book ai didi

android-studio - 如何在kotlin coroutine中显示 “@coroutine#2” ,“@coroutine#3” ,“@coroutine#1”?

转载 作者:行者123 更新时间:2023-12-02 13:16:24 27 4
gpt4 key购买 nike

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()}")
}
Kotlin 的文件

[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 42


我的Intellij IDEA和Android IDE

[main] I'm computing a piece of the answer [main] I'm computinganother piece of the answer [main] The answer is 42


如何显示“@ coroutine#2”,“@ coroutine#3”,“@ coroutine#1”?

最佳答案

打开运行/调试配置窗口,然后将-Dkotlinx.coroutines.debug添加到 VM选项中:
enter image description here
完成之后,您将获得以下输出:

[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 42

关于android-studio - 如何在kotlin coroutine中显示 “@coroutine#2” ,“@coroutine#3” ,“@coroutine#1”?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63752105/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com