Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions docs/strategies/retry.md
Original file line number Diff line number Diff line change
Expand Up @@ -474,18 +474,18 @@ Use collections and simple predicate functions:

<!-- snippet: retry-pattern-overusing-builder -->
```cs
ImmutableArray<Type> networkExceptions = new[]
{
ImmutableArray<Type> networkExceptions =
[
typeof(SocketException),
typeof(HttpRequestException),
}.ToImmutableArray();
];

ImmutableArray<Type> strategyExceptions = new[]
{
ImmutableArray<Type> strategyExceptions =
[
typeof(TimeoutRejectedException),
typeof(BrokenCircuitException),
typeof(RateLimitRejectedException),
}.ToImmutableArray();
];

ImmutableArray<Type> retryableExceptions = networkExceptions
.Union(strategyExceptions)
Expand All @@ -494,7 +494,8 @@ ImmutableArray<Type> retryableExceptions = networkExceptions
var retry = new ResiliencePipelineBuilder()
.AddRetry(new()
{
ShouldHandle = ex => new ValueTask<bool>(retryableExceptions.Contains(ex.GetType())),
ShouldHandle = args
=> ValueTask.FromResult(args.Outcome.Exception != null && retryableExceptions.Contains(args.Outcome.Exception.GetType())),
MaxRetryAttempts = 3,
})
.Build();
Expand Down
16 changes: 9 additions & 7 deletions src/Snippets/Docs/Retry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,18 +174,18 @@ public static void Pattern_OverusingBuilder()
{
#region retry-pattern-overusing-builder

ImmutableArray<Type> networkExceptions = new[]
{
ImmutableArray<Type> networkExceptions =
[
typeof(SocketException),
typeof(HttpRequestException),
}.ToImmutableArray();
];

ImmutableArray<Type> strategyExceptions = new[]
{
ImmutableArray<Type> strategyExceptions =
[
typeof(TimeoutRejectedException),
typeof(BrokenCircuitException),
typeof(RateLimitRejectedException),
}.ToImmutableArray();
];

ImmutableArray<Type> retryableExceptions = networkExceptions
.Union(strategyExceptions)
Expand All @@ -194,7 +194,9 @@ public static void Pattern_OverusingBuilder()
var retry = new ResiliencePipelineBuilder()
.AddRetry(new()
{
ShouldHandle = ex => new ValueTask<bool>(retryableExceptions.Contains(ex.GetType())),
ShouldHandle = args
=> ValueTask.FromResult(args.Outcome.Exception is not null
&& retryableExceptions.Contains(args.Outcome.Exception.GetType())),
MaxRetryAttempts = 3,
})
.Build();
Expand Down