Question
I am not able to understand why SharedFlow has no effect of applying
flowOn
s
Sam
09/20/2023, 6:59 AM
flowOn
effectively changes the context in which the flow is collected. In a regular flow, the collector coroutine is actually executing the code in the upstream flow, so changing the collector's context also changes the context in which the upstream flow is executed. But in a
SharedFlow
, there is a separate coroutine executing the upstream flow. Changing the collector's context does not affect the context of the separate producer coroutine.
Sam
09/20/2023, 7:01 AM
To change the context of a shared flow, you would need to provide the new context at the point when you launch the producer coroutine, e.g. via
shareIn
r
Rohan Maity
09/20/2023, 7:05 AM
Ok this makes sense to me now
Thanks for detailed explanation