diff --git a/backend/mirai-console/src/util/CoroutineScopeUtils.kt b/backend/mirai-console/src/util/CoroutineScopeUtils.kt index 490bbfe73..99e760d6c 100644 --- a/backend/mirai-console/src/util/CoroutineScopeUtils.kt +++ b/backend/mirai-console/src/util/CoroutineScopeUtils.kt @@ -68,13 +68,19 @@ internal class TimedTask( // `delay` always checks for cancellation lastChangedTime.loop { last -> val current = currentTimeMillis() - if (current - last > intervalMillis) { - if (!lastChangedTime.compareAndSet(last, UNCHANGED)) return@loop - action() + if (last == UNCHANGED) { + runIgnoreException { + delay(3.seconds) // accuracy not necessary + } ?: return@launch + } else { + if (current - last > intervalMillis) { + if (!lastChangedTime.compareAndSet(last, UNCHANGED)) return@loop + action() + } + runIgnoreException { + delay(3.seconds) // accuracy not necessary + } ?: return@launch } - runIgnoreException { - delay(3.seconds) // accuracy not necessary - } ?: return@launch } } }