Explorar o código

Fix 100% CPU on start, fix #1193

Him188 %!s(int64=4) %!d(string=hai) anos
pai
achega
6534b8177f
Modificáronse 1 ficheiros con 3 adicións e 6 borrados
  1. 3 6
      backend/mirai-console/src/util/CoroutineScopeUtils.kt

+ 3 - 6
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<CancellationException> {
-                    delay(3.seconds) // accuracy not necessary
-                } ?: return@launch
-                return@loop
-            }
             if (current - last > intervalMillis) {
                 if (!lastChangedTime.compareAndSet(last, UNCHANGED)) return@loop
                 action()
             }
+            runIgnoreException<CancellationException> {
+                delay(3.seconds) // accuracy not necessary
+            } ?: return@launch
         }
     }
 }