Skip to content

Instantly share code, notes, and snippets.

@wajahatkarim3
Created February 14, 2022 16:00
Show Gist options
  • Select an option

  • Save wajahatkarim3/61c87f17279707cfb410845dfcabb792 to your computer and use it in GitHub Desktop.

Select an option

Save wajahatkarim3/61c87f17279707cfb410845dfcabb792 to your computer and use it in GitHub Desktop.
Timer in Composables
@Composable
fun SomeComposableViewHere() {
val scope = rememberCoroutineScope()
scope.launch {
try {
startTimer(flipDurationMs.toLong()) {
// Timer Ended. Do something here
}
} catch(ex: Exception) {
// Timer Cancelled.
ex.printStackTrace()
}
}
}
private suspend fun startTimer(time: Long, onTimerEnd: () -> Unit) {
delay(timeMillis = time)
onTimerEnd()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment