首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何显示"@coroutine#2","@coroutine#3","@coroutine#1“?

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

Stack Overflow用户
提问于 2020-09-05 08:51:07
回答 1查看 443关注 0票数 1
代码语言:javascript
复制
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”?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-09-05 10:04:20

打开运行/调试配置窗口,并将-Dkotlinx.coroutines.debug添加到VM选项

这样做之后,您将得到以下输出:

代码语言:javascript
复制
[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
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63752105

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档