Last active
November 28, 2022 06:53
-
-
Save manuelvicnt/127d88744c7f265328df9998c8d92a3b 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