The doOnTerminate hook

Similar to the doOnError life cycle hook, there is the doOnTerminate hook. This is a generic hook that is invoked for on completion and on error stream termination events. Unlike the specific error hook, which provides the exception thrown, this hook does not provide any kind of input. It just executes the lambda provided. It is important to note that the doOnTerminate hook is invoked as soon as we receive termination events. It does not wait for the error callback to be processed. Consider the following code:

    @Test    public void testDoTerminate() {       // Removed for brevity        fibonacciGenerator                .doOnTerminate(() -> System.out.println("Terminated"))                .subscribe(System.out::println,e -> e.printStackTrace() );    }

The preceding ...

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.