Skip to content

Instantly share code, notes, and snippets.

@droid-it
Last active September 28, 2021 11:23
Show Gist options
  • Save droid-it/e4aa27cfb3afd001415fcb94567e3bba to your computer and use it in GitHub Desktop.
Save droid-it/e4aa27cfb3afd001415fcb94567e3bba to your computer and use it in GitHub Desktop.
@Composable
fun TimerScreen() {
LaunchedEffect(key1 = Unit, block = {
try {
startTimer(5000L) { // start a timer for 5 secs
println("Timer ended")
}
} catch(ex: Exception) {
println("timer cancelled")
}
})
}
suspend fun startTimer(time: Long, onTimerEnd: () -> Unit) {
delay(timeMillis = time)
onTimerEnd()
}
@hoaithuonghg
Copy link

Hi,
How about the startTimer function will be implemented. I want to run the example. But I could not implement the function.

@droid-it
Copy link
Author

Hey, sorry for missing that piece out. You can refer to it in the updated gist above

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment