KT-58046 Promote time sources, time marks, measureTime to stable
This commit is contained in:
committed by
Space Team
parent
fd54706e1a
commit
bbb36ce501
@@ -15,8 +15,8 @@ import kotlin.jvm.JvmInline
|
||||
* @see [measureTime]
|
||||
* @see [measureTimedValue]
|
||||
*/
|
||||
@SinceKotlin("1.3")
|
||||
@ExperimentalTime
|
||||
@SinceKotlin("1.9")
|
||||
@WasExperimental(ExperimentalTime::class)
|
||||
public interface TimeSource {
|
||||
/**
|
||||
* Marks a point in time on this time source.
|
||||
@@ -29,8 +29,8 @@ public interface TimeSource {
|
||||
/**
|
||||
* A [TimeSource] that returns [time marks][ComparableTimeMark] that can be compared for difference with each other.
|
||||
*/
|
||||
@SinceKotlin("1.8")
|
||||
@ExperimentalTime
|
||||
@SinceKotlin("1.9")
|
||||
@WasExperimental(ExperimentalTime::class)
|
||||
public interface WithComparableMarks : TimeSource {
|
||||
override fun markNow(): ComparableTimeMark
|
||||
}
|
||||
@@ -60,8 +60,8 @@ public interface TimeSource {
|
||||
* This time mark implements [ComparableTimeMark] and therefore is comparable with other time marks
|
||||
* obtained from the same [TimeSource.Monotonic] time source.
|
||||
*/
|
||||
@ExperimentalTime
|
||||
@SinceKotlin("1.7")
|
||||
@SinceKotlin("1.9")
|
||||
@WasExperimental(ExperimentalTime::class)
|
||||
@JvmInline
|
||||
public value class ValueTimeMark internal constructor(internal val reading: ValueTimeMarkReading) : ComparableTimeMark {
|
||||
override fun elapsedNow(): Duration = MonotonicTimeSource.elapsedFrom(this)
|
||||
@@ -114,8 +114,8 @@ internal expect class ValueTimeMarkReading
|
||||
* Represents a time point notched on a particular [TimeSource]. Remains bound to the time source it was taken from
|
||||
* and allows querying for the duration of time elapsed from that point (see the function [elapsedNow]).
|
||||
*/
|
||||
@SinceKotlin("1.3")
|
||||
@ExperimentalTime
|
||||
@SinceKotlin("1.9")
|
||||
@WasExperimental(ExperimentalTime::class)
|
||||
public interface TimeMark {
|
||||
/**
|
||||
* Returns the amount of time passed from this mark measured with the time source from which this mark was taken.
|
||||
@@ -175,8 +175,8 @@ public interface TimeMark {
|
||||
/**
|
||||
* A [TimeMark] that can be compared for difference with other time marks obtained from the same [TimeSource.WithComparableMarks] time source.
|
||||
*/
|
||||
@SinceKotlin("1.8")
|
||||
@ExperimentalTime
|
||||
@SinceKotlin("1.9")
|
||||
@WasExperimental(ExperimentalTime::class)
|
||||
public interface ComparableTimeMark : TimeMark, Comparable<ComparableTimeMark> {
|
||||
public abstract override operator fun plus(duration: Duration): ComparableTimeMark
|
||||
public open override operator fun minus(duration: Duration): ComparableTimeMark = plus(-duration)
|
||||
@@ -221,7 +221,6 @@ public interface ComparableTimeMark : TimeMark, Comparable<ComparableTimeMark> {
|
||||
}
|
||||
|
||||
|
||||
@ExperimentalTime
|
||||
private class AdjustedTimeMark(val mark: TimeMark, val adjustment: Duration) : TimeMark {
|
||||
override fun elapsedNow(): Duration = mark.elapsedNow() - adjustment
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@ package kotlin.time
|
||||
import kotlin.math.sign
|
||||
|
||||
@SinceKotlin("1.3")
|
||||
@ExperimentalTime
|
||||
internal expect object MonotonicTimeSource : TimeSource.WithComparableMarks {
|
||||
override fun markNow(): TimeSource.Monotonic.ValueTimeMark
|
||||
fun elapsedFrom(timeMark: TimeSource.Monotonic.ValueTimeMark): Duration
|
||||
@@ -24,8 +23,8 @@ internal expect object MonotonicTimeSource : TimeSource.WithComparableMarks {
|
||||
*
|
||||
* @property unit The unit in which this time source's readings are expressed.
|
||||
*/
|
||||
@SinceKotlin("1.3")
|
||||
@ExperimentalTime
|
||||
@SinceKotlin("1.9")
|
||||
@WasExperimental(ExperimentalTime::class)
|
||||
public abstract class AbstractLongTimeSource(protected val unit: DurationUnit) : TimeSource.WithComparableMarks {
|
||||
/**
|
||||
* This protected method should be overridden to return the current reading of the time source expressed as a [Long] number
|
||||
@@ -149,8 +148,8 @@ public abstract class AbstractDoubleTimeSource(protected val unit: DurationUnit)
|
||||
* thus it's capable to represent a time range of approximately ±292 years.
|
||||
* Should the reading value overflow as the result of [plusAssign] operation, an [IllegalStateException] is thrown.
|
||||
*/
|
||||
@SinceKotlin("1.3")
|
||||
@ExperimentalTime
|
||||
@SinceKotlin("1.9")
|
||||
@WasExperimental(ExperimentalTime::class)
|
||||
public class TestTimeSource : AbstractLongTimeSource(unit = DurationUnit.NANOSECONDS) {
|
||||
private var reading: Long = 0L
|
||||
|
||||
|
||||
@@ -12,8 +12,8 @@ import kotlin.contracts.*
|
||||
*
|
||||
* The elapsed time is measured with [TimeSource.Monotonic].
|
||||
*/
|
||||
@SinceKotlin("1.3")
|
||||
@ExperimentalTime
|
||||
@SinceKotlin("1.9")
|
||||
@WasExperimental(ExperimentalTime::class)
|
||||
public inline fun measureTime(block: () -> Unit): Duration {
|
||||
contract {
|
||||
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
|
||||
@@ -27,8 +27,8 @@ public inline fun measureTime(block: () -> Unit): Duration {
|
||||
*
|
||||
* The elapsed time is measured with the specified `this` [TimeSource] instance.
|
||||
*/
|
||||
@SinceKotlin("1.3")
|
||||
@ExperimentalTime
|
||||
@SinceKotlin("1.9")
|
||||
@WasExperimental(ExperimentalTime::class)
|
||||
public inline fun TimeSource.measureTime(block: () -> Unit): Duration {
|
||||
contract {
|
||||
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
|
||||
@@ -44,8 +44,8 @@ public inline fun TimeSource.measureTime(block: () -> Unit): Duration {
|
||||
*
|
||||
* The elapsed time is measured with the specified `this` [TimeSource.Monotonic] instance.
|
||||
*/
|
||||
@SinceKotlin("1.7")
|
||||
@ExperimentalTime
|
||||
@SinceKotlin("1.9")
|
||||
@WasExperimental(ExperimentalTime::class)
|
||||
public inline fun TimeSource.Monotonic.measureTime(block: () -> Unit): Duration {
|
||||
contract {
|
||||
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
|
||||
@@ -63,8 +63,8 @@ public inline fun TimeSource.Monotonic.measureTime(block: () -> Unit): Duration
|
||||
* @property value the result of the action.
|
||||
* @property duration the time elapsed to execute the action.
|
||||
*/
|
||||
@SinceKotlin("1.3")
|
||||
@ExperimentalTime
|
||||
@SinceKotlin("1.9")
|
||||
@WasExperimental(ExperimentalTime::class)
|
||||
public data class TimedValue<T>(val value: T, val duration: Duration)
|
||||
|
||||
/**
|
||||
@@ -73,8 +73,8 @@ public data class TimedValue<T>(val value: T, val duration: Duration)
|
||||
*
|
||||
* The elapsed time is measured with [TimeSource.Monotonic].
|
||||
*/
|
||||
@SinceKotlin("1.3")
|
||||
@ExperimentalTime
|
||||
@SinceKotlin("1.9")
|
||||
@WasExperimental(ExperimentalTime::class)
|
||||
public inline fun <T> measureTimedValue(block: () -> T): TimedValue<T> {
|
||||
contract {
|
||||
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
|
||||
@@ -89,8 +89,8 @@ public inline fun <T> measureTimedValue(block: () -> T): TimedValue<T> {
|
||||
*
|
||||
* The elapsed time is measured with the specified `this` [TimeSource] instance.
|
||||
*/
|
||||
@SinceKotlin("1.3")
|
||||
@ExperimentalTime
|
||||
@SinceKotlin("1.9")
|
||||
@WasExperimental(ExperimentalTime::class)
|
||||
public inline fun <T> TimeSource.measureTimedValue(block: () -> T): TimedValue<T> {
|
||||
contract {
|
||||
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
|
||||
@@ -107,8 +107,8 @@ public inline fun <T> TimeSource.measureTimedValue(block: () -> T): TimedValue<T
|
||||
*
|
||||
* The elapsed time is measured with the specified `this` [TimeSource.Monotonic] instance.
|
||||
*/
|
||||
@SinceKotlin("1.7")
|
||||
@ExperimentalTime
|
||||
@SinceKotlin("1.9")
|
||||
@WasExperimental(ExperimentalTime::class)
|
||||
public inline fun <T> TimeSource.Monotonic.measureTimedValue(block: () -> T): TimedValue<T> {
|
||||
contract {
|
||||
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
|
||||
|
||||
Reference in New Issue
Block a user