Hello Guys, How to make an automatic retry mechan...
# android
n
Hello Guys, How to make an automatic retry mechanism for retrofit API calls with Kotlin coroutines. Previously I was using RxJava for doing this. Is there any way to do this with coroutines? Thanks in Advance
Also, if you've questions like that about coroutines/flow, post them in #coroutines or #flow channel
n
Thanks for your reply. Do we have a CallAdapterFactory for Flow?
m
I don't think there is a one provided by default, see why: https://github.com/square/retrofit/issues/3497 But if you really need to, you can google it & you will find a plethora of tutorials online that can help you making a custom
CallAdapter.Factory
m
Retrying would probably be easier with suspend functions. Call the Retrofit function, if it fails check the failure reason and decide if you want to retry. If you do, do any delaying you want and then retry again. You could wrap the created RetrofitApi with another one that has retrying built in if you don’t want each caller to have to deal with retries.
325 Views