Skip to content

Instantly share code, notes, and snippets.

@droid-it
Last active September 8, 2021 12:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save droid-it/ae56b48367b2cd12fb9739cc02f77d3b to your computer and use it in GitHub Desktop.
Save droid-it/ae56b48367b2cd12fb9739cc02f77d3b to your computer and use it in GitHub Desktop.
@Composable
fun TimerScreen() {
val scope = rememberCoroutineScope()
Column {
Button(onClick = {
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")
scope.cancel()
}) {
Text("Cancel Timer")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment