mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-10 18:40:15 +08:00
Fix TimedTask if not changed
This commit is contained in:
parent
2636cad32d
commit
c96eb3ccf1
@ -68,6 +68,11 @@ 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
|
||||
} else {
|
||||
if (current - last > intervalMillis) {
|
||||
if (!lastChangedTime.compareAndSet(last, UNCHANGED)) return@loop
|
||||
action()
|
||||
@ -77,6 +82,7 @@ internal class TimedTask(
|
||||
} ?: return@launch
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal fun CoroutineScope.launchTimedTask(
|
||||
|
Loading…
Reference in New Issue
Block a user