Daniel Perez
04/26/2023, 7:43 PMA
to outlive scope B
and vice versa, so if either of them stop I need to stop all of their coroutines. Is this possible using the CoroutineScope()
factory function?kevin.cianfarini
04/26/2023, 7:46 PMsuspend fun foo() = coroutineScope {
launch { scopeA() }
launch { scopeB() }
}
suspend fun scopeA = coroutineScope { /* some work */ }
suspend fun scopeB = coroutineScope { /* some work */ }
Daniel Perez
04/26/2023, 7:54 PMkevin.cianfarini
04/26/2023, 7:56 PMDaniel Perez
04/26/2023, 8:06 PMlifecycleScope
I'm currently using to communicate changes from the parent UI/ViewModel with Flow
. This nested fragment must be able to survive configuration changes. Since it's nested, I need to stop propagating events to it when the parent UI get's torn down and recreated, so I want to use viewLifecycleOwner
.
The fragment survives configuration changes but it can also be torn down and replaced with a new one before a configuration change ever happens, hence my use case where it's lifecycleScope
could outlive the current viewLifecycleOwner
, but it also may not. In that case, the old Fragment actually get's leaked when we use the viewLifecycleOwner.lifecycleScope
to observe the changes and then it crashes.
I know I could just use the Job
that gets returned from the launch
method, but I wanted to ask anyways if this was possible by "combining" coroutine scopes and catering to the lowest common denominatorkevin.cianfarini
04/26/2023, 8:20 PMlifecycleScope
at all. I fear I won’t be of much help.Daniel Perez
04/26/2023, 8:21 PMgildor
04/27/2023, 6:44 AMgildor
04/27/2023, 6:47 AMI have a nested fragment from a 3rd party library whoseI’m currently using to communicate changes from the parent UI/ViewModel withlifecycleScope
Flow
gildor
04/27/2023, 6:48 AM