The single scheduler

The Schedulers.single scheduler executes work on a single-worker thread pool. Since this is a single worker, all tasks are executed one by one, and no task is performed in a concurrent manner. The scheduler is quite useful for isolating the execution of non-threadsafe operations to a single thread. Consider the following code:

@Test  public void testSingleScheduler() throws Exception{       // Removed for Brevity        fibonacciGenerator                .delayElements(Duration.ofNanos(10),Schedulers.single())                .doOnNext(x -> print("Next value is  "+x))                .doFinally(x -> print("Closing "))           .subscribe(x -> print("Sub received : "+x));      Thread.sleep(500); }

In the preceding code, the following has occurred:

  1. We added the delayElements operator to our chain. ...

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.