Last active
September 8, 2021 12:18
-
-
Save droid-it/ae56b48367b2cd12fb9739cc02f77d3b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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