TimeSource

interface TimeSource(source)

A source of time for measuring time intervals.

The only operation provided by the time source is markNow. It returns a TimeMark, which can be used to query the elapsed time later.

In general, TimeSource may not be monotonic, which may result in a negative duration returned from TimeMark.elapsedNow for a TimeMark obtained from a particular TimeSource. The monotonicity is guaranteed for TimeSource.Monotonic.

Since Kotlin

1.9

See also

Inheritors

Types

Link copied to clipboard
object Companion
Since Kotlin 1.9
Link copied to clipboard

The most precise time source available in the platform.

Since Kotlin 1.9
Link copied to clipboard

A TimeSource that returns time marks that can be compared for difference with each other.

Since Kotlin 1.9

Functions

Link copied to clipboard
@JvmName(name = "fromTimeSource")
fun TimeSource.asClock(origin: Instant): Clock

Creates a Clock that uses the time mark at the moment of creation to determine how far the current moment is from the origin.

Since Kotlin 2.3
Link copied to clipboard
abstract fun markNow(): TimeMark

Marks a point in time on this time source.

Since Kotlin 1.9
Link copied to clipboard
inline fun TimeSource.measureTime(block: () -> Unit): Duration

Executes the given function block and returns the duration of the elapsed time interval.

Since Kotlin 1.9
Link copied to clipboard
inline fun <T> TimeSource.measureTimedValue(block: () -> T): TimedValue<T>

Executes the given function block and returns an instance of TimedValue class, containing both the result of function execution and the duration of the elapsed time interval.

Since Kotlin 1.9