withMinimumDuration

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.

When the block finishes early, the call delays for the difference, which keeps short operations behind a loading indicator from flickering. When the block takes minimum or longer no extra delay is added, and when the block throws, the exception propagates without any padding delay.

Parameters

minimum

the smallest total duration the call should take.

timeSource

the time source used to measure the block, TimeSource.Monotonic by default.