Skip to content

Instantly share code, notes, and snippets.

@tomoima525
Last active May 2, 2023 22:38
Show Gist options
  • Select an option

  • Save tomoima525/39f31d3a14ba8ea2797e22e19021b4ba to your computer and use it in GitHub Desktop.

Select an option

Save tomoima525/39f31d3a14ba8ea2797e22e19021b4ba to your computer and use it in GitHub Desktop.
Observer pattern sample
PublishProcessor<List<Article>> articleList = PublishProcessor.create();
@Override
public Completable getArticles() {
return remoteDataSource.getArticles()
.flatMapCompletable(articles -> localDataSource
.saveArticles(articles)
.doOnSuccess(articleList::onNext))
}
public Observable<List<Article>> observeArticles() {
return articleList;
}
/// ArticleViewModel.java
disposables.addAll(
articleService.getArticles()
.subscribeOn(Schedular.io())
.subscribe(() -> { }, e -> {}),
articleService.observeArticles()
.toSingle()
.observeOn(Android.mainthread())
.subscribe(list -> view::bind)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment