Deadline

class Deadline(val timeout: Duration, timeSource: TimeSource.WithComparableMarks = TimeSource.Monotonic)

A fixed time budget that starts counting down at construction.

Time is read from the given time source, which defaults to TimeSource.Monotonic. A non-positive timeout produces a deadline that is expired from the start. All state is captured at construction, so reading the properties is safe from any coroutine.

Constructors

Link copied to clipboard
constructor(timeout: Duration, timeSource: TimeSource.WithComparableMarks = TimeSource.Monotonic)

Properties

Link copied to clipboard

The time passed since construction, growing without bound past timeout.

Link copied to clipboard

Whether the deadline has expired.

Link copied to clipboard

The expired fraction of timeout, from 0.0 to 1.0.

Link copied to clipboard

The time left before expiry, floored at Duration.ZERO.

Link copied to clipboard

The full time budget this deadline was created with.

Functions

Link copied to clipboard
suspend fun await()

Suspends for the remaining time in a single delay.

Link copied to clipboard

Throws an IllegalStateException when the deadline has expired.

Link copied to clipboard
suspend fun <T> orNull(block: suspend () -> T): T?

Runs block bounded by the remaining time and returns null on expiry.