Created
September 8, 2021 11:41
-
-
Save droid-it/dbee6d661f1a9e8d8a1737c3d54fad94 to your computer and use it in GitHub Desktop.
This file contains hidden or 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() | |
| 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