Last active
January 8, 2017 06:05
-
-
Save akbarsha03/a1e73322a4cfff7c59c0a1e72ea03dce to your computer and use it in GitHub Desktop.
RxJava recursive function using PublishSubject
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
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