Florian
01/30/2021, 10:43 AMNetworkBoundResource
. The problem right now is that Loading
doesn't emit any database updates. Would it be possible to change this in a way that Loading
emits DB updates while the remote fetch is in progress?
flow {
val data = query().first()
val flow = if (shouldFetch(data)) {
emit(Resource.Loading(data))
try {
saveFetchResult(fetch())
onFetchSuccess()
query().map { Resource.Success(it) }
} catch (t: Throwable) {
onFetchFailed(t)
query().map { Resource.Error(t, it) }
}
} else {
query().map { Resource.Success(it) }
}
emitAll(flow)
}