Package hu.akarnokd.rxjava3.schedulers
Class BlockingScheduler
- java.lang.Object
-
- io.reactivex.rxjava3.core.Scheduler
-
- hu.akarnokd.rxjava3.schedulers.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) orexecute(Action)to start with a first action.
In the example code above,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 */ }); }); }observeOn(scheduler)will execute on the main thread of the Java application.- Since:
- 0.15.1
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class io.reactivex.rxjava3.core.Scheduler
Scheduler.Worker
-
-
Constructor Summary
Constructors Constructor Description BlockingScheduler()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Scheduler.WorkercreateWorker()voidexecute()Begin executing the blocking event loop without any initial action.voidexecute(Action action)Begin executing the blocking event loop with the given initial action (usually contain the rest of the 'main' method).DisposablescheduleDirect(java.lang.Runnable run, long delay, java.util.concurrent.TimeUnit unit)voidshutdown()-
Methods inherited from class io.reactivex.rxjava3.core.Scheduler
clockDriftTolerance, now, scheduleDirect, schedulePeriodicallyDirect, start, when
-
-
-
-
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:
scheduleDirectin classScheduler
-
createWorker
public Scheduler.Worker createWorker()
- Specified by:
createWorkerin classScheduler
-
-