Rohan Maity
08/08/2020, 3:20 PMtunnel.pipe.send("LOPI")
tunnel.pipe.asFlow().flowOn(Dispatchers.Main).collect {
tvPUI.text = it.toString()
}
delay(2000)
tunnel.pipe.send("HOLA")tseisel
08/08/2020, 3:43 PMcollect suspends until the source channel is closed, therefore "HOLA" could not be sentRohan Maity
08/08/2020, 3:44 PMRohan Maity
08/08/2020, 3:44 PMwasyl
08/08/2020, 3:49 PMlaunch { ..collect { } })Rohan Maity
08/08/2020, 3:54 PMRohan Maity
08/08/2020, 3:55 PMRohan Maity
08/08/2020, 3:56 PMsend and since its suspend function that whole coroutine was suspended (including collection)Rohan Maity
08/08/2020, 3:56 PMRohan Maity
08/08/2020, 3:56 PMwasyl
08/08/2020, 3:56 PMcollect { } starts collecting the flow and only completes (returns) when the flow finishes (channel closes). But the new coroutine started with launch runs concurrently, so launch { } call returns immediately, allowing your send to be actually calledwasyl
08/08/2020, 4:00 PMlaunch do you receive tunnel.pipe.send("LOPI")? Because I’m not sure you should, as you send it before flow is collected, and channels are hot, which means LOPI should be lostRohan Maity
08/08/2020, 4:18 PMRohan Maity
08/08/2020, 4:28 PMdarkmoon_uk
08/08/2020, 11:50 PMRohan Maity
08/09/2020, 5:47 AMRohan Maity
08/09/2020, 5:51 AMsend "LOPI" (which is suspend) and since I also tried collection in same coroutine. and there was no receiver for "LOPI" that whole coroutine was suspended
therefore collection was never completed in first place