Timers

interface Timers

JavaScript Timers

Implements intrinsic JavaScript timers, at the familiar symbols setTimeout and setInterval; each method starts a timer task which is dispatched after a specified delay. Interval timers repeat their execution until canceled, while regular one-shot timers execute only once.

Note that parameters are reversed for the host-side versions of these methods. JavaScript setTimeout takes the callback value first, for example, and the delay second; setTimeout takes the delay first so that the callback can use Kotlin's lambda syntax.

 

Functions

Link copied to clipboard
abstract fun clearInterval(id: TimerId)

Cancels a repeated timer task previously scheduled with setTimeout.

Link copied to clipboard
abstract fun clearTimeout(id: TimerId)

Cancels a one-shot timer task previously scheduled with setTimeout.

Link copied to clipboard
abstract fun setInterval(delay: Long? = DEFAULT_TIMEOUT, callback: () -> Unit): TimerId

Schedules a callback to be called repeatedly, each time after a delay. This method takes a JVM callback.

abstract fun setInterval(delay: Long? = DEFAULT_TIMEOUT, vararg arg: Any?, callback: Value): TimerId

Schedules a callback to be called repeatedly, each time after a delay. This method variant takes a polyglot Value.

Link copied to clipboard
abstract fun setTimeout(delay: Long? = DEFAULT_TIMEOUT, callback: () -> Unit): TimerId

Schedules a callback to be called after a delay. This method takes a JVM callback.

abstract fun setTimeout(delay: Long? = DEFAULT_TIMEOUT, vararg arg: Any?, callback: Value): TimerId

Schedules a callback to be called after a delay. This method variant takes a polyglot Value.