I want to create a repostiory for managing api and...
# coroutines
p
I want to create a repostiory for managing api and databasse objects at one place. I have a database which exposes a Flowable<Optional<MyObject>. And I have an API which returns a
suspend fun myObject : MyObject
. I now want to listen to events of that repository. When I start listening, I want to subscribe to the flowable. If the Optional is present, I want to return the wrapped object. If it's absent, I want to load it and insert it into the database. If that fails, I want to inform the user about an error. If the object is present but stale, I want to try to load it from the API but not inform the user about the failure. And all together I want to make sure that there are no unnecessary api calls so that listening to that repo from other places does not start another network call.