RealHTTP icon indicating copy to clipboard operation
RealHTTP copied to clipboard

[#79] Draft: Add custom retry strategy implementation

Open NicFontana opened this issue 2 years ago • 0 comments

Hello,

this PR should add the feature requested in #79.

You can provide a custom retry strategy by implementing a closure that takes the current HTTPRequest as input and returns an amount of seconds of your choice.

For example, the requested .exponential(base: 2, from: 1) could be easily implemented in this way:

let strategy: HTTPRetryStrategy = .custom { request in
    let numberOfPreviousAttempts = request.currentRetry
    let maximumNumberOfAttempts = request.maxRetries
            
    guard numberOfPreviousAttempts < maximumNumberOfAttempts else { return 0 }
    return pow(Double(2), Double(numberOfPreviousAttempts + 1))
}

Closes #79

NicFontana avatar Mar 19 '23 18:03 NicFontana