Package-level declarations

Types

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

A fixed time budget that starts counting down at construction.

Link copied to clipboard
class RateLimiter(val permits: Int, val per: Duration, timeSource: TimeSource.WithComparableMarks = TimeSource.Monotonic)

A sliding-window rate limiter that grants at most permits acquisitions within any window of length per.

Link copied to clipboard
class Stopwatch(timeSource: TimeSource.WithComparableMarks = TimeSource.Monotonic)

A stopwatch that accumulates elapsed time across start and stop cycles.

Functions

Link copied to clipboard

Returns the average of all durations.

Link copied to clipboard
fun backoffSequence(initialDelay: Duration, factor: Double = 2.0, maxDelay: Duration = Duration.INFINITE): Sequence<Duration>

Returns an infinite sequence of exponentially growing backoff delays.

Link copied to clipboard

Formats this duration as a colon-separated clock string, such as "01:23:45".

Link copied to clipboard

Formats this duration as hours, minutes, and seconds, such as "1h 23m 45s".

Link copied to clipboard
fun Duration.humanReadable(maxParts: Int = 2): String

Formats this duration as its most significant components, such as "1h 23m".

Link copied to clipboard

Parses a clock string produced by formatClock back into a Duration.

Link copied to clipboard

Parses a clock string produced by formatClock, or returns null when text is not valid.

Link copied to clipboard
suspend fun pollUntil(interval: Duration, timeout: Duration, condition: suspend () -> Boolean): Boolean

Polls condition until it returns true or timeout elapses, and reports whether it became true.

Link copied to clipboard

Rounds this duration to the nearest whole hour.

Link copied to clipboard

Rounds this duration to the nearest whole minute.

Link copied to clipboard

Rounds this duration to the nearest whole second.

Link copied to clipboard

Returns the sum of all durations, or Duration.ZERO for an empty iterable.

Link copied to clipboard
suspend fun <T> withMinimumDuration(minimum: Duration, timeSource: TimeSource.WithComparableMarks = TimeSource.Monotonic, block: suspend () -> T): T

Runs block and then delays so the whole call takes at least minimum.