Schedules the given command
for execution at some time in the future.
The ExecutionModel is a specification of how run-loops and producers should behave in regards to executing tasks either synchronously or asynchronously.
The ExecutionModel is a specification of how run-loops and producers should behave in regards to executing tasks either synchronously or asynchronously.
Reports that an asynchronous computation failed.
Reports that an asynchronous computation failed.
Schedules a task to run in the future, after initialDelay
.
Schedules a task to run in the future, after initialDelay
.
For example the following schedules a message to be printed to standard output after 5 minutes:
val task = scheduler.scheduleOnce(5, TimeUnit.MINUTES, new Runnable { def run() = print("Hello, world!") }) // later if you change your mind ... task.cancel()
is the time to wait until the execution happens
is the time unit used for initialDelay
is the callback to be executed
a Cancelable
that can be used to cancel the created task
before execution.
Returns the current time in milliseconds.
Returns the current time in milliseconds. Note that while the unit of time of the return value is a millisecond, the granularity of the value depends on the underlying operating system and may be larger. For example, many operating systems measure time in units of tens of milliseconds.
It's the equivalent of System.currentTimeMillis()
. When wanting
to measure time, do not use System.currentTimeMillis()
directly, prefer this method instead, because then it can be
mocked for testing purposes (see for example
TestScheduler)
Schedules a periodic task that becomes enabled first after the given initial delay, and subsequently with the given period.
Schedules a periodic task that becomes enabled first after the given
initial delay, and subsequently with the given period. Executions will
commence after initialDelay
then initialDelay + period
, then
initialDelay + 2 * period
and so on.
If any execution of the task encounters an exception, subsequent executions are suppressed. Otherwise, the task will only terminate via cancellation or termination of the scheduler. If any execution of this task takes longer than its period, then subsequent executions may start late, but will not concurrently execute.
For example the following schedules a message to be printed to standard output approximately every 10 seconds with an initial delay of 5 seconds:
val task = scheduler.scheduleAtFixedRate(5, 10, TimeUnit.SECONDS, new Runnable { def run() = print("Repeated message") }) // later if you change your mind ... task.cancel()
is the time to wait until the first execution happens
is the time to wait between 2 successive executions of the task
is the time unit used for the initialDelay
and the period
parameters
is the callback to be executed
a cancelable that can be used to cancel the execution of this repeated task at any time.
Schedules for execution a periodic task that is first executed after the given initial delay and subsequently with the given delay between the termination of one execution and the commencement of the next.
Schedules for execution a periodic task that is first executed after the given initial delay and subsequently with the given delay between the termination of one execution and the commencement of the next.
For example the following schedules a message to be printed to standard output every 10 seconds with an initial delay of 5 seconds:
val task = s.scheduleWithFixedDelay(5, 10, TimeUnit.SECONDS, new Runnable { def run() = print("Repeated message") }) // later if you change your mind ... task.cancel()
is the time to wait until the first execution happens
is the time to wait between 2 successive executions of the task
is the time unit used for the initialDelay
and the delay
parameters
is the callback to be executed
a cancelable that can be used to cancel the execution of this repeated task at any time.
Given a function that will receive the underlying
ExecutionModel,
returns a new Scheduler reference, based on the source,
that exposes the transformed ExecutionModel
when queried by means of the executionModel property.
Given a function that will receive the underlying
ExecutionModel,
returns a new Scheduler reference, based on the source,
that exposes the transformed ExecutionModel
when queried by means of the executionModel property.
This method enables reusing global scheduler references in a local scope, but with a slightly modified execution model to inject.
The contract of this method (things you can rely on):
Scheduler
must not be modified in any wayScheduler
in every way except for
the execution modelSample:
import monix.execution.Scheduler.global implicit val scheduler = { val em = global.executionModel global.withExecutionModel(em.withAutoCancelableLoops(true)) }
Helper for building a Scheduler.
You can inherit from this class and provided a correct scheduleOnce you'll get Scheduler.scheduleWithFixedDelay and Scheduler.scheduleAtFixedRate for free.