Tower Guidev2
12/12/2021, 7:46 PMTower Guidev2
12/12/2021, 7:47 PMval outcome: Flow<Outcome> = service.myRemoteAPIcall(arg1 , arg2)
val result: Flow<PagingData<MyDataUI>> = myDatabase.fetchLocalData()
Fragment Code
============
viewLifecycleOwner.lifecycleScope.launch {
outcome.take(1).collect { outcome ->
if (outocme == Success)
withContext(Dispatchers.Main) {
result.collect {
myDataAdapter.submitData(it)
}
}
}
}
I do not collect the PagingData
flow until the remote api call has completed successfully. Therefore I would expect the data that is submitted to my PagingDataAdapter
to reflect the changes made by the remote api call.
However this is not the case.
i would like to understand two aspects of the observed behaviour.
i). why am i not seeing the updated data? where do I make my mistake.
ii).how can I fix this? how do i "wait" correctly for the remote api to complete before fetching the local (updated) data?yigit
12/15/2021, 9:23 PMmyRemoteAPIcall
finishes writing into the database before it returns ?yigit
12/15/2021, 9:23 PMyigit
12/15/2021, 9:23 PMTower Guidev2
12/16/2021, 8:03 AM