Skip to content

Instantly share code, notes, and snippets.

@antslava
Created February 15, 2017 15:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save antslava/0beaec4cf6c5a42d6f418cf006292387 to your computer and use it in GitHub Desktop.
Save antslava/0beaec4cf6c5a42d6f418cf006292387 to your computer and use it in GitHub Desktop.
RxJava share()
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