In the context of Android and replacing SingleLive...
# coroutines
l
In the context of Android and replacing SingleLiveEvent. can anyone explain why a BUFFERED Channel seems to be preferred to the default RENDEZVOUS Channel?
w
keep in mind
Channel
is a considered a low level primitive compared to
StateFlow
and
SharedFlow
. Those two might also be worth checking out
are you referring to the default
Channel
constructor?
i would think
Copy code
MutableSharedFlow(0, 0, onBufferOverflow = BufferOverflow.DROP_LATEST)
is analogous to
SingleLiveEvent
l
It isn’t unfortunately as any events emitted when there are no subscribers would be dropped which could happen during an Android configuration change, hence the need for a Channel which will suspend/buffer until there is a subscriber
w
well i think you’ve answered your question then - the buffer retains emissions that could occur in that time
l
So with a buffered Channel, it could still send events while there is no subscribers, whereas with a rendezvous Channel no further events would be able to be sent due to the suspending behaviour?
w
i think that’s correct
u
But it would suspend until there is a receiver (depending on how you send). so no lost events either. but potential dead locks :-)
w
unless your using
tryEmit