I need to call some function after x seconds elapsed exactly.
How would I do this in Kotlin?
I've tried with using :
GlobalScope.launch
{
val seconds = 5
val duration = (seconds * 1000).toLong()
delay(duration)
callTheFunction ()
}
but based on my measurements looks like it's sometimes accurate and sometimes not. Am I using it in the wrong way or is there a better way to do it?