Fix TimedTask if not changed

This commit is contained in:
Him188 2021-04-16 13:03:06 +08:00
parent 2636cad32d
commit c96eb3ccf1

View File

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