Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid Outcome<T> to Outcome conversion when not necessary #1229

Merged
merged 2 commits into from
May 26, 2023

Conversation

martintmk
Copy link
Contributor

@martintmk martintmk commented May 26, 2023

Details on the issue fix or feature implementation

This PR introduces new internal helpers that are used in individual strategies.

  • EventInvoker
  • GeneratorInvoker
  • PredicateInvoker

These classes use generic and non-generic delegates and adopt them to a generic methods:

Usage:

// non-generic options
var options = new RetryStrategyOptions(); 
PredicateInvoker<ShouldRetryArguments>.NonGeneric(options.ShouldRetry);
EventInvoker<OnRetryArguments>.NonGeneric(options.OnRetry);
GeneratorInvoker<RetryDelayArguments, TimeSpan>.NonGeneric(options.RetryDelayGenerator);

// or generic
var options = new RetryStrategyOptions<string>(); 
PredicateInvoker<ShouldRetryArguments>.Generic(options.ShouldRetry);
EventInvoker<OnRetryArguments>.Generic(options.OnRetry);
GeneratorInvoker<RetryDelayArguments, TimeSpan>.Generic(options.RetryDelayGenerator);

These reduce some duplications we have and provide nice perf boost in strategies. I'll follow up in other strategies.

Confirm the following

  • I started this PR by branching from the head of the default branch
  • I have targeted the PR to merge into the default branch
  • I have included unit tests for the issue/feature
  • I have successfully run a local build

@martintmk martintmk added the v8 Issues related to the new version 8 of the Polly library. label May 26, 2023
@martintmk martintmk added this to the v8.0.0 milestone May 26, 2023
@codecov-commenter
Copy link

codecov-commenter commented May 26, 2023

Codecov Report

Merging #1229 (0131cd4) into main (38f9870) will increase coverage by 0.05%.
The diff coverage is 100.00%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

@@            Coverage Diff             @@
##             main    #1229      +/-   ##
==========================================
+ Coverage   82.85%   82.91%   +0.05%     
==========================================
  Files         264      267       +3     
  Lines        6119     6139      +20     
  Branches      978      979       +1     
==========================================
+ Hits         5070     5090      +20     
  Misses        844      844              
  Partials      205      205              
Flag Coverage Δ
linux 82.91% <100.00%> (+0.05%) ⬆️
macos ?
windows 82.91% <100.00%> (+0.05%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...c/Polly.Core/Retry/RetryStrategyOptions.TResult.cs 100.00% <ø> (ø)
src/Polly.Core/Retry/RetryResilienceStrategy.cs 100.00% <100.00%> (ø)
.../Retry/RetryResilienceStrategyBuilderExtensions.cs 100.00% <100.00%> (ø)
src/Polly.Core/Strategy/EventInvoker.cs 100.00% <100.00%> (ø)
src/Polly.Core/Strategy/GeneratorInvoker.cs 100.00% <100.00%> (ø)
src/Polly.Core/Strategy/PredicateInvoker.cs 100.00% <100.00%> (ø)

@martintmk martintmk merged commit acf1836 into main May 26, 2023
@martintmk martintmk deleted the mtomka/delegate-handlers branch May 26, 2023 07:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
v8 Issues related to the new version 8 of the Polly library.
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants