Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#79] Draft: Add custom retry strategy implementation #86

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

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