KStarbound/src/main/kotlin/ru/dbotthepony/kstarbound/util/ExecutionTimePacer.kt
2024-04-21 22:26:02 +07:00

15 lines
328 B
Kotlin

package ru.dbotthepony.kstarbound.util
import kotlinx.coroutines.delay
class ExecutionTimePacer(private val budget: Long, private val pause: Long) {
private var origin = System.nanoTime()
suspend fun measureAndSuspend() {
if (System.nanoTime() - origin >= budget) {
delay(pause)
origin = System.nanoTime()
}
}
}