
Lightweight coroutine-based countdown timer exposing StateFlow states (Idle, Running, Paused, Finished), periodic interval ticks, and controls for start, pause, resume, stop, and restart.
A lightweight, Coroutine-based CountDownTimer for Kotlin Multiplatform (Android, iOS, JVM, and Linux).
Add the dependency to your commonMain source set:
kotlin {
sourceSets {
commonMain.dependencies {
implementation("io.github.rezita:countdowntimer:1.0.0")
}
}
}val timer = CountDownTimer(
durationMs = 30000L,
intervalMs = 1000L
)
// Collect state
scope.launch {
timer.state.collect { state ->
when (state) {
is TimerState.Idle -> println("Idle")
is TimerState.Running -> println("Remaining: ${state.remainingMs}ms")
is TimerState.Paused -> println("Paused at: ${state.remainingMs}ms")
is TimerState.Finished -> println("Finished!")
}
}
}
// Control the timer
timer.start(scope)
// timer.pause()
// timer.resume(scope)
// timer.stop()
//timer.restart(scope)Licensed under the Apache License, Version 2.0. See LICENSE for details.
A lightweight, Coroutine-based CountDownTimer for Kotlin Multiplatform (Android, iOS, JVM, and Linux).
Add the dependency to your commonMain source set:
kotlin {
sourceSets {
commonMain.dependencies {
implementation("io.github.rezita:countdowntimer:1.0.0")
}
}
}val timer = CountDownTimer(
durationMs = 30000L,
intervalMs = 1000L
)
// Collect state
scope.launch {
timer.state.collect { state ->
when (state) {
is TimerState.Idle -> println("Idle")
is TimerState.Running -> println("Remaining: ${state.remainingMs}ms")
is TimerState.Paused -> println("Paused at: ${state.remainingMs}ms")
is TimerState.Finished -> println("Finished!")
}
}
}
// Control the timer
timer.start(scope)
// timer.pause()
// timer.resume(scope)
// timer.stop()
//timer.restart(scope)Licensed under the Apache License, Version 2.0. See LICENSE for details.