Skip to content

Conversation

@NicFontana
Copy link

@NicFontana NicFontana commented Mar 19, 2023

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 NicFontana changed the title Feature/custom retry implementation Feat: add custom retry strategy implementation Mar 19, 2023
@NicFontana NicFontana changed the title Feat: add custom retry strategy implementation [#79] Draft: Add custom retry strategy implementation Jan 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Add starting power offset for the exponential backoff

1 participant