All Downloads are FREE. Search and download functionalities are using the official Maven repository.

main.misk.concurrent.FakeTicker.kt Maven / Gradle / Ivy

There is a newer version: 2024.09.17.200749-4708422
Show newest version
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)
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy