Created
March 29, 2021 14:48
-
-
Save fergusonm/14621a5833ba1093d03cb3df09271c53 to your computer and use it in GitHub Desktop.
Compact flowWithLifecycle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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