I have a repository making a network call via a datasource.
I have two use cases that both call that reposository to get the resource but are making different treatments.
Those use cases are subscribing at the same time.
The behavior I want is to make the network call on first subscription, block the other ones and then cache the data to observers in queue.
For now I have a fetch method in the repository actually making the network call (called at one place in my code). I have a get method that return a behavior subject that is valued when the fetch method get data (the uses cases are observing this behavior subject).
I don't like having those two methods and I think it should be transparent. In an ideal case the use cases should call a single repository method and get data (the first one making the network call because cache is missing, the second one getting the cached data).
Is there a way to do this with RxJava ?