Stylianos Gakis
08/13/2024, 2:30 PMCacheFirst
and I did it with smth like this:
return flow {
while (currentCoroutineContext().isActive) {
val result = apolloClient.query()...
when (result) {
is Fail -> { delay(10.seconds) }
is Success -> {
emit(result...)
break
}
}
}
}
But since I am now expecting two emissions, I am having a hard time imagining how to do this. I can no longer delay on any "Fail" responses, the cache miss could be one for example which I want to just ignore in this case.
Any thoughts? Have you done smth like this before? My first idea was to try and hold some local var responseCount = 0
right inside the flow {
block, and do ++
when I get a response, and set it back to 0 when the while loop loops, but I feel like I am making this more complicated than it should be.bod
08/13/2024, 4:08 PMCacheAndNetwork
makes this more complicated and I'd probably continue doing what you did previously without itStylianos Gakis
08/13/2024, 7:43 PMStylianos Gakis
08/14/2024, 9:28 AMreturn flow {
apolloClient
.query(..)
.fetchPolicy(FetchPolicy.CacheOnly)
.safeExecute()
.onRight {
emit(successvalue)
}
while (currentCoroutineContext().isActive) {
val result = apolloClient
.query(...)
.fetchPolicy(FetchPolicy.NetworkOnly)
.safeExecute()
when (result) {
Fail -> emit(fail); delay()
Success -> emit(result); break
}
}
}
And it's all good. I wanted to get fancy with flow stuff but no need tbh 😄bod
08/14/2024, 9:29 AM