I am running a network call as follows. Repository...
# coroutines
s
I am running a network call as follows. Repository
Copy code
fun home(): Flow<HomeResponse> =
        flow { emit(ApiService.home()) }.flowOn(<http://Dispatchers.IO|Dispatchers.IO>)
ViewModel
Copy code
@ExperimentalCoroutinesApi
fun home() {
    viewModelScope.launch {
        repository.home()
            .onStart { _homeLiveData.postValue(Resource.loading(null)) }
            .catch { _homeLiveData.postValue(Resource.error(it.message ?: "", null)) }
            .collect { _homeLiveData.postValue(Resource.success(it)) }
    }
}
Is there anything built-in in Flow that would ignore the repeated calling of
home()
method and let the existing request fail or reach success?
w
I think SharedFlow is the closest to what you’d like, but it’s not released yet. I’m not sure it’d support your use case exactly, but I don’t think there’s anything built-in right now
s
Thanks. In that I case I will enable/disable the button once I start the asynchronous work and get up to desired state.
z
`SharedFlow`/`StateFlow` could help here, but I think you’d still have another problem to solve. I’d suggest using a library like Dropbox’s Store (https://github.com/dropbox/Store) which handles this sort of debouncing for you.