Skip to content

Instantly share code, notes, and snippets.

@if6was9
Created March 27, 2019 06:01
Show Gist options
  • Select an option

  • Save if6was9/e912e7fa2feecf0ff0e7e672df84d1c1 to your computer and use it in GitHub Desktop.

Select an option

Save if6was9/e912e7fa2feecf0ff0e7e672df84d1c1 to your computer and use it in GitHub Desktop.
ObservableOnSubscribe<String> observableOnSubscribe = new ObservableOnSubscribe<String>() {
@Override
public void subscribe(ObservableEmitter<String> emitter) throws Exception {
// This will be called when subscribe() is called
// At this point
System.out.println(Thread.currentThread()+": ObservableOnSubscribe.subscribe() called");
ImmutableList.of("one","two","three").forEach(it->{
System.out.println(Thread.currentThread()+": emitter.onNext("+it+") called");
emitter.onNext(it);
});
System.out.println(Thread.currentThread()+": emitter.onComplete() called");
emitter.onComplete();
System.out.println(Thread.currentThread()+": leaving subscribe()");
}
};
System.out.println(Thread.currentThread()+": calling Observable.create()...");
Observable obs = Observable.create(observableOnSubscribe);
System.out.println(Thread.currentThread()+": Observable.create() complete");
obs.observeOn(Schedulers.io()).subscribe(it->{
System.out.println(Thread.currentThread()+": received "+it);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment