fun wait(){
val timeout= TimeHelper.getNow() + timeoutInterval // <- part of class constructor
if(processor.getLag() > 0){
val currentTIme = TimeHelper.getNow()
if(currentTime >= timeout){ System.exit(42) }
Thread.sleep(someTime)
}
}
And want to use a coroutine
runBlocking
and
delay
, would it be something like
Copy code
fun wait() = runBlocking{
launch { delayMethod() }
if(processor.getLag() > 0){
val currentTIme = TimeHelper.getNow()
if(currentTime >= timeout){ System.exit(42) }
}
}
suspend fun delayMethod(){
delay(someTime)
}
g
gildor
12/05/2022, 6:41 AM
No, it’s incorrect, launch returns immediately, remove launch it will suspend on someTime
gildor
12/05/2022, 6:41 AM
so essentially delay is the same as Thread.sleep but non blocking, but requires suspend block (in your case it’s runBlocking)
gildor
12/05/2022, 6:42 AM
but in general, it’s not very clear why have blocking function for this