FunkyMuse
01/12/2021, 1:24 AMjefbit
01/12/2021, 1:43 AMgildor
01/12/2021, 2:00 AMFunkyMuse
01/12/2021, 8:33 AMgildor
01/12/2021, 8:43 AMgildor
01/12/2021, 8:44 AMFunkyMuse
01/12/2021, 8:45 AMgildor
01/12/2021, 8:46 AMBut the return type is flowSo you want a flow of those sealed classes?
gildor
01/12/2021, 8:48 AMFunkyMuse
01/12/2021, 8:51 AMgildor
01/12/2021, 8:53 AMI need to catch the throwable if it happensI really not sure that you should catch it though, probably crash is just fine for this case
gildor
01/12/2021, 8:54 AMgildor
01/12/2021, 8:54 AMviewModelScope.launch
if insert alredy suspend functionFunkyMuse
01/12/2021, 8:55 AMgildor
01/12/2021, 8:55 AMgildor
01/12/2021, 8:55 AMFunkyMuse
01/12/2021, 8:55 AMgildor
01/12/2021, 8:55 AMgildor
01/12/2021, 8:56 AMFunkyMuse
01/12/2021, 8:56 AMgildor
01/12/2021, 9:03 AMFunkyMuse
01/12/2021, 9:03 AMgildor
01/12/2021, 9:03 AMgildor
01/12/2021, 9:03 AMFunkyMuse
01/12/2021, 9:04 AMgildor
01/12/2021, 9:05 AMCoroutineScope.launchWithState(state: StateFlow, block: suspend () -> Unit): Job {
stateflow.value= Sealed.Loading
try {
block()
} catch (t: Throwable){
stateflow.value= Sealed.CallError(t)
} finally {
stateflow.value= Sealed.CallFinished
}
}
gildor
01/12/2021, 9:06 AMviewModelScope.launchWithState(stateflow) {
dao.insert(model)
}
FunkyMuse
01/12/2021, 9:06 AMgildor
01/12/2021, 9:06 AMgildor
01/12/2021, 9:07 AMgildor
01/12/2021, 9:08 AMFunkyMuse
01/12/2021, 9:09 AMgildor
01/12/2021, 9:11 AMgildor
01/12/2021, 9:12 AMFunkyMuse
01/12/2021, 9:21 AMViewModel.viewModelSupervisorIOSupervised(crossinline function: suspend () -> Unit) {
viewModelScope.launch(ioDispatcher) {
supervisorScope {
function()
}
}
}
what about this?gildor
01/12/2021, 9:22 AMgildor
01/12/2021, 9:22 AM