Is flow(retry or retryWhen ) good in a case that w...
# coroutines
p
Is flow(retry or retryWhen ) good in a case that we are waiting for a backend response until the response is ok? Let's say if we do 3 calls and is failure then error to the UI (Android) but if the first KO second KO and the thirth is OK return OK. Any other idea using Retrofit2?
t
I did this exact thing. I'm sure there's a clean interceptor for retrofit as well, but this felt really magical and nice https://pl.kotl.in/fIiADddzX
👍 1
I think of it as retryWhen "starts the flow over" for downstream consumers. Under the covers, the flow subscription(is that the right Kotlin term) was canceled, and a new subscription was started. So make sure the makeQuery func sets up anything it needs(and isn't relying on inbound state somehow)
p
But the thing is that I want this specific call to use that methodology, not all, if I create an interceptor it will do it for all the calls, right?
Also read something about WorkManager, perhaps is a good fit for this @taer?
t
Think you're right. Interceptor would be for all calls on that instance of the client(can always have more than one okhttp client configured differently). The flow retry would only apply where you attached it. No idea about workmanager.