Skip to content

Instantly share code, notes, and snippets.

@amin3536
Last active August 8, 2018 18:51
Show Gist options
  • Save amin3536/0d8cece1aaedc230495a25b44852c4ed to your computer and use it in GitHub Desktop.
Save amin3536/0d8cece1aaedc230495a25b44852c4ed to your computer and use it in GitHub Desktop.
public Single<User> getUserById(String userId){
return db.getUserById(userId)
/// if there is no user in the database get data from api
.onErrorResumeNext(api.getUserById(userId)
.subscribeOn(Schedulers.io())
//check your request
.filter(statusPojo::getStatus)
// save data to room
.switchMap(data -> {
//sava data to db
return Observable.just(data)
})
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment