blob: ad6e9f7fba1a3371e928803a4c22f21bd04876ea (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
/*
* SPDX-FileCopyrightText: 2023 Linnea Gräf <nea@nea.moe>
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package moe.nea.firmament.util
import kotlin.time.Duration
import kotlin.time.ExperimentalTime
import kotlin.time.TimeSource
@OptIn(ExperimentalTime::class)
class Timer {
private var mark: TimeSource.Monotonic.ValueTimeMark? = null
fun timePassed(): Duration {
return mark?.elapsedNow() ?: Duration.INFINITE
}
fun markNow() {
mark = TimeSource.Monotonic.markNow()
}
fun markFarPast() {
mark = null
}
}
|