Thomas
04/22/2019, 7:21 PMval channel = ConflatedBroadcastChannel(Unit)
channel.asFlow().produceIn(GlobalScope).poll()!!
If I understand correctly this shouldn’t be happening because the channel has a default Unit
value. The following code, however, does not crash:
val channel = ConflatedBroadcastChannel(Unit)
channel.openSubscription().poll()!!
I don’t get why this works but the first example doesn’t. Could someone please explain this behaviour?gildor
04/22/2019, 11:13 PMgildor
04/22/2019, 11:14 PMThomas
04/23/2019, 7:06 AMrunBlocking { }
call and put in in a unit testgildor
04/23/2019, 7:08 AMThomas
04/23/2019, 7:09 AMConflatedBroadcastChannel
as a flow in my code. In a unit test I want to check the values of the flow, so I convert the flow to a channel using produceIn
so I could use poll()
. I'm now using receive()
which does do what I want.gildor
04/23/2019, 7:18 AMreceive()
for thisgildor
04/23/2019, 7:22 AMI convert the flow to a channel usingBut why do you need channel for this? You can just use suspend methodso I could useproduceIn
poll()
single()
to get 1 value from FlowThomas
04/23/2019, 7:55 AMsingle()
requires the flow to send one value and be closed or else it won't return. So that's why I'm using `poll()`/`receive()` for this, because I need to check the value (multiple times) without closing the flow.
If you know a better approach, please let me know because I might be missing something obvious.gildor
04/23/2019, 8:11 AMgildor
04/23/2019, 8:11 AMThomas
04/23/2019, 8:35 AMtoList()
won’t work either because it requires the flow to be closed or it won’t return.gildor
04/23/2019, 8:55 AM