Created
December 3, 2018 10:35
-
-
Save anitaa1990/7aef38776789bdccbcee179faf55ab04 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. Each item is squared by itself before it is | |
* emitted. | |
* */ | |
Observable<Integer> observable = Observable.range(1, 5) | |
.subscribeOn(Schedulers.io()) | |
.map(integer -> { | |
System.out.println(String.format("Squaring %d with itself", integer)); | |
return integer * integer; | |
}); | |
/* | |
* Step 2: Create a subject that observes | |
* this emission from the observable. | |
* */ | |
ReplaySubject<Integer> subject = ReplaySubject.create(); | |
observable.subscribe(subject); | |
/* | |
* Step 3: We are subscribing two subscribers to the Subject. | |
* */ | |
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