Created
March 29, 2022 13:31
-
-
Save kairos34/180992981a5f0dc6f1d26c572fea2e82 to your computer and use it in GitHub Desktop.
Collect flow lifecycle aware way extension function
This file contains hidden or 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> Fragment.collectLifecycleFlow(flow: Flow<T>, collect: suspend (T) -> Unit){ | |
viewLifecycleOwner.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