viluon
05/19/2025, 8:07 AMflowOn
obviously doesn't help: not only is it happening outside of a collection (so it doesn't see flow items), it affects the upstream, not downstream.
I'm aware that one can use `channelFlow`s to switch context arbitrarily. However, this (to the best of my knowledge) doesn't affect downstream flows: there's a channel in-between that separates them.
TL;DR: how do I make the flow element part of the downstream coroutine context (to propagate it through the chain of emissions) while preserving flow requirements? Is it even possible?Dmitry Khalanskiy [JB]
05/19/2025, 8:16 AMobject DirectDispatcher : CoroutineDispatcher() {
override fun dispatch(context: CoroutineContext, block: Runnable) {
block.run()
}
}
Then, all collection code will run in-place from the publisher. This is not idiomatic kotlinx.coroutines
code, but it does recreate RxJava's approach to threading.viluon
05/19/2025, 10:14 AMDmitry Khalanskiy [JB]
05/19/2025, 10:16 AMFlow
. The consumer of Flow
is intentionally isolated from the context of the producer, that's by design.viluon
05/19/2025, 10:32 AM