Runs a block of code in this ExecutionContext
.
Runs a block of code in this ExecutionContext
.
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.minutes, { println("Hello, world!") }) // later if you change your mind ... task.cancel()
is the time to wait until the execution happens
is the callback to be executed
a Cancelable
that can be used to cancel the created task
before execution.
Schedules the given action
for immediate execution.
Schedules the given action
for immediate execution.
a Cancelable that can be used to cancel the task in case it hasn't been executed yet.
Schedules a task for periodic execution.
Schedules a task for periodic execution. The callback scheduled for execution receives a function as parameter, a function that can be used to reschedule the execution or consequently to stop it.
This variant of scheduleRepeated is useful if at some point you want to stop the execution from within the callback.
The following increments a number every 5 seconds until the number reaches 20, then prints a message and stops:
var counter = 0 scheduler.schedule(5.seconds, 5.seconds, { reschedule => count += 1 if (counter < 20) reschedule() else println("Done!") })
is the time to wait until the first execution happens
is the time to wait between 2 subsequent executions of the task
is the callback to be executed
a cancelable that can be used to cancel the task at any time.
Schedules a task for execution repeated with the given delay
between
executions.
Schedules a task for execution repeated with the given delay
between
executions. The first execution happens after initialDelay
.
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 = scheduler.scheduleRepeated(5.seconds, 10.seconds , { println("Hello, world!") }) // 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 subsequent executions of the task
is the callback to be executed
a cancelable that can be used to cancel the execution of this repeated task at any time.