Skip to content

Commit 39ef4aa

Browse files
committed
Update ReuseRetryConfiguration snippet to demonstrate reusing a RetryConfiguration with any Clock type.
1 parent c878857 commit 39ef4aa

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

Snippets/Common Use Cases/ReuseRetryConfiguration.swift

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,23 @@ import Retry
77

88
// snippet.show
99

10-
extension RetryConfiguration<ContinuousClock> {
11-
static let standard = RetryConfiguration(
12-
recoverFromFailure: { $0.isRetryable ? .retry : .throw }
13-
)
10+
extension RetryConfiguration where ClockType.Duration == Duration {
11+
static func standard(using clock: ClockType = ContinuousClock()) -> Self {
12+
return RetryConfiguration(
13+
clock: clock,
14+
recoverFromFailure: { $0.isRetryable ? .retry : .throw }
15+
)
16+
}
1417

15-
static let highTolerance = (
16-
Self.standard
18+
static func highTolerance(using clock: ClockType = ContinuousClock()) -> Self {
19+
return standard(using: clock)
1720
.withMaxAttempts(10)
1821
.withBackoff(.default(baseDelay: .seconds(1),
1922
maxDelay: nil))
20-
)
23+
}
2124
}
2225

23-
try await retry(with: .highTolerance.withLogger(myLogger)) {
26+
try await retry(with: .highTolerance().withLogger(myLogger)) {
2427
try await doSomething()
2528
}
2629

0 commit comments

Comments
 (0)