--

This solution does not have a single source of truth, you are returning the database data and then returning the network data, so you effectively have two sources of truth. What you should do is use Room's APIs to return a flow from the database and then update the database from remote, the flow will emit once the database is updated.

Another issue I see is that your refresh control is not synchronized, so if you make multiple calls to the query function, because the refresh only updates after the network and storage operations complete, you will end up with multiple network calls in flight at the same time.

Query returns a flow, so it should not be a suspend function.

--

--

Francesc Vilarino Guell
Francesc Vilarino Guell

Responses (1)