Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
@Composable
fun TimerScreen() {
val scope = rememberCoroutineScope()
var job: Job? by remember {
mutableStateOf(null)
}
Column {
Button(onClick = {
job = scope.launch {
try {
println("Timer started")
startTimer(5000) {
println("Timer ended")
}
} catch (ex: Exception) {
println("timer cancelled")
}
}
}) {
Text("Start Timer")
}
Spacer(Modifier.height(20.dp))
Button(onClick = {
println("Cancelling timer")
job?.cancel()
}) {
Text("Cancel Timer")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment