I have 2 stateFlow's in my viewModel. To collect them in fragment I have to launch coroutines 2 times as below:
lifecycleScope.launchWhenStarted {
stocksVM.quotes.collect {
if (it is Resource.Success) {
it.data?.let { list ->
quoteAdapter.submitData(list)
}
}
}
}
lifecycleScope.launchWhenStarted {
stocksVM.stockUpdate.collect {
log(it.data?.data.toString())
}
}
If I have more stateFlow's, I have to launch coroutines respectively. Is there a better way to handle multiple stateFlow's in my Fragment/Activity or wherever?