I have following sample that demontrates the problem:
Observable<Integer> observable = Observable.create(subscriber -> {
IntStream.range(0, 1_00).forEach(subscriber::onNext);
subscriber.onCompleted();
}).doOnCompleted(() -> System.out.println("I'm first, but want to be second"));
observable.subscribe((i)-> {}, (e)-> System.err.println(e), ()-> System.out.println("I'm second, but want to be first"));
If I replace observable doOnCompleted
with doAfterTerminate
it works, but it has slightly different semantics.
How to achieve that subscriber onCompleted
will be called before doOnCompleted
on that observable ?