Closed
Description
Expected behavior
Following code:
Mono.just("outer")
.then(Mono.just("inner").doOnTerminate(() -> System.out.println("Completed inner mono.")))
.doOnTerminate(() -> System.out.println("Completed outer mono."))
.subscribe(System.out::println, Throwable::printStackTrace, () -> System.out.println("Subscriber onComplete called."));
Expected output:
inner
Completed inner mono.
Completed outer mono.
Subscriber onComplete called.
Actual behavior
Actual output:
inner
Subscriber onComplete called.
Complete outer mono.
Complete inner mono.
Reactor Core version
3.2.8
Additional details
Switching the inner Mono
to an empty one produces the expected output
Mono.just("outer")
.then(Mono.empty().doOnTerminate(() -> System.out.println("Completed inner mono.")))
.doOnTerminate(() -> System.out.println("Completed outer mono."))
.subscribe(System.out::println, Throwable::printStackTrace, () -> System.out.println("Subscriber onComplete called."));
Output:
Completed inner mono.
Completed outer mono.
Subscriber onComplete called.
Switching to thenMany(Flux)
instead of then(Mono)
also creates the expected output.
Looking at a more basic example:
Mono.just("outer")
.doOnTerminate(() -> System.out.println("Complete outer mono."))
.subscribe(System.out::println, Throwable::printStackTrace, () -> System.out.println("Subscriber onComplete called."));
also produces slightly unexpected output:
outer
Subscriber onComplete called.
Complete outer mono.
Switching to Flux
here produces the expected output.
For the first example the issue is somewhere inside MonoIgnoreThen
I believe.