Similar to the doOnError life cycle hook, there is the doFinally hook. This hook is invoked post-stream completion. The hook executes the lambda provided. It is important to note that the doFinally hook is invoked post-stream close callback processing, unlike the previously discussed doOnTerminate hook, which is invoked as soon as we received the close events. Consider the following code:
@Test public void testDoFinally() { Flux<Long> fibonacciGenerator = Flux.generate(() -> Tuples.<Long, Long>of(0L, 1L), (state, sink) -> { if (state.getT1() < 0) sink.error(new RuntimeException("Value out of bounds")); else sink.next(state.getT1()); return Tuples.of(state.getT2(), state.getT1() + state.getT2()); }); fibonacciGenerator ...