-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
RecoveryAction.retryAfter
to allow specifying a minimum retry d…
…elay.
- Loading branch information
1 parent
37be416
commit 7c571c6
Showing
5 changed files
with
149 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Sleep a minimum duration before the next attempt. | ||
|
||
// snippet.hide | ||
|
||
import Retry | ||
|
||
// snippet.show | ||
|
||
try await retry { | ||
try await doSomething() | ||
} recoverFromFailure: { error in | ||
switch error { | ||
case let error as MyRetryAwareServerError: | ||
return .retryAfter(ContinuousClock().now + error.minRetryDelay) | ||
|
||
default: | ||
return .retry | ||
} | ||
} | ||
|
||
// snippet.hide | ||
|
||
func doSomething() async throws { | ||
} | ||
|
||
struct MyRetryAwareServerError: Error { | ||
let minRetryDelay: Duration | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters