Skip to content

Commit

Permalink
Update ReuseRetryConfiguration snippet to demonstrate reusing a `Re…
Browse files Browse the repository at this point in the history
…tryConfiguration` with any `Clock` type.
  • Loading branch information
fumoboy007 committed Jan 8, 2024
1 parent c878857 commit 39ef4aa
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions Snippets/Common Use Cases/ReuseRetryConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,23 @@ import Retry

// snippet.show

extension RetryConfiguration<ContinuousClock> {
static let standard = RetryConfiguration(
recoverFromFailure: { $0.isRetryable ? .retry : .throw }
)
extension RetryConfiguration where ClockType.Duration == Duration {
static func standard(using clock: ClockType = ContinuousClock()) -> Self {
return RetryConfiguration(
clock: clock,
recoverFromFailure: { $0.isRetryable ? .retry : .throw }
)
}

static let highTolerance = (
Self.standard
static func highTolerance(using clock: ClockType = ContinuousClock()) -> Self {
return standard(using: clock)
.withMaxAttempts(10)
.withBackoff(.default(baseDelay: .seconds(1),
maxDelay: nil))
)
}
}

try await retry(with: .highTolerance.withLogger(myLogger)) {
try await retry(with: .highTolerance().withLogger(myLogger)) {
try await doSomething()
}

Expand Down

0 comments on commit 39ef4aa

Please sign in to comment.