The immediate scheduler

The Schedulers.immediate scheduler executes work on the currently executing thread. All tasks are executed on the caller thread, and no task is performed in parallel. This is the default execution model for most Reactor tasks. Consider the following code:

@Test  public void testImmediateSchedular() throws Exception{       // Removed for Brevity        fibonacciGenerator                .delayElements(Duration.ofNanos(10),Schedulers.immediate())                .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.
  2. The test tries to schedule the delay on the main thread.

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.