Florian
08/19/2021, 11:07 PMfixedRateTimer
function appropriate and accurate enough to create a countdown timer? And is there any problem with launching a coroutine inside the timer action block?
fun startTimer() {
timer?.cancel()
applicationScope.launch {
val selectedTask = selectedTask.first()
if (selectedTask != null) {
taskDao.updateLastActiveTimestamp(selectedTask.id, System.currentTimeMillis())
startTimerService()
timerRunningFlow.value = true
timer = fixedRateTimer(period = TICK_DELAY) {
applicationScope.launch {
taskDao.increaseMillisCompletedToday(selectedTask.id, TICK_DELAY)
}
}
}
}
}
ephemient
08/20/2021, 3:37 AMFlorian
08/20/2021, 9:14 AMGreg Hibberd
08/20/2021, 3:30 PMFlorian
08/20/2021, 5:26 PMephemient
08/20/2021, 5:46 PMFlorian
08/20/2021, 7:04 PMdelay
+ calculating the elapsedTime
difference to combat the imprecision of delay