Vincent Williams
08/13/2020, 8:11 PMstreetsofboston
08/13/2020, 8:18 PMEventFlow
for that.
It is like a StateFlow with respect that it is a hot stream of data, but it differs that it is state-less (a new collector will not receive the last value it had emitted).
Think of a StateFlow like it could've been backed by a Conflated Broadcast Channel and of an EventFlow like it could've been backed by a rendezvous Channel.Vincent Williams
08/13/2020, 8:19 PMstreetsofboston
08/13/2020, 8:37 PMoffer
instead of send
. But you risk loosing an emission if no one is listening/collecting (but then it wouldn’t be a problem… 🙂 )Vincent Williams
08/13/2020, 8:38 PMstreetsofboston
08/13/2020, 8:40 PMoffer
instead of send
.Vincent Williams
08/13/2020, 9:15 PMstreetsofboston
08/13/2020, 9:19 PMchannel.send(event)
in one background thread more than once in really quick succession.
And your collector in the UI, on the Main thread (Main dispatcher), which should finish in 16ms, but is somehow a bit slower than the producer calling the send
method for the 2nd time.
Usually this is not a big issue, since Events are often used for navigation and two navigation events should not be emitted in such quick succession (faster than the UI can handle them).send
method in the viewModelScope
for example (assuming here you do Android development). This way you won’t miss sent events (unless the viewModelScope
itself gets cancelled).gildor
08/13/2020, 11:48 PMVincent Williams
08/13/2020, 11:51 PMgildor
08/13/2020, 11:52 PMstreetsofboston
08/14/2020, 3:20 AMsend
on that channel would not risk losing any events, even if the consumer's CoroutineScope is cancelled (eg UI detached), because if the consumer (collector) is detached no one is listening and the sender/producer will just suspend until a new collector arrives (UI re-attached).gildor
08/14/2020, 3:37 AM