title: How do you split a 'hot' stream of events from a callback in Kotlin?
body: <p>I'm processing a hot stream of events, arriving by callback. 'Downstream' I'd like to split it into multiple streams, and process them.The events all arrive sequentially from a single thread (which I don't control, so I don't think I can use co routines here)
  What is the right structure to use here?</p>
  
  <p>I can create a Flow pretty easily, using callbackFlow and sendBlocking, but the semantics don't seem to line up, as the Flow isn't cold.
  What is the best way to split a flow into multiple downstream flows (depending on the contents of events). Or should I use channels? It matches the 'hotness' of my source, but the whole polling downstream seems off (in this basically synchronoussituation), and a lot of the methods seem deprecated in favor of Flow.</p>
  
  <p>I <em>can</em> do all this by just using 'callbacks all the way' but that creates a lot tighter coupling than I'd like. Any ideas?</p>
  
  <p>Edit:</p>
  
  <p>I ended up with this, seems to work:</p>
  
  <pre class="lang-kotlin prettyprint-override"><code>    fun testFlow() {
          runBlocking {
              val original = flowOf("aap", "noot", "mies", "wim", "zus","jet","weide","does")
              val broadcast = original.broadcastIn(this)
              val flow1 = broadcast.openSubscription().receiveAsFlow().filter { it.length == 4 }
              val flow2 = broadcast.openSubscription().receiveAsFlow().filter { it.length == 3 }
              flow1.collect { it -&gt; println("Four letter: ${it}") }
              flow2.collect { it -&gt; println("Three letter: ${it}") }
          }
      }
  </code></pre>