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 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.