Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WassimBenltaief/8648663bb18cd8666289 to your computer and use it in GitHub Desktop.
Save WassimBenltaief/8648663bb18cd8666289 to your computer and use it in GitHub Desktop.
PublishSubject emmiting value when a private Observable is completed
public class Main {
public static void main(String [] args) {
final PublishSubject<Boolean> subject = PublishSubject.create();
subject.subscribe(new Observer<Boolean>() {
@Override
public void onCompleted() {
}
@Override
public void onError(Throwable e) {
}
@Override
public void onNext(Boolean aBoolean) {
System.out.println("Observable completed");
}
});
Observable.create(new Observable.OnSubscribe<Integer>() {
@Override
public void call(Subscriber<? super Integer> subscriber) {
for (int i = 0; i < 5; i++) {
subscriber.onNext(i);
}
subscriber.onCompleted();
}
}).doOnCompleted(new Action0() {
@Override
public void call() {
subject.onNext(true);
}
}).subscribe();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment