Skip to content

Instantly share code, notes, and snippets.

@yoonseopshin
Created December 19, 2021 11:54
Show Gist options
  • Save yoonseopshin/407690ade765e3a93fdf49a62d7a97b9 to your computer and use it in GitHub Desktop.
Save yoonseopshin/407690ade765e3a93fdf49a62d7a97b9 to your computer and use it in GitHub Desktop.
Lifecycle flow extension
fun <T> ComponentActivity.collectLatestLifecycleFlow(flow: Flow<T>, collect: suspend (T) -> Unit) {
lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.STARTED) {
flow.collectLatest(collect)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment