The doFinally hook

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      ;            return Tuples.of(state.getT2(), state.getT1() + state.getT2());        }); fibonacciGenerator ...

Get Hands-On Reactive Programming with Reactor now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.