Since `Clock` and `Instant` are about to go stable...
# coroutines
k
Since
Clock
and
Instant
are about to go stable in the stdlib, is there any willingness to add a Clock implementation in the test coroutines artifact that reflects the current time of the test scheduler?
plus one 3
I've implemented something like this in numerous projects. Would be great to have it out of the box since this stuff is in the stdlib now.
Copy code
@OptIn(ExperimentalCoroutinesApi::class)
@ExperimentalTime
private class TestClock(private val scheduler: TestCoroutineScheduler) : Clock {
    override fun now() = Instant.fromEpochMilliseconds(scheduler.currentTime)
}

@ExperimentalTime
val TestScope.testClock: Clock get() = TestClock(testScheduler)
h
It is since Kotlin 2.2.20-Beta2: `testTimeSource.asClock(origin = Instant.parse("2025-02-09T051105.005Z"))`: https://youtrack.jetbrains.com/issue/KT-76394/kotlin.time.TimeSource.asClock-missing
👍 1
k
Neat!