问题描述
是否有一种方法可以更改自定义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 (将#修改为@)