delay

suspend fun delay(timeMillis: Long)(source)

Delays coroutine for at least the given time without blocking a thread and resumes it after a specified time. If the given timeMillis is non-positive, this function returns immediately.

This suspending function is cancellable: if the Job of the current coroutine is cancelled while this suspending function is waiting, this function immediately resumes with CancellationException. There is a prompt cancellation guarantee: even if this function is ready to return the result, but was cancelled while suspended, CancellationException will be thrown. See suspendCancellableCoroutine for low-level details.

If you want to delay forever (until cancellation), consider using awaitCancellation instead.

Note that delay can be used in select invocation with onTimeout clause.

Implementation note: how exactly time is tracked is an implementation detail of CoroutineDispatcher in the context.

Parameters

timeMillis

time in milliseconds.


suspend fun delay(duration: Duration)(source)

Delays coroutine for at least the given duration without blocking a thread and resumes it after the specified time. If the given duration is non-positive, this function returns immediately.

This suspending function is cancellable: if the Job of the current coroutine is cancelled while this suspending function is waiting, this function immediately resumes with CancellationException. There is a prompt cancellation guarantee: even if this function is ready to return the result, but was cancelled while suspended, CancellationException will be thrown. See suspendCancellableCoroutine for low-level details.

If you want to delay forever (until cancellation), consider using awaitCancellation instead.

Note that delay can be used in select invocation with onTimeout clause.

Implementation note: how exactly time is tracked is an implementation detail of CoroutineDispatcher in the context.