Hi. I have a question about Flow. I have a functio...
# coroutines
l
Hi. I have a question about Flow. I have a function in my ViewModel that fire an http call. I’d like to refresh the data when the activity attached to the viewModel goes in the onResume callback - so re-executing an http call. Atm the http call is not executed on the second request
Copy code
fun callService() { 
    viewModelScope.launch {
        repository.getData().collect {
            // Update state. Called only once :(
        }
    }
}
s
Looks like (from the name) that getData() is a one-shot function, it returns one value. The getData() should be a plain suspend fun (not return a Flow) and the result of getData() should then be assigned to another Flow.
stateFlow.update { oldState -> calcState(oldState, repository.getData()) }
l
Yeah I just figured out ! Make sens tho. Thanks
👍 1