Ayla
05/05/2023, 6:04 AMval tempJob:Job? = null
fun getNotesToday(today:LocalDate){
viewModelScope.launch{
tempJob?.cancel()
tempJob=launch{
database.noteQuery
.getNotesBetween(today.start,today.end)
.asFlow()
.collectLatest{...}
}
}
It seems a bit troublesome to do the same for every situation like this, is there a better way?glureau
05/05/2023, 6:58 AMhfhbd
05/05/2023, 7:54 AMflorent
05/05/2023, 8:11 AMAyla
05/05/2023, 10:44 AMflorent
05/05/2023, 11:25 AMStylianos Gakis
05/06/2023, 8:22 PMflowThatReturnsCurrentDay().collectLatest { date ->
yourDbFlow.collect { ... }
}
This by itself should cancel the old collection, and start a new one with the new date. Just need to create a flow which returns this date somehow.Ayla
05/07/2023, 10:27 AM