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:
- We added the delayElements operator to our chain. ...