AbstractLongTimeSource

Common
JVM
JS
Native
1.9
abstract class AbstractLongTimeSource : WithComparableMarks
(source)

An abstract class used to implement time sources that return their readings as Long values in the specified unit.

Time marks returned by this time source can be compared for difference with other time marks obtained from the same time source.

Constructors

Common
JVM
JS
Native
1.0

<init>

An abstract class used to implement time sources that return their readings as Long values in the specified unit.

AbstractLongTimeSource(unit: DurationUnit)

Properties

Common
JVM
JS
Native
1.0

unit

The unit in which this time source's readings are expressed.

val unit: DurationUnit

Functions

Common
JVM
JS
Native
1.0

markNow

Marks a point in time on this time source.

open fun markNow(): ComparableTimeMark
Common
JVM
JS
Native
1.0

read

This protected method should be overridden to return the current reading of the time source expressed as a Long number in the unit specified by the unit property.

abstract fun read(): Long

Extension Functions

Common
JVM
JS
Native
1.9

measureTime

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

fun TimeSource.measureTime(block: () -> Unit): Duration
Common
JVM
JS
Native
1.9

measureTimedValue

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

fun <T> TimeSource.measureTimedValue(
    block: () -> T
): TimedValue<T>

Inheritors

Common
JVM
JS
Native
1.9

TestTimeSource

A time source that has programmatically updatable readings. It is useful as a predictable source of time in tests.

class TestTimeSource : AbstractLongTimeSource