Stylianos Gakis
08/05/2025, 11:37 AMStylianos Gakis
08/05/2025, 11:37 AMreturn flow {
var didReturnSuccessfulResponse = false
while (!didReturnSuccessfulResponse) {
apolloClient
.query(...)
.fetchPolicy(FetchPolicy.NetworkOnly)
...
.collect {
if (it.isRight()) {
didReturnSuccessfulResponse = true
}
emit(it)
}
delay(5.seconds)
}
}
Stylianos Gakis
08/05/2025, 11:37 AM.retry
flow operator, but that seems to work only when there are exceptions involved, so I do not think this is what I want hereStylianos Gakis
08/05/2025, 11:40 AMretryWhen
or retry
feel like the perfect API here to wrap this sort of looping logic, but for me to be able to use em I'd need to instead throw
inside of my mapping function or something like that, which feels like the wrong thing to do here.
Are there any smarter ideas here or is my silly while loop
the best I can do?mbonnin
08/05/2025, 12:18 PMwhile-loop
. I think retry {}
is misleading actually. Exceptions shouldn't be used for flow control as they are expensive and type-unsafeStylianos Gakis
08/05/2025, 2:02 PMretryWhen
sort of flow operator which restarts the flow, but on a predicate which is not an exception would be nice.
The predicate could be on the emitted values instead.
But in any case, the simple loop looks to be working fine for me, so I will keep it nice and simple here ^^bod
08/05/2025, 2:03 PMmbonnin
08/05/2025, 2:05 PMtakeWhile {}
+ onCompletion {}
might be able to help but TBH, I feel it's one of those cases like when everyone was flatMapping{}, apply{}, run {}, etc...
in the early days of Kotlin when in the end, it's just a for loopmbonnin
08/05/2025, 2:05 PM