I read that coroutine delays are not precise. What...
# coroutines
f
I read that coroutine delays are not precise. What will cause a
delay
to take longer than the specified time? And do you think this will work to get the actual passed time after a delay (for example for a countdown timer)?
Copy code
val timeBefore = SystemClock.elapsedRealtime()
delay(TICK_DELAY)
val timeAfter = SystemClock.elapsedRealtime()
val passedTime = timeAfter - timeBefore
l
measureTime { }
from the stdlib should suit your needs. If the Dispatcher, or the VM/machine is short on resources, as can be seen when your computer freezes, the actual delay will be longer than requested.
The computer/device going to sleep, or your app being paused can also lead to delay being longer than what requested.
f
thank you for the info!
measureTime
seems useful!