public Delay
This dispatcher feature is implemented by class CoroutineDispatcher implementations that natively support
scheduled execution of tasks.
Implementation of this interface affects operation of delay and withTimeout functions.
class CoroutineDispatcher| Modifier and Type | Interface and Description |
|---|---|
static class |
Delay.DefaultImpls
This dispatcher feature is implemented by
class CoroutineDispatcher implementations that natively support
scheduled execution of tasks. |
| Modifier and Type | Method and Description |
|---|---|
java.lang.Object |
delay(long time,
java.util.concurrent.TimeUnit unit,
kotlin.coroutines.experimental.Continuation<? super kotlin.Unit> p)
Delays coroutine for a given time without blocking a thread and resumes it after a specified time.
This suspending function is cancellable.
If the
interface Job of the current coroutine is cancelled or completed while this suspending function is waiting, this function
immediately resumes with CancellationException. |
DisposableHandle |
invokeOnTimeout(long time,
java.util.concurrent.TimeUnit unit,
java.lang.Runnable block)
Schedules invocation of a specified block after a specified delay time.
The resulting
interface DisposableHandle can be used to DisposableHandle.dispose of this invocation
request if it is not needed anymore. |
void |
scheduleResumeAfterDelay(long time,
java.util.concurrent.TimeUnit unit,
CancellableContinuation<? super kotlin.Unit> continuation)
Schedules resume of a specified continuation after a specified delay time.
|
java.lang.Object delay(long time,
java.util.concurrent.TimeUnit unit,
kotlin.coroutines.experimental.Continuation<? super kotlin.Unit> p)
Delays coroutine for a given time without blocking a thread and resumes it after a specified time.
This suspending function is cancellable.
If the interface Job of the current coroutine is cancelled or completed while this suspending function is waiting, this function
immediately resumes with CancellationException.
interface Jobvoid scheduleResumeAfterDelay(long time,
java.util.concurrent.TimeUnit unit,
CancellableContinuation<? super kotlin.Unit> continuation)
Schedules resume of a specified continuation after a specified delay time.
Continuation must be scheduled to resume even if it is already cancelled, because a cancellation is just
an exception that the coroutine that used delay might wanted to catch and process. It might
need to close some resources in its finally blocks, for example.
This implementation is supposed to use dispatcher's native ability for scheduled execution in its thread(s). In order to avoid an extra delay of execution, the following code shall be used to resume this continuation when the code is already executing in the appropriate thread:
with(continuation) { resumeUndispatched(Unit) }
DisposableHandle invokeOnTimeout(long time, java.util.concurrent.TimeUnit unit, java.lang.Runnable block)
Schedules invocation of a specified block after a specified delay time.
The resulting interface DisposableHandle can be used to DisposableHandle.dispose of this invocation
request if it is not needed anymore.
This implementation uses a built-in single-threaded scheduled executor service.