如何使CoroutineContext.Element不通过Kotlin中的启动/异步传播

问题描述

是否有一种方法可以更改自定义CoroutineContext.Element通过launchasync的传播方式,以满足下面的代码

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插件中,我想通过自定义ProgressIndicatorprogressScope并在ProgressElement(val pi: ProgressIndicator)中注入coroutineContext来与协程结婚。通过launchasync创建的作业,嵌套的progressScope对父项pushState使用popState / ProgressIndicator而不是创建新的父项。

到目前为止,我看到的唯一选择是用自定义生成器替换launchasync,但是我不确定是否能够在代码库中强制执行。

>

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)