Created
February 15, 2017 15:41
-
-
Save antslava/0beaec4cf6c5a42d6f418cf006292387 to your computer and use it in GitHub Desktop.
RxJava share()
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
package com.antmobile.java; | |
import rx.Observable; | |
import rx.Subscriber; | |
import rx.schedulers.Schedulers; | |
public class FirstTempClass { | |
public static void main(String[] args) { | |
final Observable<Long> observable = Observable.create(new Observable.OnSubscribe<Long>() { | |
public void call(Subscriber<? super Long> subscriber) { | |
subscriber.onNext(System.nanoTime()); | |
} | |
}) | |
.subscribeOn(Schedulers.io()) | |
.observeOn(Schedulers.io()) | |
.share(); | |
// First | |
observable.subscribe(new Subscriber<Long>() { | |
public void onCompleted() { | |
System.out.println(""); | |
} | |
public void onError(Throwable e) { | |
System.out.println(); | |
} | |
public void onNext(Long aLong) { | |
System.out.println("first:= " + aLong); | |
} | |
}); | |
// Second | |
observable.subscribe(new Subscriber<Long>() { | |
public void onCompleted() { | |
System.out.println(); | |
} | |
public void onError(Throwable e) { | |
System.out.println(); | |
} | |
public void onNext(Long aLong) { | |
System.out.println("second:= " + aLong); | |
} | |
}); | |
while (true) { | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment