Skip to content

Commit

Permalink
Simplify OutcomeResilienceStrategy
Browse files Browse the repository at this point in the history
  • Loading branch information
martintmk committed Jul 27, 2023
1 parent 65df668 commit b3caa61
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/Polly.Core/Utils/OutcomeResilienceStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@ protected internal sealed override ValueTask<Outcome<TResult>> ExecuteCore<TResu
TState state)
{
// Check if we can cast directly, thus saving some cycles and improving the performance
if (context.ResultType == typeof(T))
if (callback is Func<ResilienceContext, TState, ValueTask<Outcome<T>>> casted)
{
// cast is safe here, because TResult and T are the same type
var callbackCasted = (Func<ResilienceContext, TState, ValueTask<Outcome<T>>>)(object)callback;
var valueTask = ExecuteCore(callbackCasted, context, state);

return TaskHelper.ConvertValueTask<T, TResult>(valueTask, context);
return TaskHelper.ConvertValueTask<T, TResult>(
ExecuteCore(casted, context, state),
context);
}
else
{
Expand Down

0 comments on commit b3caa61

Please sign in to comment.