Skip to content

Commit

Permalink
feat: Make RetryStrategyOptions initializer public (#571)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbelkins authored Jul 31, 2023
1 parent 24100df commit 236a2d1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions Sources/ClientRuntime/Retries/ExponentialBackoffStrategy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,23 @@
import func Foundation.pow
import struct Foundation.TimeInterval

struct ExponentialBackoffStrategy: RetryBackoffStrategy {
public struct ExponentialBackoffStrategy: RetryBackoffStrategy {
let options: ExponentialBackoffStrategyOptions

var random: () -> Double = { Double.random(in: 0.0...1.0) }

// values set by Retry Behavior 2.0 SEP
let r = 2.0

init(options: ExponentialBackoffStrategyOptions = ExponentialBackoffStrategyOptions()) {
public init() {
self.init(options: ExponentialBackoffStrategyOptions())
}

init(options: ExponentialBackoffStrategyOptions) {
self.options = options
}

func computeNextBackoffDelay(attempt: Int) -> TimeInterval {
public func computeNextBackoffDelay(attempt: Int) -> TimeInterval {
min(random() * pow(r, Double(attempt)), options.maxBackoff)
}
}
2 changes: 1 addition & 1 deletion Sources/ClientRuntime/Retries/RetryStrategyOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public struct RetryStrategyOptions {
/// - maxRetriesBase: The number of times to retry the initial request. Defaults to 2.
/// - availableCapacity: The number of available tokens in a retry quota. Defaults to 500.
/// - maxCapacity: The max number of tokens in a retry quota. Defaults to 500.
init(
public init(
backoffStrategy: RetryBackoffStrategy = ExponentialBackoffStrategy(),
maxRetriesBase: Int = 2,
availableCapacity: Int = 500,
Expand Down

0 comments on commit 236a2d1

Please sign in to comment.