-
-
Save belinwu/f7f03cae52bc9f3cc3ef19571ba27a6a to your computer and use it in GitHub Desktop.
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
/* Copyright 2022 Google LLC. | |
SPDX-License-Identifier: Apache-2.0 */ | |
inline fun <T> Flow<T>.launchAndCollectIn( | |
owner: LifecycleOwner, | |
minActiveState: Lifecycle.State = Lifecycle.State.STARTED, | |
crossinline action: suspend CoroutineScope.(T) -> Unit | |
) = owner.lifecycleScope.launch { | |
owner.repeatOnLifecycle(minActiveState) { | |
collect { | |
action(it) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment