Class BlockingScheduler


  • public final class BlockingScheduler
    extends Scheduler
    A Scheduler that uses the current thread, in an event-loop and blocking fashion to execute actions.

    Use the execute() to start waiting for tasks (from other threads) or execute(Action) to start with a first action.

    
     public static void main(String[] args) {
         BlockingScheduler scheduler = new BlockingScheduler();
         scheduler.execute(() -> {
             // This executes in the blocking event loop.
             // Usually the rest of the "main" method should
             // be moved here.
    
             someApi.methodCall()
               .subscribeOn(Schedulers.io())
               .observeOn(scheduler)
               .subscribe(v -> { /* on the main thread */ });
         });
     }
     
    In the example code above, observeOn(scheduler) will execute on the main thread of the Java application.
    Since:
    0.15.1
    • Constructor Detail

      • BlockingScheduler

        public BlockingScheduler()
    • Method Detail

      • execute

        public void execute()
        Begin executing the blocking event loop without any initial action.

        This method will block until the shutdown() is invoked.

        See Also:
        execute(Action)
      • execute

        public void execute​(Action action)
        Begin executing the blocking event loop with the given initial action (usually contain the rest of the 'main' method).

        This method will block until the shutdown() is invoked.

        Parameters:
        action - the action to execute
      • scheduleDirect

        public Disposable scheduleDirect​(java.lang.Runnable run,
                                         long delay,
                                         java.util.concurrent.TimeUnit unit)
        Overrides:
        scheduleDirect in class Scheduler