mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-10 10:30:13 +08:00
Fix TimedTask if not changed
This commit is contained in:
parent
2636cad32d
commit
c96eb3ccf1
@ -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<CancellationException> {
|
||||
delay(3.seconds) // accuracy not necessary
|
||||
} ?: return@launch
|
||||
} else {
|
||||
if (current - last > intervalMillis) {
|
||||
if (!lastChangedTime.compareAndSet(last, UNCHANGED)) return@loop
|
||||
action()
|
||||
}
|
||||
runIgnoreException<CancellationException> {
|
||||
delay(3.seconds) // accuracy not necessary
|
||||
} ?: return@launch
|
||||
}
|
||||
runIgnoreException<CancellationException> {
|
||||
delay(3.seconds) // accuracy not necessary
|
||||
} ?: return@launch
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user