The use-case is to 'drive' a Flow stream off invalidations from Room.
For example, say you have TableOne and TableTwo and you want to combine data from both, querying in a transaction and avoiding intermediate emissions since an operation write both tables in a transaction. Then one could use such API to drive the stream, like this:
suspend fun getCombinedData(): Flow<CombinedData> {
// Create an observer of the tables that would invalidate the flow
return db.invalidationTracker.createObserverFlow(arrayOf("TableOne", "TableTwo")).map { _ ->
val (dataFromTableOne, dataFromTableTwo) = db.withTransaction {
dao.getDataOneSuspending() to dao.getDataTwoSuspending()
}
combineTransform(dataFromTableOne, dataFromTableTwo) // returns List<CombinedData>
)
}
Description
The use-case is to 'drive' a Flow stream off invalidations from Room.
For example, say you have
TableOne
andTableTwo
and you want to combine data from both, querying in a transaction and avoiding intermediate emissions since an operation write both tables in a transaction. Then one could use such API to drive the stream, like this: