I have the following code which creates a simple Observable, emits an Integer and calls onComplete. According to https://medium.com/@ValCanBuild/making-rxjava-code-tidier-with-doonsubscribe-and-dofinally-3748f223d32d doFinally — Calls the specified action after this Observable signals onError or onCompleted or gets disposed by the downstream.
However, even after onComplete is called (I verified it is being called, check output below the code) I cannot see doFinally being called at all.
import io.reactivex.rxjava3.core.Observable;
public static void main(String args[]) {
test();
}
public static void test() {
System.out.println("Start");
Observable<Integer> observable = Observable.create(emitter -> {
emitter.onNext(1);
emitter.onComplete();
});
observable.doFinally(() -> System.out.println("Test do finally before"));
observable.blockingSubscribe(System.out::println, System.out::println, () -> {
System.out.println("ON Complete");
});
observable.doFinally(() -> System.out.println("Test do finally after"));
System.out.println("End");
}
Output
Start
1
ON Complete
End
AS per my understanding if it is a blocking Stream after onComplete, it should execute doFinally. Need help in this on what I might be missing.