Sudhir Singh Khanger
08/10/2020, 10:53 AMfun home(): Flow<HomeResponse> =
flow { emit(ApiService.home()) }.flowOn(<http://Dispatchers.IO|Dispatchers.IO>)
ViewModel
@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?wasyl
08/10/2020, 11:00 AMSudhir Singh Khanger
08/10/2020, 11:03 AMZach Klippenstein (he/him) [MOD]
08/10/2020, 3:36 PM