Florian Walther (live streaming)
01/05/2022, 12:25 PMSystemClock.elapsedRealtime
in a test.Florian Walther (live streaming)
01/05/2022, 12:25 PMfun startTimer(
millisInFuture: Long,
countDownInterval: Long,
onTick: (millisUntilFinished: Long) -> Unit,
onFinish: () -> Unit,
) {
millisUntilFinished = millisInFuture
timerJob = scope.launch {
val startTime = timeSource.elapsedRealTime
val targetTime = startTime + millisInFuture
while (true) {
if (timeSource.elapsedRealTime < targetTime) {
delay(countDownInterval)
millisUntilFinished = targetTime - timeSource.elapsedRealTime
onTick(millisUntilFinished)
} else {
onFinish()
}
}
}
}
Florian Walther (live streaming)
01/05/2022, 12:26 PMdelay
is not exactFlorian Walther (live streaming)
01/05/2022, 12:27 PMlouiscad
01/05/2022, 12:42 PMFlorian Walther (live streaming)
01/05/2022, 12:46 PMFlorian Walther (live streaming)
01/05/2022, 12:47 PMlouiscad
01/05/2022, 12:52 PMFlorian Walther (live streaming)
01/07/2022, 10:34 AM