Orhan Tozan
11/02/2021, 10:32 AM// Listen to multiple flows
lifecycleScope.launch {
lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED) {
// As collect is a suspend function, if you want to collect
// multiple flows in parallel, you need to do so in
// different coroutines
launch {
flow1.collect { /* Do something */ }
}
launch {
flow2.collect { /* Do something */ }
}
}
}
Is there anything wrong with doing this instead? :
// Listen to multiple flows
lifecycleScope.launch {
lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED) {
// As collect is a suspend function, if you want to collect
// multiple flows in parallel, you need to do so in
// different coroutines
launch {
flow1.collect { /* Do something */ }
}
}
}
lifecycleScope.launch {
lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED) {
launch {
flow2.collect { /* Do something */ }
}
}
}
Adam Powell
11/02/2021, 2:36 PMrepeatOnLifecycle
block is only doing one thing at a time, other than that, yeah that's fineIllustrator
11/04/2021, 3:40 AMAdam Powell
11/04/2021, 3:45 AMlaunchWhenStarted
altogether. It was a bit of a failed experiment and will be removed in a future release eventually.