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:
- We added the delayElements operator to our chain.
- The test tries to schedule the delay on the main thread.