When collecting a flow using an activity lifecycle...
# android
m
When collecting a flow using an activity lifecycleScope, I’ve noticed that using the default
CoroutineStart.Default
, doesn’t work sometimes when using an empty buffer
Channel
and
receiveAsFlow
(where an event is being offered instead of sent).
CoroutineStart.Undispatched
does seem to work however. I’m assuming this is because the launched coroutine needs to have executed the collect coroutine before an event is offered to the channel, in order to receive it. So, is using
CoroutineStart.Undispatched
the correct approach, or should I be using a buffered channel instead?
I’m leaning towards using a buffer, because otherwise we need to enforce that the flow collection is initiated before the event is offered.
a
if you need to see all events then yes, you'll need to buffer that channel.
Dispatcher games to try to play subscribe timing Jenga will mask issues at best and lead to massive headaches down the road
👍 1
m
In this particular case, these are navigation events, so definitely don’t want to miss any of those!