I need to create an API, it should be flow, which collects events. The problem is that these events may be from a channel (I need an analog for PublishSubject) and from a flow (which does a network request).
I also not sure if it's the best solution, so let me know if I can make it better.
What am I doing:
My api:
override val statusFlow = trackStatus()
private fun trackStatus(): Flow<State> = flow { ... }
private val deviceChannel = Channel<State>(CONFLATED)
So statusFlow should return a flow from which I can receive data from both flow and channel.
I tried to convert the channel to flow by consumeAsflow, but it doesn't work.
I see a solution as
private fun trackStatus(): Flow<State> = flowOf(channel.toFlow(), flow).flattenMerge()
What is the proper way to do it?