Created
December 3, 2018 10:06
-
-
Save anitaa1990/6ff85e801e45ff262490f0a44578735a to your computer and use it in GitHub Desktop.
This file contains 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
/* | |
* Step 1: Create an observable that emits an integer | |
* from 1 to 5 | |
* */ | |
Observable<Integer> observable = Observable.range(1, 5) | |
.subscribeOn(Schedulers.io()); | |
/* | |
* Step 2: Create a subject that observes | |
* this emission from the observable. In this scenario, | |
* the subject acts an an observer since it observes the | |
* changes to the Observable. | |
* */ | |
ReplaySubject<Integer> subject = ReplaySubject.create(); | |
observable.subscribe(subject); | |
/* | |
* Step 3: In this scenario, the subject acts an an Observable, | |
* since it emits each item from the original Observable. | |
* */ | |
subject.subscribe(s -> System.out.println("subscriber one: " + s)); | |
subject.subscribe(s -> System.out.println("subscriber two: " + s)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment