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

Refactored to expression bodied members (Retry). #574

Merged
merged 1 commit into from
Jan 29, 2019
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
4 changes: 1 addition & 3 deletions src/Polly.Shared/Retry/AsyncRetryPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ internal AsyncRetryPolicy(
[DebuggerStepThrough]
protected override Task<TResult> ImplementationAsync(Func<Context, CancellationToken, Task<TResult>> action, Context context, CancellationToken cancellationToken,
bool continueOnCapturedContext)
{
return AsyncRetryEngine.ImplementationAsync(
=> AsyncRetryEngine.ImplementationAsync(
action,
context,
cancellationToken,
Expand All @@ -94,7 +93,6 @@ protected override Task<TResult> ImplementationAsync(Func<Context, CancellationT
_sleepDurationsEnumerable,
_sleepDurationProvider
);
}
}
}

20 changes: 5 additions & 15 deletions src/Polly.Shared/Retry/AsyncRetrySyntax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ public static class AsyncRetrySyntax
/// <param name="policyBuilder">The policy builder.</param>
/// <returns>The policy instance.</returns>
public static AsyncRetryPolicy RetryAsync(this PolicyBuilder policyBuilder)
{
return policyBuilder.RetryAsync(1);
}
=> policyBuilder.RetryAsync(1);

/// <summary>
/// Builds an <see cref="AsyncRetryPolicy" /> that will retry <paramref name="retryCount" /> times.
Expand All @@ -43,13 +41,11 @@ public static AsyncRetryPolicy RetryAsync(this PolicyBuilder policyBuilder, int
/// <returns>The policy instance.</returns>
/// <exception cref="System.ArgumentNullException">onRetry</exception>
public static AsyncRetryPolicy RetryAsync(this PolicyBuilder policyBuilder, Action<Exception, int> onRetry)
{
return policyBuilder.RetryAsync(1,
=> policyBuilder.RetryAsync(1,
#pragma warning disable 1998 // async method has no awaits, will run synchronously
onRetryAsync: async (outcome, i, ctx) => onRetry(outcome, i)
#pragma warning restore 1998
);
}

/// <summary>
/// Builds an <see cref="AsyncRetryPolicy" /> that will retry once
Expand All @@ -60,9 +56,7 @@ public static AsyncRetryPolicy RetryAsync(this PolicyBuilder policyBuilder, Acti
/// <returns>The policy instance.</returns>
/// <exception cref="System.ArgumentNullException">onRetry</exception>
public static AsyncRetryPolicy RetryAsync(this PolicyBuilder policyBuilder, Func<Exception, int, Task> onRetryAsync)
{
return policyBuilder.RetryAsync(1, onRetryAsync: (outcome, i, ctx) => onRetryAsync(outcome, i));
}
=> policyBuilder.RetryAsync(1, onRetryAsync: (outcome, i, ctx) => onRetryAsync(outcome, i));

/// <summary>
/// Builds an <see cref="AsyncRetryPolicy" /> that will retry <paramref name="retryCount" /> times
Expand Down Expand Up @@ -111,9 +105,7 @@ public static AsyncRetryPolicy RetryAsync(this PolicyBuilder policyBuilder, int
/// <returns>The policy instance.</returns>
/// <exception cref="System.ArgumentNullException">onRetry</exception>
public static AsyncRetryPolicy RetryAsync(this PolicyBuilder policyBuilder, Action<Exception, int, Context> onRetry)
{
return policyBuilder.RetryAsync(1, onRetry);
}
=> policyBuilder.RetryAsync(1, onRetry);

/// <summary>
/// Builds an <see cref="AsyncRetryPolicy"/> that will retry once
Expand All @@ -124,9 +116,7 @@ public static AsyncRetryPolicy RetryAsync(this PolicyBuilder policyBuilder, Acti
/// <returns>The policy instance.</returns>
/// <exception cref="System.ArgumentNullException">onRetry</exception>
public static AsyncRetryPolicy RetryAsync(this PolicyBuilder policyBuilder, Func<Exception, int, Context, Task> onRetryAsync)
{
return policyBuilder.RetryAsync(1, onRetryAsync);
}
=> policyBuilder.RetryAsync(1, onRetryAsync);

/// <summary>
/// Builds an <see cref="AsyncRetryPolicy"/> that will retry <paramref name="retryCount"/> times
Expand Down
20 changes: 5 additions & 15 deletions src/Polly.Shared/Retry/AsyncRetryTResultSyntax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ public static class AsyncRetryTResultSyntax
/// <param name="policyBuilder">The policy builder.</param>
/// <returns>The policy instance.</returns>
public static AsyncRetryPolicy<TResult> RetryAsync<TResult>(this PolicyBuilder<TResult> policyBuilder)
{
return policyBuilder.RetryAsync(1);
}
=> policyBuilder.RetryAsync(1);

/// <summary>
/// Builds an <see cref="AsyncRetryPolicy{TResult}" /> that will retry <paramref name="retryCount" /> times.
Expand All @@ -43,13 +41,11 @@ public static AsyncRetryPolicy<TResult> RetryAsync<TResult>(this PolicyBuilder<T
/// <returns>The policy instance.</returns>
/// <exception cref="System.ArgumentNullException">onRetry</exception>
public static AsyncRetryPolicy<TResult> RetryAsync<TResult>(this PolicyBuilder<TResult> policyBuilder, Action<DelegateResult<TResult>, int> onRetry)
{
return policyBuilder.RetryAsync(1,
=> policyBuilder.RetryAsync(1,
#pragma warning disable 1998 // async method has no awaits, will run synchronously
onRetryAsync: async (outcome, i, ctx) => onRetry(outcome, i)
#pragma warning restore 1998
);
}

/// <summary>
/// Builds an <see cref="AsyncRetryPolicy{TResult}" /> that will retry once
Expand All @@ -60,9 +56,7 @@ public static AsyncRetryPolicy<TResult> RetryAsync<TResult>(this PolicyBuilder<T
/// <returns>The policy instance.</returns>
/// <exception cref="System.ArgumentNullException">onRetry</exception>
public static AsyncRetryPolicy<TResult> RetryAsync<TResult>(this PolicyBuilder<TResult> policyBuilder, Func<DelegateResult<TResult>, int, Task> onRetryAsync)
{
return policyBuilder.RetryAsync(1, onRetryAsync: (outcome, i, ctx) => onRetryAsync(outcome, i));
}
=> policyBuilder.RetryAsync(1, onRetryAsync: (outcome, i, ctx) => onRetryAsync(outcome, i));

/// <summary>
/// Builds an <see cref="AsyncRetryPolicy{TResult}" /> that will retry <paramref name="retryCount" /> times
Expand Down Expand Up @@ -111,9 +105,7 @@ public static AsyncRetryPolicy<TResult> RetryAsync<TResult>(this PolicyBuilder<T
/// <returns>The policy instance.</returns>
/// <exception cref="System.ArgumentNullException">onRetry</exception>
public static AsyncRetryPolicy<TResult> RetryAsync<TResult>(this PolicyBuilder<TResult> policyBuilder, Action<DelegateResult<TResult>, int, Context> onRetry)
{
return policyBuilder.RetryAsync(1, onRetry);
}
=> policyBuilder.RetryAsync(1, onRetry);

/// <summary>
/// Builds an <see cref="AsyncRetryPolicy{TResult}"/> that will retry once
Expand All @@ -124,9 +116,7 @@ public static AsyncRetryPolicy<TResult> RetryAsync<TResult>(this PolicyBuilder<T
/// <returns>The policy instance.</returns>
/// <exception cref="System.ArgumentNullException">onRetry</exception>
public static AsyncRetryPolicy<TResult> RetryAsync<TResult>(this PolicyBuilder<TResult> policyBuilder, Func<DelegateResult<TResult>, int, Context, Task> onRetryAsync)
{
return policyBuilder.RetryAsync(1, onRetryAsync);
}
=> policyBuilder.RetryAsync(1, onRetryAsync);

/// <summary>
/// Builds an <see cref="AsyncRetryPolicy{TResult}"/> that will retry <paramref name="retryCount"/> times
Expand Down
8 changes: 2 additions & 6 deletions src/Polly.Shared/Retry/RetryPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ internal RetryPolicy(

/// <inheritdoc/>
protected override TResult Implementation<TResult>(Func<Context, CancellationToken, TResult> action, Context context, CancellationToken cancellationToken)
{
return RetryEngine.Implementation(
=> RetryEngine.Implementation(
action,
context,
cancellationToken,
Expand All @@ -46,7 +45,6 @@ protected override TResult Implementation<TResult>(Func<Context, CancellationTok
? (retryCount, outcome, ctx) => _sleepDurationProvider(retryCount, outcome.Exception, ctx)
: (Func<int, DelegateResult<TResult>, Context, TimeSpan>)null
);
}
}

/// <summary>
Expand Down Expand Up @@ -78,8 +76,7 @@ internal RetryPolicy(
/// <inheritdoc/>
[DebuggerStepThrough]
protected override TResult Implementation(Func<Context, CancellationToken, TResult> action, Context context, CancellationToken cancellationToken)
{
return RetryEngine.Implementation(
=> RetryEngine.Implementation(
action,
context,
cancellationToken,
Expand All @@ -90,6 +87,5 @@ protected override TResult Implementation(Func<Context, CancellationToken, TResu
_sleepDurationsEnumerable,
_sleepDurationProvider
);
}
}
}
12 changes: 3 additions & 9 deletions src/Polly.Shared/Retry/RetrySyntax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ public static class RetrySyntax
/// <param name="policyBuilder">The policy builder.</param>
/// <returns>The policy instance.</returns>
public static RetryPolicy Retry(this PolicyBuilder policyBuilder)
{
return policyBuilder.Retry(1);
}
=> policyBuilder.Retry(1);

/// <summary>
/// Builds a <see cref="Policy"/> that will retry <paramref name="retryCount"/> times.
Expand All @@ -42,9 +40,7 @@ public static RetryPolicy Retry(this PolicyBuilder policyBuilder, int retryCount
/// <returns>The policy instance.</returns>
/// <exception cref="System.ArgumentNullException">onRetry</exception>
public static RetryPolicy Retry(this PolicyBuilder policyBuilder, Action<Exception, int> onRetry)
{
return policyBuilder.Retry(1, onRetry);
}
=> policyBuilder.Retry(1, onRetry);

/// <summary>
/// Builds a <see cref="Policy"/> that will retry <paramref name="retryCount"/> times
Expand Down Expand Up @@ -73,9 +69,7 @@ public static RetryPolicy Retry(this PolicyBuilder policyBuilder, int retryCount
/// <returns>The policy instance.</returns>
/// <exception cref="System.ArgumentNullException">onRetry</exception>
public static RetryPolicy Retry(this PolicyBuilder policyBuilder, Action<Exception, int, Context> onRetry)
{
return policyBuilder.Retry(1, onRetry);
}
=> policyBuilder.Retry(1, onRetry);

/// <summary>
/// Builds a <see cref="Policy"/> that will retry <paramref name="retryCount"/> times
Expand Down
16 changes: 4 additions & 12 deletions src/Polly.Shared/Retry/RetryTResultSyntax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ public static class RetryTResultSyntax
/// <param name="policyBuilder">The policy builder.</param>
/// <returns>The policy instance.</returns>
public static RetryPolicy<TResult> Retry<TResult>(this PolicyBuilder<TResult> policyBuilder)
{
return policyBuilder.Retry(1);
}
=> policyBuilder.Retry(1);

/// <summary>
/// Builds a <see cref="Policy{TResult}"/> that will retry <paramref name="retryCount"/> times.
Expand All @@ -42,9 +40,7 @@ public static RetryPolicy<TResult> Retry<TResult>(this PolicyBuilder<TResult> po
/// <returns>The policy instance.</returns>
/// <exception cref="System.ArgumentNullException">onRetry</exception>
public static RetryPolicy<TResult> Retry<TResult>(this PolicyBuilder<TResult> policyBuilder, Action<DelegateResult<TResult>, int> onRetry)
{
return policyBuilder.Retry(1, onRetry);
}
=> policyBuilder.Retry(1, onRetry);

/// <summary>
/// Builds a <see cref="Policy{TResult}"/> that will retry <paramref name="retryCount"/> times
Expand Down Expand Up @@ -73,9 +69,7 @@ public static RetryPolicy<TResult> Retry<TResult>(this PolicyBuilder<TResult> po
/// <returns>The policy instance.</returns>
/// <exception cref="System.ArgumentNullException">onRetry</exception>
public static RetryPolicy<TResult> Retry<TResult>(this PolicyBuilder<TResult> policyBuilder, Action<DelegateResult<TResult>, int, Context> onRetry)
{
return policyBuilder.Retry(1, onRetry);
}
=> policyBuilder.Retry(1, onRetry);

/// <summary>
/// Builds a <see cref="Policy{TResult}"/> that will retry <paramref name="retryCount"/> times
Expand Down Expand Up @@ -348,13 +342,11 @@ public static RetryPolicy<TResult> WaitAndRetry<TResult>(this PolicyBuilder<TRes
/// onRetry
/// </exception>
public static RetryPolicy<TResult> WaitAndRetry<TResult>(this PolicyBuilder<TResult> policyBuilder, int retryCount, Func<int, Context, TimeSpan> sleepDurationProvider, Action<DelegateResult<TResult>, TimeSpan, int, Context> onRetry)
{
return policyBuilder.WaitAndRetry(
=> policyBuilder.WaitAndRetry(
retryCount,
(i, outcome, ctx) => sleepDurationProvider(i, ctx),
onRetry
);
}

/// <summary>
/// Builds a <see cref="Policy{TResult}"/> that will wait and retry <paramref name="retryCount"/> times.
Expand Down