Last active
April 23, 2019 15:39
-
-
Save photizzo/e0143813170cd28b1da198181f4f030b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val cacheObservable:Observable<Data> = cacheSourceObservable | |
val remoteObservable:Observable<Data> = remoteSourceObservable.doOnNext { data -> | |
saveDataToCache(data) | |
} | |
val sourceObservable = Observable.concat( | |
cacheObservable.onErrorResumeNext(Function<Throwable, Observable<DriverStatsEntity>> { Observable.empty() /*ignore any errors from serving data from cache*/ }), | |
remoteObservable.onErrorResumeNext(Function<Throwable, Observable<DriverStatsEntity>> { throwable -> | |
if (!cache.hasCachedData()) Observable.error<Throwable>(throwable) /*show error from server since there is no data to be served*/ | |
Observable.empty() /*ignore any errors from remote server and continue serving data from cache*/ | |
}) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment