mkrussel
04/30/2021, 3:01 PMFlow
where a lot of updates can happen at once and I want the collector to only process the last one.
The producer and the consumer are both on the UI thread. The desired behavior is when the producer gets out of their loop and goes back to waiting for some event, then the consumer gets the latest state.
What I have now is a callbackFlow
that is conflated
.
val flow = callbackFlow<Any> {
event.register { offer(someValue) }
awaitClose { event.unregister() }
}.conflate()
val job = scope.launch() {
flow.collect { }
The scope is using Android's MainScope
. And the event is sending events on the main thread.
When I was using a MutableStateFlow
this behaves as I wanted, but with the conflated callbackFlow
the caller is getting the first and last event, once all the events have been offerred.baxter
04/30/2021, 6:20 PMmkrussel
04/30/2021, 8:20 PMconflate
does, but it is getting me the first and last, and skipping the ones in the middle.baxter
04/30/2021, 8:40 PMcollecteLatest
?mkrussel
04/30/2021, 8:49 PMokarm
05/01/2021, 3:21 PM