Skip to content

Instantly share code, notes, and snippets.

@anitaa1990
Created August 19, 2018 08:32
Show Gist options
  • Save anitaa1990/3c232c91dd673354bd74bea1303274de to your computer and use it in GitHub Desktop.
Save anitaa1990/3c232c91dd673354bd74bea1303274de to your computer and use it in GitHub Desktop.
/* Example of doOnNext() */
Observable.just("A", "B", "C", "D", "E", "F")
.doOnNext(new Consumer<String>() {
@Override
public void accept(String s) {
System.out.println("doOnNext: " + s);
}
})
.subscribe();
/* Example of doOnSubscribe(), doOnUnSubscribe(), doOnEach() */
Observable.range(1, 5)
.doOnEach(new Observer<Integer>() {
@Override
public void onError(Throwable e) {
e.printStackTrace();
}
@Override
public void onComplete() {
System.out.println("Complete is called");
}
@Override
public void onSubscribe(Disposable d) {
System.out.println("onSubscribe is called");
}
@Override
public void onNext(Integer value) {
System.out.println("onNext: " + value);
}
})
.doOnSubscribe(new Consumer<Disposable>() {
@Override
public void accept(Disposable disposable) {
System.out.println("onUnSubscribe is called");
}
})
.subscribe();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment