CountDownTimer KMP
A lightweight, Coroutine-based CountDownTimer for Kotlin Multiplatform (Android, iOS, JVM, and Linux).
Installation
Add the dependency to your commonMain source set:
kotlin {
sourceSets {
commonMain.dependencies {
implementation("io.github.rezita:countdowntimer:1.0.0")
}
}
}
Usage
val timer = CountDownTimer(
durationMs = 30000L,
intervalMs = 1000L
)
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!")
}
}
}
timer.start(scope)
License
Licensed under the Apache License, Version 2.0. See LICENSE for details.