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

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

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.