android - 如何在 Kotlin 中获取协程的名称?
问题描述
我很好奇协程suspended
在主线程上的内部工作。真正的问题是如何suspended
在主线程上记录一个协程函数。执行的具体地点在哪里?是虚拟线程吗?
解决方案
如果您正在谈论记录协程名称:
你可以通过
给协程命名(如果你想要自定义名称):
launch(CoroutineName("My-Coroutine"))
在 IntelliJ 工具栏菜单中启用日志记录:运行 -> 编辑配置并添加
-Dkotlinx.coroutines.debug
在虚拟机选项中。
然后你可以@My-Coroutine
在logcat中看到。
在编辑配置更改后尝试以下代码:
fun main() = runBlocking {
println(" 'runBlocking': I'm working in thread ${Thread.currentThread().name}")
val job = launch(CoroutineName("my-custom-name")) {
println(" 'runBlocking': I'm working in thread ${Thread.currentThread().name}")
}
job.join()}
推荐阅读
- r - R中ROSE的过采样和欠采样问题
- python - 这段python字典代码有什么问题?
- macos - 导出 DYLD_LIBRARY_PATH 导致 libncurses.5.4.dylib 未加载错误
- windows - wWinMain 控件 nCmdShow
- couchbase - 不清楚的错误,无效的功能搜索。- 在 )
- reactjs - 在反应类组件方法中等待完成 redux-saga
- python - 插入变量作为熊猫 iloc 函数参数
- angular - dist 文件夹的正确路径
- visual-studio - Visual Studio:在生成后事件中继续生成错误的解决方案
- angular - 如何根据角度下拉列表中的多个选定值动态添加输入字段