Vincent Williams
08/20/2020, 4:52 PMprivate fun subscribeToViewModel() = lifecycleScope.launch(Dispatchers.Main) {
viewModel.viewState.collect { onViewStateEvent(it) }
viewModel.navigationEvents.collect { onNavigationEvent(it) }
}
This code doesnt seem to work. It only collects the first flow. Do I need to have two separate launch statements? Is there an easier way to do this as it gets a little messy with 3 or 4 flowslouiscad
08/20/2020, 5:13 PMonEach and launchInVincent Williams
08/20/2020, 5:20 PMlouiscad
08/20/2020, 5:56 PMVincent Williams
08/20/2020, 6:54 PMVincent Williams
08/20/2020, 6:54 PMlouiscad
08/20/2020, 6:55 PMcollect suspends while collecting itemslouiscad
08/20/2020, 6:57 PMlaunch + collect is equivalent to onEach + launchIn, unless you care about each CPU cycle, in which case there's a very very tiny difference. So I'd pick onEach + launchIn when more convenient.Vincent Williams
08/20/2020, 6:59 PMcatch instead of the coroutine exception handlerVincent Williams
08/20/2020, 6:59 PMlouiscad
08/20/2020, 7:00 PMVincent Williams
08/20/2020, 7:01 PM