aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/utils/DelayedRun.kt
blob: 0fa9152cd0ad3d339897e3a721a5e209f709c158 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package at.hannibal2.skyhanni.utils

import kotlin.time.Duration

object DelayedRun {
    val map = mutableMapOf<() -> Any, SimpleTimeMark>()

    fun runDelayed(duration: Duration, run: () -> Unit) {
        map[run] = SimpleTimeMark.now() + duration
    }

    fun checkRuns() {
        map.entries.removeIf { (runnable, time) ->
            val inPast = time.isInPast()
            if (inPast) {
                runnable()
            }
            inPast
        }
    }
}