Skip to content

Instantly share code, notes, and snippets.

@droid-it
Created September 8, 2021 11:41
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save droid-it/dbee6d661f1a9e8d8a1737c3d54fad94 to your computer and use it in GitHub Desktop.
@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