Skip to content

Instantly share code, notes, and snippets.

@yoonseopshin
Created December 19, 2021 11:54
Show Gist options
  • Select an option

  • Save yoonseopshin/407690ade765e3a93fdf49a62d7a97b9 to your computer and use it in GitHub Desktop.

Select an option

Save yoonseopshin/407690ade765e3a93fdf49a62d7a97b9 to your computer and use it in GitHub Desktop.

Revisions

  1. yoonseopshin created this gist Dec 19, 2021.
    7 changes: 7 additions & 0 deletions FlowExt.kt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    fun <T> ComponentActivity.collectLatestLifecycleFlow(flow: Flow<T>, collect: suspend (T) -> Unit) {
    lifecycleScope.launch {
    repeatOnLifecycle(Lifecycle.State.STARTED) {
    flow.collectLatest(collect)
    }
    }
    }