Remove time source since it is very usage specific
This commit is contained in:
parent
5ace88e01e
commit
95a7fb0203
@ -4,7 +4,7 @@ kotlin.code.style=official
|
|||||||
specifyKotlinAsDependency=false
|
specifyKotlinAsDependency=false
|
||||||
|
|
||||||
projectGroup=ru.dbotthepony.kommons
|
projectGroup=ru.dbotthepony.kommons
|
||||||
projectVersion=2.13.1
|
projectVersion=2.14.0
|
||||||
|
|
||||||
guavaDepVersion=33.0.0
|
guavaDepVersion=33.0.0
|
||||||
gsonDepVersion=2.8.9
|
gsonDepVersion=2.8.9
|
||||||
|
@ -1,53 +0,0 @@
|
|||||||
package ru.dbotthepony.kommons.util
|
|
||||||
|
|
||||||
interface ITimeSource {
|
|
||||||
val nanos: Long
|
|
||||||
val micros: Long get() = nanos / 1_000L
|
|
||||||
val millis: Long get() = nanos / 1_000_000L
|
|
||||||
val seconds: Double get() = (nanos / 1_000L) / 1_000_000.0
|
|
||||||
}
|
|
||||||
|
|
||||||
class JVMTimeSource : ITimeSource {
|
|
||||||
private val origin = System.nanoTime()
|
|
||||||
|
|
||||||
override val nanos: Long
|
|
||||||
get() = System.nanoTime() - origin
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
@JvmField
|
|
||||||
val INSTANCE = JVMTimeSource()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class ArtificialTimeSource(nanos: Long = 0L) : ITimeSource {
|
|
||||||
override var nanos: Long = nanos
|
|
||||||
private set
|
|
||||||
|
|
||||||
fun advance(nanos: Long) {
|
|
||||||
this.nanos += nanos
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class PausableTimeSource(private val parent: ITimeSource) : ITimeSource {
|
|
||||||
override val nanos: Long get() {
|
|
||||||
if (isPaused) {
|
|
||||||
return pausedSince - skipped
|
|
||||||
} else {
|
|
||||||
return parent.nanos - skipped
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private var isPaused = false
|
|
||||||
private var pausedSince = 0L
|
|
||||||
private var skipped = 0L
|
|
||||||
|
|
||||||
fun pause() {
|
|
||||||
if (!isPaused) {
|
|
||||||
isPaused = true
|
|
||||||
pausedSince = parent.nanos
|
|
||||||
} else {
|
|
||||||
isPaused = false
|
|
||||||
skipped += parent.nanos - pausedSince
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user