main.misk.concurrent.FakeTicker.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of misk-testing Show documentation
Show all versions of misk-testing Show documentation
Open source application container in Kotlin
package misk.concurrent
import com.google.common.base.Ticker
import java.time.Duration
import java.util.concurrent.TimeUnit
import jakarta.inject.Inject
import jakarta.inject.Singleton
@Singleton
class FakeTicker @Inject constructor() : Ticker(), Sleeper {
private var nowNs = 0L
val nowMs: Long
get() = TimeUnit.NANOSECONDS.toMillis(nowNs)
override fun read() = nowNs
override fun sleep(duration: Duration) {
nowNs += duration.toNanos()
}
fun sleepMs(durationMs: Long) {
nowNs += TimeUnit.MILLISECONDS.toNanos(durationMs)
}
}