Delay

interface Delay (source)

This dispatcher feature is implemented by CoroutineDispatcher implementations that natively support scheduled execution of tasks.

Implementation of this interface affects operation of delay and withTimeout functions.

Functions

delay

open suspend fun delay(
    time: Long,
    unit: TimeUnit = TimeUnit.MILLISECONDS
): Unit

Delays coroutine for a given time without blocking a thread and resumes it after a specified time. This suspending function is cancellable. If the Job of the current coroutine is cancelled or completed while this suspending function is waiting, this function immediately resumes with CancellationException.

invokeOnTimeout

open fun invokeOnTimeout(
    time: Long,
    unit: TimeUnit,
    block: Runnable
): DisposableHandle
abstract fun invokeOnTimeout(
    time: Int,
    block: Runnable
): DisposableHandle

Schedules invocation of a specified block after a specified delay time. The resulting DisposableHandle can be used to dispose of this invocation request if it is not needed anymore.

scheduleResumeAfterDelay

abstract fun scheduleResumeAfterDelay(
    time: Long,
    unit: TimeUnit,
    continuation: CancellableContinuation<Unit>
): Unit
abstract fun scheduleResumeAfterDelay(
    time: Int,
    continuation: CancellableContinuation<Unit>
): Unit

Schedules resume of a specified continuation after a specified delay time.