不确定内部流动在什么上下文
我对内部流产生的上下文
考虑以下代码有一个疑问。
withContext(Dispatchers.Main)
{
val flowA = flowOf(1,2,3,4)
val flowB = flowOf("a","b","c")
flowA.flatMapConcat { num->
val bResponse = flowB.first() //would this operate on Dispatchers.Main OR IO
flowOf(bResponse)
}.flowOn(Dispatchers.IO)
}
}
我有一个嵌套流,我不确定Flowb.first()终端操作员会在什么上下文上操作?
I have a question about the context in which an inner flow produces
Consider the following code.
withContext(Dispatchers.Main)
{
val flowA = flowOf(1,2,3,4)
val flowB = flowOf("a","b","c")
flowA.flatMapConcat { num->
val bResponse = flowB.first() //would this operate on Dispatchers.Main OR IO
flowOf(bResponse)
}.flowOn(Dispatchers.IO)
}
}
I have a nested flow and I am unsure on what context would the flowB.first() terminal operator operate on ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如您所见文档,
由于
val breasponse = flowb.first()
在flowa
内部执行,因此其上下文将其上下文更改为dispatchers.io
flow> flow < /代码>操作员。As you can see in the documentation,
Since
val bResponse = flowB.first()
is executed insideflowA
, its context is changed toDispatchers.IO
by theflowOn
operator.