如何解决如何使CoroutineContext.Element不通过Kotlin中的启动/异步传播
是否有一种方法可以更改自定义CoroutineContext.Element
通过launch
和async
的传播方式,以满足下面的代码?
suspend fun CoroutingScope.foo(): Foo? = TODO()
fun test() = runBlocking {
withContext(FooElement(foo1)) {
assertSame(foo1,foo())
coroutineScope {
assertSame(foo1,foo())
}
launch {
assertNull(foo())
}
async {
assertNull(foo())
}
}
}
在我的IntelliJ插件中,我想通过自定义ProgressIndicator
和progressScope
并在ProgressElement(val pi: ProgressIndicator)
中注入coroutineContext
来与协程结婚。通过launch
或async
创建的作业,嵌套的progressScope
对父项pushState
使用popState
/ ProgressIndicator
而不是创建新的父项。
到目前为止,我看到的唯一选择是用自定义生成器替换launch
和async
,但是我不确定是否能够在代码库中强制执行。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。