PublisherAsFlow ignores the CoroutineContext, so t...
# coroutines
b
PublisherAsFlow ignores the CoroutineContext, so that it make no sense to call flowOn on it. Is it a bug? I have opened an issue for this: https://github.com/Kotlin/kotlinx.coroutines/issues/1765
b
That's because flows inherit the scope for its operators based on the context that the
collect
is called from. A publisher should already have it's schedulers registered before it's adapted to a Flow. If you don't have any schedulers on your Publisher, your
flowOn
operator will set the context that the
collect
is executed against
b
The
flowOn
operator will not set the context, that's the problem.
b
I see now. In the implementation, it looks like they are explicitly abstracting the collection context away from the reactive stuff through a channel. So the logic that opens the scription happens on your IO thread, but it doesn't influence the publisher itself. The only thing the context is used for is if that reactive streams implementation has its own version of a context, then it supplies that context so it's accessible through the coroutine context. See
ReactorContext
https://github.com/Kotlin/kotlinx.coroutines/blob/1.3.3/reactive/kotlinx-coroutines-reactor/src/ReactorContext.kt I could see why they wouldn't manipulate the reactive streams' scheduling. We'll see what they say in that issue I guess