File tree Expand file tree Collapse file tree 2 files changed +17
-14
lines changed
Expand file tree Collapse file tree 2 files changed +17
-14
lines changed Original file line number Diff line number Diff line change @@ -474,18 +474,18 @@ Use collections and simple predicate functions:
474474
475475<!-- snippet: retry-pattern-overusing-builder -->
476476``` cs
477- ImmutableArray < Type > networkExceptions = new []
478- {
477+ ImmutableArray < Type > networkExceptions =
478+ [
479479 typeof (SocketException ),
480480 typeof (HttpRequestException ),
481- }. ToImmutableArray () ;
481+ ] ;
482482
483- ImmutableArray < Type > strategyExceptions = new []
484- {
483+ ImmutableArray < Type > strategyExceptions =
484+ [
485485 typeof (TimeoutRejectedException ),
486486 typeof (BrokenCircuitException ),
487487 typeof (RateLimitRejectedException ),
488- }. ToImmutableArray () ;
488+ ] ;
489489
490490ImmutableArray < Type > retryableExceptions = networkExceptions
491491 .Union (strategyExceptions )
@@ -494,7 +494,8 @@ ImmutableArray<Type> retryableExceptions = networkExceptions
494494var retry = new ResiliencePipelineBuilder ()
495495 .AddRetry (new ()
496496 {
497- ShouldHandle = ex => new ValueTask <bool >(retryableExceptions .Contains (ex .GetType ())),
497+ ShouldHandle = args
498+ => ValueTask .FromResult (args .Outcome .Exception != null && retryableExceptions .Contains (args .Outcome .Exception .GetType ())),
498499 MaxRetryAttempts = 3 ,
499500 })
500501 .Build ();
Original file line number Diff line number Diff line change @@ -174,18 +174,18 @@ public static void Pattern_OverusingBuilder()
174174 {
175175 #region retry-pattern-overusing-builder
176176
177- ImmutableArray < Type > networkExceptions = new [ ]
178- {
177+ ImmutableArray < Type > networkExceptions =
178+ [
179179 typeof ( SocketException ) ,
180180 typeof ( HttpRequestException ) ,
181- } . ToImmutableArray ( ) ;
181+ ] ;
182182
183- ImmutableArray < Type > strategyExceptions = new [ ]
184- {
183+ ImmutableArray < Type > strategyExceptions =
184+ [
185185 typeof ( TimeoutRejectedException ) ,
186186 typeof ( BrokenCircuitException ) ,
187187 typeof ( RateLimitRejectedException ) ,
188- } . ToImmutableArray ( ) ;
188+ ] ;
189189
190190 ImmutableArray < Type > retryableExceptions = networkExceptions
191191 . Union ( strategyExceptions )
@@ -194,7 +194,9 @@ public static void Pattern_OverusingBuilder()
194194 var retry = new ResiliencePipelineBuilder ( )
195195 . AddRetry ( new ( )
196196 {
197- ShouldHandle = ex => new ValueTask < bool > ( retryableExceptions . Contains ( ex . GetType ( ) ) ) ,
197+ ShouldHandle = args
198+ => ValueTask . FromResult ( args . Outcome . Exception is not null
199+ && retryableExceptions . Contains ( args . Outcome . Exception . GetType ( ) ) ) ,
198200 MaxRetryAttempts = 3 ,
199201 } )
200202 . Build ( ) ;
You can’t perform that action at this time.
0 commit comments