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 } } }