I am using Moya to handle HTTP operations and normally I have an refreshToken()
. I am checking token if expired or not when a request is about happen but the problem is there can be a scenarios that more than one requests. If they are chained with nested types it is not a problem however, it is not likely all the time.
To be more clear lets say I have request1()
and request2()
and assume that they execute separate operations and can be triggered anytime(for instance one is called in a viewDidLoad()
, other one is called in another viewDidLoad()
). when this happens and if the token is expired, my refresh request fails. (statusCode: 400)
So, my question is, how can I make provider to wait refresh()
operation get done?I mean by provider is other endpoints. I want them to wait refresh()
endpoint if it is on.
I will be very appreciated if you suggest a way that will make this easier.