KTimer
A cancellable one-shot timer that fires block after delay.
Port of the useTimeout React hook.
val timer = KTimer(scope = viewModelScope, delay = 2.seconds) {
println("fired!")
}
// Runs automatically. To restart:
timer.reset()
// To stop:
timer.clear()Content copied to clipboard
Parameters
scope
CoroutineScope that owns the timer job.
delay
How long to wait before firing block. Pass null to start paused.
block
Suspending action called once when the timer fires.