https://kotlinlang.org logo
#android
Title
# android
a

azabost

10/11/2023, 8:42 PM
Hey. I'm looking for some clues about how exactly Room behaves when: • a query returns a
Flow
• there is an active subscriber of that
Flow
• a few changes in the observed table take place in the background • the subscriber of the
Flow
consumes the data slower than the updates are being made In particular, I would like to know if the
Flow
is going to emit every intermediate snapshot of the queried data or just the latest.
Copy code
----data update A----------data update B-----------data update C-->
       \
        \
      collected snapshot A & processing --------------------------------->finished
                                                                              \
                                                                               \
                                                                            what's in the next collected snapshot? B or C?
d

David

10/12/2023, 7:01 AM
a

azabost

10/12/2023, 10:40 AM
Yeah, I'm familiar with that term. I tested Room-generated
Flow
with`conflate()` yesterday, hoping to always get the latest possible result from Room. It helped a lot but, unfortunately, it still didn't work the way I expected. My case looked like this:
Copy code
database.dataFlow()
  .conflate()
  .collect { values ->
    // some processing
    database.updateSomethingThatAffectsTheFlow(values)
}
It turned out that the change made by
database.updateSomethingThatAffectsTheFlow()
was not reflected in the next collected value. I had to wait for yet another value to see that change 😕 I suspect that Room didn't have enough time to compute the new value for the
Flow
before the subscriber became ready to receive the next update. Or something.