https://kotlinlang.org logo
#coroutines
Title
# coroutines
p

Pablo

10/02/2020, 10:12 AM
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

taer

10/02/2020, 1:46 PM
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

Pablo

10/03/2020, 8:15 AM
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

taer

10/03/2020, 3:24 PM
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.
8 Views