K Merle
01/17/2022, 5:45 AMcombine(
flowOne(),
flowTwo(),
flowThree()
) { _, _, flowThree->
flowThree
}.stateIn(
viewModelScope + ioDispatcher,
SharingStarted.WhileSubscribed(NETWORK_RESULT_SHARING_TIMEOUT),
Result.Loading
)
Should flowThree
emit values here when collected? FlowThree should emit every time flowOne() or flowTwo() emit values.combine(flowOne(), flowTwo()) { _, _ -> }.flatMapLatest {
flowThree()
}.stateIn(
viewModelScope + ioDispatcher,
SharingStarted.WhileSubscribed(NETWORK_RESULT_SHARING_TIMEOUT),
Result.Loading
)
gildor
01/17/2022, 5:52 AMFrancesc
01/17/2022, 5:53 AMgildor
01/17/2022, 5:54 AMK Merle
01/17/2022, 5:55 AMflowThree()
is network request.Francesc
01/17/2022, 5:55 AMgildor
01/17/2022, 5:55 AMFrancesc
01/17/2022, 5:57 AMgildor
01/17/2022, 6:00 AMI do want to restart asJust a question, why do you need flow for this, wouldn’t suspend function be more clear? because you would replace flatMapLatest with mapLatest/map (depedning on your use case) and it would be clear that it require restart every time, just as any other function callis network request.flowThree()
K Merle
01/17/2022, 6:01 AMgildor
01/17/2022, 6:05 AMviewModelScope + ioDispatcher
And one more point. Why do you need io dispatcher for this?K Merle
01/17/2022, 6:05 AMgildor
01/17/2022, 6:05 AMK Merle
01/17/2022, 6:05 AMgildor
01/17/2022, 6:05 AMK Merle
01/17/2022, 6:06 AMgildor
01/17/2022, 6:06 AMK Merle
01/17/2022, 6:08 AMgildor
01/17/2022, 6:12 AMgood practice in general to put everything to an IO by defaultI think it’s depends what is everything, you do not wrap everything to io if those operations are non blocking and the only operation which will run on IO is collection of them In our code we prefer to handle all CPU heavy/IO blocking operations on level of suspend functions, flow builders, and do not allow them to leak further, otherwise you don’t really cannot believe to any suspend function to be called from main thread or even any suspend function
K Merle
01/17/2022, 6:15 AM