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
|
// `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
|
||||||
|
} else {
|
||||||
if (current - last > intervalMillis) {
|
if (current - last > intervalMillis) {
|
||||||
if (!lastChangedTime.compareAndSet(last, UNCHANGED)) return@loop
|
if (!lastChangedTime.compareAndSet(last, UNCHANGED)) return@loop
|
||||||
action()
|
action()
|
||||||
@ -77,6 +82,7 @@ internal class TimedTask(
|
|||||||
} ?: return@launch
|
} ?: return@launch
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun CoroutineScope.launchTimedTask(
|
internal fun CoroutineScope.launchTimedTask(
|
||||||
|
Loading…
Reference in New Issue
Block a user