Skip to content

Instantly share code, notes, and snippets.

@murki
Last active February 22, 2016 05:34
Show Gist options
  • Save murki/8b848026f3a61ab44d8c to your computer and use it in GitHub Desktop.
Save murki/8b848026f3a61ab44d8c to your computer and use it in GitHub Desktop.
// DiskRepository.java
public void saveData(Data data) {
// implementation
}
// DomainService.java
@RxLogObservable
public Observable<Data> getMergedData() {
return Observable.merge(
diskRepository.getData().subscribeOn(Schedulers.io()),
networkRepository.getData()
.doOnNext(new Action1<Data>() {
@Override
public void call(Data data) {
diskRepository.saveData(data); // <-- save to cache
}
}).subscribeOn(Schedulers.io())
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment