Posted on Leave a comment

Loading data from few sources by rxjava

Observable<Data> memory = ...;  
Observable<Data> disk = ...;  
Observable<Data> network = ...;
// Retrieve the first source with data
Observable<Data> source = Observable  
  .concat(memory, disk, network)

Save data to cache

Observable<Data> networkWithSave = network.doOnNext(data -> {  
Observable<Data> diskWithCache = disk.doOnNext(data -> {  

Update data

Observable<Data> source = Observable  
  .concat(memory, diskWithCache, networkWithSave)
  .first(data -> data.isUpToDate());
Leave a Reply

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.