title: How to merge flow and channel in Kotlin?
body: <p>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).</p>
  
  <p>I also not sure if it's the best solution, so let me know if I can make it better.</p>
  
  <p>What am I doing:</p>
  
  <p>My api:</p>
  
  <pre><code>override val statusFlow = trackStatus()
  
  private fun trackStatus(): Flow&lt;State&gt; = flow { ... }
  
  private val deviceChannel = Channel&lt;State&gt;(CONFLATED)
  </code></pre>
  
  <p>So statusFlow should return a flow from which I can receive data from both flow and channel.</p>
  
  <p>I tried to convert the channel to flow by consumeAsflow, but it doesn't work.</p>
  
  <p>I see a solution as </p>
  
  <pre><code>private fun trackStatus(): Flow&lt;State&gt; = flowOf(channel.toFlow(), flow).flattenMerge()
  </code></pre>
  
  <p>What is the proper way to do it?</p>