Learning RxSwift - Here's my Problem:
i have a webservice that fetches data using an active access token, whenever the token expired , then first call the token generate api and then call the current request to run again. so that it will have an active access token to valid results.
but i have problem in getting the response for token and then call the prev. request?
so i tried adding an observable request , then in response check if the token is invalid, then call another observable to return an active token, once token is received , call the older request again.
func apirequest(_ urlConvertible:URLRequestConvertible) -> Observable<[String:AnyObject]> {
return Observable.create({ observer -> Disposable in
let _ = Alamofire.request(urlConvertible).responseJSON
{ response in
if isTokenExpired() {
self.generateToken().subscribe(onNext: response {
self.apirequest(oldRequest)
})
}
}
return Disposables.create()
})
}
i was expecting like any Rx operators or any ideas to try?
Thanks