The ExecutorService scheduler

The Schedulers.fromExecutor enables us to build a scheduler over the Java ExecutorService. The scheduler does not own thread generation, but instead, it is controlled by the underlying ExecutorService. The scheduler should not be favored over other schedulers, as the life cycle of the ExecutorService must be managed by the developer. Consider the following code:

 @Test    public void testExecutorScheduler() throws Exception{        // Removed for Brevity        ExecutorService executor = Executors.newSingleThreadExecutor();        fibonacciGenerator                .filter(x -> {                    print("Executing Filter");                    return x < 100;                }).delayElements(Duration.ZERO,Schedulers.fromExecutor(executor))                 .doOnNext(x -> print("Next value is  "+ x)) .doFinally(x -> print("Closing ...

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.