Heartbeat

class Heartbeat(startDelay: Duration = Duration.ZERO, period: Duration, coroutineContext: CoroutineContext, task: () -> Unit)

Utility class to trigger a task at a regular intervals.

Parameters

startDelay

The initial delay before the first execution of task.

period

The period between two executions of task.

coroutineContext

The coroutine context in which Heartbeat is run.

task

The task to execute at regular intervals.

Constructors

Link copied to clipboard
constructor(startDelay: Duration = Duration.ZERO, period: Duration, coroutineContext: CoroutineContext, task: () -> Unit)

Functions

Link copied to clipboard
fun start(restart: Boolean = true)

Start the execution of this heartbeat. Does nothing if it is already running and restart is false.

Link copied to clipboard
fun stop()

Stop the execution of this heartbeat.