KInterval

class KInterval(scope: CoroutineScope, val period: Duration?, block: suspend () -> Unit)(source)

A repeating interval that invokes block every period.

Port of the useInterval React hook.

val interval = KInterval(scope = viewModelScope, period = 1.seconds) {
println("tick")
}
// Stops:
interval.clear()

Pass null for period to create the interval in a paused state (call set later).

Parameters

scope

CoroutineScope that owns the interval job.

period

Time between invocations. Pass null to start paused.

block

Suspending action called on each tick.

Constructors

Link copied to clipboard
constructor(scope: CoroutineScope, period: Duration?, block: suspend () -> Unit)

Properties

Link copied to clipboard

Functions

Link copied to clipboard
fun clear()

Stops the interval.

Link copied to clipboard
fun set()

Starts the interval. No-op if period is null. Cancels any existing job first.