From 6534b8177f6ae8e8c6c2de928e0430bc809e60b7 Mon Sep 17 00:00:00 2001 From: Him188 Date: Fri, 16 Apr 2021 12:52:10 +0800 Subject: [PATCH] Fix 100% CPU on start, fix #1193 --- backend/mirai-console/src/util/CoroutineScopeUtils.kt | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/backend/mirai-console/src/util/CoroutineScopeUtils.kt b/backend/mirai-console/src/util/CoroutineScopeUtils.kt index 8d12eeae4..490bbfe73 100644 --- a/backend/mirai-console/src/util/CoroutineScopeUtils.kt +++ b/backend/mirai-console/src/util/CoroutineScopeUtils.kt @@ -68,16 +68,13 @@ internal class TimedTask( // `delay` always checks for cancellation lastChangedTime.loop { last -> val current = currentTimeMillis() - if (last == UNCHANGED) { - runIgnoreException { - delay(3.seconds) // accuracy not necessary - } ?: return@launch - return@loop - } if (current - last > intervalMillis) { if (!lastChangedTime.compareAndSet(last, UNCHANGED)) return@loop action() } + runIgnoreException { + delay(3.seconds) // accuracy not necessary + } ?: return@launch } } }