Stylianos Gakis
04/18/2023, 10:01 AMmapLatest
on it which in that lambda you’re doing all this processing, if the DB emits a new value into that flow, your previous calculation should be cancelled and you will get the fresh data automatically.adte
04/18/2023, 4:02 PMmap
function and not deal with any flow inside thereStylianos Gakis
04/18/2023, 8:18 PMcombine
on those so that you get them all together in one flow, and then do whatever you want with them. Gonna paste some code that I used just to make sure that the types all play well together.
object queries {
fun getFlowForId(id: Long): Flow<Int> = flowOf()
}
fun getData(ids: List<Long>): Flow<List<Int>> {
val allFlows: List<Flow<Int>> = ids.map {
queries.getFlowForId(it)
}
return combine(allFlows) { flows: Array<Int> ->
flows.toList()
}.mapLatest {
//do stuff here
it
}
}
Does this look like what you’re looking for?apsaliya
04/19/2023, 5:42 AMexecute
is called, you can do something like this. This will execute your mapper every time user table is updated.
notificationQuery: SELECT * FROM USER
// this query will only be used for observing changes in User table
...
...
notificationQuery.asFlow()
.map {
// val user = databse.queries.fetchById().executeAsOne()
// map to the type you want
}