Skip to content

Commit 6491cc4

Browse files
committed
chore: rename parameter
1 parent 0d7d53f commit 6491cc4

File tree

3 files changed

+4
-6
lines changed

3 files changed

+4
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ $`g(x) = random[0, f(x)[`$ where `x` is the current attempt and `f(x)` the base
112112
```swift
113113
@available(iOS 18.0, macOS 15.0, macCatalyst 18.0, tvOS 18.0, watchOS 11.0, visionOS 2.0, *)
114114
extension BackoffStrategy where C.Duration == Duration {
115-
public func jitter<T>(_ generator: T = SystemRandomNumberGenerator()) -> Self where T: RandomNumberGenerator { ... }
115+
public func jitter<T>(using generator: T = SystemRandomNumberGenerator()) -> Self where T: RandomNumberGenerator { ... }
116116
}
117117
```
118118

Sources/Retry/Retry.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ import _PowShims
66
/// This can be useful for implementing retry policies with increasing delays between attempts.
77
public struct BackoffStrategy<C> where C: Clock {
88
public let duration: (Int) -> C.Duration
9-
public init(duration: @escaping (Int) -> C.Duration) {
10-
self.duration = duration
11-
}
9+
public init(duration: @escaping (Int) -> C.Duration) { self.duration = duration }
1210
}
1311

1412
extension BackoffStrategy {
@@ -64,7 +62,7 @@ extension BackoffStrategy where C.Duration == Duration {
6462
/// Jitter can help reduce contention when multiple sources retry concurrently in distributed systems.
6563
/// - Parameter generator: A custom random number generator conforming to the `RandomNumberGenerator` protocol. Defaults to `SystemRandomNumberGenerator`.
6664
/// - Note: `g(x) = random[0, f(x)[` where `x` is the current attempt and `f(x)` the base backoff strategy.
67-
public func jitter<T>(_ generator: T = SystemRandomNumberGenerator()) -> Self where T: RandomNumberGenerator {
65+
public func jitter<T>(using generator: T = SystemRandomNumberGenerator()) -> Self where T: RandomNumberGenerator {
6866
var generator = generator
6967
let attosecondsPerSecond: Int128 = 1_000_000_000_000_000_000
7068
return .init { attempt in

Tests/RetryTests/RetryTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ struct CustomError: Error { }
119119

120120
@available(iOS 18.0, macOS 15.0, macCatalyst 18.0, tvOS 18.0, watchOS 11.0, visionOS 2.0, *)
121121
@Test func testJitterBackoffStrategy() {
122-
let strategy = BackoffStrategy<ContinuousClock>.exponential(a: .seconds(3), b: 2).jitter(Xoshiro(seed: 1))
122+
let strategy = BackoffStrategy<ContinuousClock>.exponential(a: .seconds(3), b: 2).jitter(using: Xoshiro(seed: 1))
123123
#expect(strategy.duration(0) == .init(secondsComponent: 2, attosecondsComponent: 162894527200761519))
124124
#expect(strategy.duration(1) == .init(secondsComponent: 5, attosecondsComponent: 574149987820172283))
125125
#expect(strategy.duration(2) == .init(secondsComponent: 0, attosecondsComponent: 699421850917031809))

0 commit comments

Comments
 (0)