Skip to content

Instantly share code, notes, and snippets.

@akbarsha03
Last active January 8, 2017 06:05
Show Gist options
  • Save akbarsha03/a1e73322a4cfff7c59c0a1e72ea03dce to your computer and use it in GitHub Desktop.
Save akbarsha03/a1e73322a4cfff7c59c0a1e72ea03dce to your computer and use it in GitHub Desktop.
RxJava recursive function using PublishSubject
PublishSubject<Integer> limit = PublishSubject.create();
limit.concatMap(integer -> Observable.just(integer + 1)) // Assuming this gives network result based upon the artist id you provided
.doOnNext(integer -> {
// Based on the network result i make my conditions here
Timber.d("Publish: doOnNext: %d", integer);
if (integer < 10) {
// Pass the artist id to make the next call
limit.onNext(integer);
} else {
limit.onCompleted();
}
})
.toList()
.subscribe(integers -> Timber.d("Publish: All the results"));
limit.onNext(1); // For demo, I'm starting here with 1. You have to pass the artist id here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment