public final class TestScheduler extends Scheduler
By default, the tasks submitted via the various schedule
methods are not
wrapped by the RxJavaPlugins.onSchedule(Runnable)
hook. To enable this behavior,
create a TestScheduler
via TestScheduler(boolean)
or TestScheduler(long, TimeUnit, boolean)
.
Scheduler.Worker
Constructor and Description |
---|
TestScheduler()
Creates a new TestScheduler with initial virtual time of zero.
|
TestScheduler(boolean useOnScheduleHook)
Creates a new TestScheduler with the option to use the
RxJavaPlugins.onSchedule(Runnable) hook when scheduling tasks. |
TestScheduler(long delayTime,
TimeUnit unit)
Creates a new TestScheduler with the specified initial virtual time.
|
TestScheduler(long delayTime,
TimeUnit unit,
boolean useOnScheduleHook)
Creates a new TestScheduler with the specified initial virtual time
and with the option to use the
RxJavaPlugins.onSchedule(Runnable) hook when scheduling tasks. |
Modifier and Type | Method and Description |
---|---|
void |
advanceTimeBy(long delayTime,
TimeUnit unit)
Moves the Scheduler's clock forward by a specified amount of time.
|
void |
advanceTimeTo(long delayTime,
TimeUnit unit)
Moves the Scheduler's clock to a particular moment in time.
|
@NonNull Scheduler.Worker |
createWorker()
Retrieves or creates a new
Scheduler.Worker that represents sequential execution of actions. |
long |
now(@NonNull TimeUnit unit)
Returns the 'current time' of the Scheduler in the specified time unit.
|
void |
triggerActions()
Triggers any actions that have not yet been triggered and that are scheduled to be triggered at or
before this Scheduler's present time.
|
clockDriftTolerance, scheduleDirect, scheduleDirect, schedulePeriodicallyDirect, shutdown, start, when
public TestScheduler()
public TestScheduler(boolean useOnScheduleHook)
RxJavaPlugins.onSchedule(Runnable)
hook when scheduling tasks.
History: 3.0.10 - experimental
useOnScheduleHook
- if true
, the tasks submitted to this
TestScheduler is wrapped via the
RxJavaPlugins.onSchedule(Runnable)
hookpublic TestScheduler(long delayTime, TimeUnit unit)
delayTime
- the point in time to move the Scheduler's clock tounit
- the units of time that delayTime
is expressed inpublic TestScheduler(long delayTime, TimeUnit unit, boolean useOnScheduleHook)
RxJavaPlugins.onSchedule(Runnable)
hook when scheduling tasks.
History: 3.0.10 - experimental
delayTime
- the point in time to move the Scheduler's clock tounit
- the units of time that delayTime
is expressed inuseOnScheduleHook
- if true
, the tasks submitted to this
TestScheduler is wrapped via the
RxJavaPlugins.onSchedule(Runnable)
hookpublic long now(@NonNull @NonNull TimeUnit unit)
Scheduler
public void advanceTimeBy(long delayTime, TimeUnit unit)
delayTime
- the amount of time to move the Scheduler's clock forwardunit
- the units of time that delayTime
is expressed inpublic void advanceTimeTo(long delayTime, TimeUnit unit)
delayTime
- the point in time to move the Scheduler's clock tounit
- the units of time that delayTime
is expressed inpublic void triggerActions()
@NonNull public @NonNull Scheduler.Worker createWorker()
Scheduler
Scheduler.Worker
that represents sequential execution of actions.
When work is completed, the Worker
instance should be released
by calling Disposable.dispose()
to avoid potential resource leaks in the
underlying task-execution scheme.
Work on a Scheduler.Worker
is guaranteed to be sequential and non-overlapping.
createWorker
in class Scheduler