mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-26 16:10:11 +08:00
Fix 100% CPU on start, fix #1193
This commit is contained in:
parent
852a546786
commit
6534b8177f
@ -68,16 +68,13 @@ internal class TimedTask(
|
|||||||
// `delay` always checks for cancellation
|
// `delay` always checks for cancellation
|
||||||
lastChangedTime.loop { last ->
|
lastChangedTime.loop { last ->
|
||||||
val current = currentTimeMillis()
|
val current = currentTimeMillis()
|
||||||
if (last == UNCHANGED) {
|
|
||||||
runIgnoreException<CancellationException> {
|
|
||||||
delay(3.seconds) // accuracy not necessary
|
|
||||||
} ?: return@launch
|
|
||||||
return@loop
|
|
||||||
}
|
|
||||||
if (current - last > intervalMillis) {
|
if (current - last > intervalMillis) {
|
||||||
if (!lastChangedTime.compareAndSet(last, UNCHANGED)) return@loop
|
if (!lastChangedTime.compareAndSet(last, UNCHANGED)) return@loop
|
||||||
action()
|
action()
|
||||||
}
|
}
|
||||||
|
runIgnoreException<CancellationException> {
|
||||||
|
delay(3.seconds) // accuracy not necessary
|
||||||
|
} ?: return@launch
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user