Skip to content

Instantly share code, notes, and snippets.

@fergusonm
Created March 29, 2021 14:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fergusonm/14621a5833ba1093d03cb3df09271c53 to your computer and use it in GitHub Desktop.
Save fergusonm/14621a5833ba1093d03cb3df09271c53 to your computer and use it in GitHub Desktop.
Compact flowWithLifecycle
fun <T> Flow<T>.collectIn(
lifecycleOwner: LifecycleOwner,
minActiveState: Lifecycle.State = Lifecycle.State.STARTED,
action: suspend (T) -> Unit
): Job = lifecycleOwner.lifecycleScope.launch {
flowWithLifecycle(lifecycleOwner.lifecycle, minActiveState).collect(action)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment