Skip to content

Conversation

martintmk
Copy link
Contributor

@martintmk martintmk commented Jul 25, 2023

Details on the issue fix or feature implementation

These changes enable flowing the type used in the callback back to the result:

ResilienceStrategy<object> strategy = NullResilienceStrategy<object>.Instance;

int v1 = strategy.Execute(() => 10);
string v2 = strategy.Execute(() => "val");
bool v3 = strategy.Execute(() => true);

Previously, these all would be object:

ResilienceStrategy<object> strategy = NullResilienceStrategy<object>.Instance;

object v1 = strategy.Execute(() => 10);
object v2 = strategy.Execute(() => "val");
object v3 = strategy.Execute(() => true);

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 Jul 25, 2023
@martintmk martintmk added this to the v8.0.0 milestone Jul 25, 2023
Copy link
Member

@martincostello martincostello left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just not a big fan of the name T as it's not very descriptive alongside TResult and TState and might cause some confusion between T and TResult when both are kinda a result (just in different contexts).

/// <typeparam name="TState">The type of state associated with the callback.</typeparam>
/// <param name="callback">The user-provided callback.</param>
/// <param name="context">The context associated with the callback.</param>
/// <param name="state">The state associated with the callback.</param>
/// <returns>The instance of <see cref="ValueTask"/> that represents the asynchronous execution.</returns>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="callback"/> or <paramref name="context"/> is <see langword="null"/>.</exception>
public ValueTask<TResult> ExecuteAsync<TState>(
Func<ResilienceContext, TState, ValueTask<TResult>> callback,
public ValueTask<T> ExecuteAsync<T, TState>(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if there's a better name we can give this rather than T?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any suggestions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just swap T with TResult?

So it will be ResilienceStrategy<T> but individual methods will have TResult?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't have any good suggestions - your one sounds fine to me.

@codecov
Copy link

codecov bot commented Jul 25, 2023

Codecov Report

Merging #1428 (c1b803e) into main (59e461a) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##             main    #1428   +/-   ##
=======================================
  Coverage   83.92%   83.92%           
=======================================
  Files         275      275           
  Lines        6526     6526           
  Branches     1007     1007           
=======================================
  Hits         5477     5477           
  Misses        840      840           
  Partials      209      209           
Flag Coverage Δ
linux ?
macos 83.92% <ø> (ø)
windows 83.92% <ø> (ø)

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

Files Changed Coverage Δ
src/Polly.Core/ResilienceStrategy.TResult.Async.cs 100.00% <ø> (ø)
src/Polly.Core/ResilienceStrategy.TResult.Sync.cs 100.00% <ø> (ø)

@martintmk martintmk enabled auto-merge (squash) July 25, 2023 08:56
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.

2 participants