Skip to content

Instantly share code, notes, and snippets.

@sproctor
Last active October 17, 2021 15:51
Show Gist options
  • Save sproctor/25f7db41252cf0ce450d2bf958a5427a to your computer and use it in GitHub Desktop.
Save sproctor/25f7db41252cf0ce450d2bf958a5427a to your computer and use it in GitHub Desktop.
launched effect example
@Composable
fun TimeDisplay(viewModel: TimeDisplayViewModel) {
val properties: Map<String, Long> by viewModel.properties.collectAsState()
var timeRemaining by rememeber { mutableStateOf(0) }
Text(timeRemaining.toString)
val timeProperty = properties["time"]
LaunchedEffect(timeProperty) {
val currentTime = System.currentTimeMillis()
while (timeProperty > currentTime) {
timeRemaining = timeProperty - currentTime
delay(1000L)
}
timeRemaining = 0L
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment