I think that retrier variable in SessionManager is not very good...
What do you think put it into the Request?
use way like this:
Alamofire.request("https://temp.com", method: .get, parameters: nil, encoding: URLEncoding.default, headers: nil).response { (response) in
}.retrier(_ shouldRetry: Bool, _ timeDelay: TimeInterval) //There may be other related parameters
This is something that we're going to investigate in-depth in AF5 @gaoyuexit. Having a single retrier per SessionManager can be a bit limiting when you are trying to funnel multiple authentication systems through a single session manager. More updates to come...
I have the same problem at the moment. But to channel it in the request seems wrong on the other hand. I think a great addition would be to hold multiply retriers and you can cancel the current one. In this way you could add specific logic for specific requests in the retriers.
I might be a bit late to the party, but I'm using my homegrown Rx interface to SessionManager which allows me to do something like this:
func methodName(data: ServiceName.Method.RequestData/*Encodable*/) -> Single<ServiceName.Method.ResponseData/*Decodable*/> {
return sessionManager
.rx
.post(url, body: data/*, ...*/)
.object()
}
// ...
let disposable = service
.methodName(data: data)
.timeout(configuration.timeout, scheduler: configuration.timeoutScheduler)
.retry(configuration.retryCount) // automatically retries failed request
.retryWhen(retryHandler()) // invokes custom retry handler to do more sophisticated retry logic like exponential backoff or presenting a UI
.subscribe(/*...*/)
This way, the caller has full control over the retry logic. And readily-available instruments in Rx are quite powerful, so I don't even need that functionality in Alamofire.
Yeah not everyone using rx, so we need this directly on alamofire on the request base.
I've solved the offline retrier issue earlier in a project by creating a custom Codable APIRequest struct that holds:
Maybe a similar approach could be followed for this?
I've been meaning to submit a PR for this, but just saw this issue and thought I'd share this with you 馃槃
This feature has been built out in #2704 and merged into master. It will ship shortly as part of Alamofire 5.0.0-beta.2. 馃馃徎
yay!
Most helpful comment
I might be a bit late to the party, but I'm using my homegrown Rx interface to
SessionManagerwhich allows me to do something like this:This way, the caller has full control over the retry logic. And readily-available instruments in Rx are quite powerful, so I don't even need that functionality in Alamofire.