Fix 100% CPU on start, fix #1193

This commit is contained in:
Him188 2021-04-16 12:52:10 +08:00
parent 852a546786
commit 6534b8177f

View File

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