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

more nullables #1013

Merged
merged 2 commits into from
Jan 10, 2023
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
5 changes: 3 additions & 2 deletions src/Polly/AsyncPolicy.TResult.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
namespace Polly;
#nullable enable
namespace Polly;

/// <summary>
/// Transient exception handling policies that can be applied to asynchronous delegates
Expand All @@ -22,7 +23,7 @@ internal AsyncPolicy(
/// Constructs a new instance of a derived <see cref="AsyncPolicy{TResult}"/> type with the passed <paramref name="policyBuilder"/>.
/// </summary>
/// <param name="policyBuilder">A <see cref="PolicyBuilder{TResult}"/> indicating which exceptions and results the policy should handle.</param>
protected AsyncPolicy(PolicyBuilder<TResult> policyBuilder = null)
protected AsyncPolicy(PolicyBuilder<TResult>? policyBuilder = null)
: base(policyBuilder)
{
}
Expand Down
5 changes: 3 additions & 2 deletions src/Polly/AsyncPolicy.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
namespace Polly;
#nullable enable
namespace Polly;

/// <summary>
/// Transient exception handling policies that can be applied to asynchronous delegates
Expand All @@ -18,7 +19,7 @@ internal AsyncPolicy(ExceptionPredicates exceptionPredicates)
/// Constructs a new instance of a derived <see cref="AsyncPolicy"/> type with the passed <paramref name="policyBuilder"/>.
/// </summary>
/// <param name="policyBuilder">A <see cref="PolicyBuilder"/> specifying which exceptions the policy should handle. </param>
protected AsyncPolicy(PolicyBuilder policyBuilder = null)
protected AsyncPolicy(PolicyBuilder? policyBuilder = null)
: base(policyBuilder)
{
}
Expand Down
33 changes: 17 additions & 16 deletions src/Polly/Caching/AsyncCacheTResultSyntax.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
namespace Polly;
#nullable enable
namespace Polly;

public partial class Policy
{
Expand All @@ -13,7 +14,7 @@ public partial class Policy
/// <param name="onCacheError">Delegate to call if an exception is thrown when attempting to get a value from or put a value into the cache, passing the execution context, the cache key, and the exception.</param>
/// <returns>The policy instance.</returns>
/// <exception cref="ArgumentNullException">cacheProvider</exception>
public static AsyncCachePolicy<TResult> CacheAsync<TResult>(IAsyncCacheProvider cacheProvider, TimeSpan ttl, Action<Context, string, Exception> onCacheError = null)
public static AsyncCachePolicy<TResult> CacheAsync<TResult>(IAsyncCacheProvider cacheProvider, TimeSpan ttl, Action<Context, string, Exception>? onCacheError = null)
{
if (cacheProvider == null) throw new ArgumentNullException(nameof(cacheProvider));

Expand All @@ -32,7 +33,7 @@ public static AsyncCachePolicy<TResult> CacheAsync<TResult>(IAsyncCacheProvider
/// <returns>The policy instance.</returns>
/// <exception cref="ArgumentNullException">cacheProvider</exception>
/// <exception cref="ArgumentNullException">ttlStrategy</exception>
public static AsyncCachePolicy<TResult> CacheAsync<TResult>(IAsyncCacheProvider cacheProvider, ITtlStrategy ttlStrategy, Action<Context, string, Exception> onCacheError = null)
public static AsyncCachePolicy<TResult> CacheAsync<TResult>(IAsyncCacheProvider cacheProvider, ITtlStrategy ttlStrategy, Action<Context, string, Exception>? onCacheError = null)
{
if (cacheProvider == null) throw new ArgumentNullException(nameof(cacheProvider));

Expand All @@ -52,7 +53,7 @@ public static AsyncCachePolicy<TResult> CacheAsync<TResult>(IAsyncCacheProvider
/// <returns>The policy instance.</returns>
/// <exception cref="ArgumentNullException">cacheProvider</exception>
/// <exception cref="ArgumentNullException">cacheKeyStrategy</exception>
public static AsyncCachePolicy<TResult> CacheAsync<TResult>(IAsyncCacheProvider cacheProvider, TimeSpan ttl, ICacheKeyStrategy cacheKeyStrategy, Action<Context, string, Exception> onCacheError = null)
public static AsyncCachePolicy<TResult> CacheAsync<TResult>(IAsyncCacheProvider cacheProvider, TimeSpan ttl, ICacheKeyStrategy cacheKeyStrategy, Action<Context, string, Exception>? onCacheError = null)
{
if (cacheProvider == null) throw new ArgumentNullException(nameof(cacheProvider));

Expand All @@ -73,7 +74,7 @@ public static AsyncCachePolicy<TResult> CacheAsync<TResult>(IAsyncCacheProvider
/// <exception cref="ArgumentNullException">cacheProvider</exception>
/// <exception cref="ArgumentNullException">ttlStrategy</exception>
/// <exception cref="ArgumentNullException">cacheKeyStrategy</exception>
public static AsyncCachePolicy<TResult> CacheAsync<TResult>(IAsyncCacheProvider cacheProvider, ITtlStrategy ttlStrategy, ICacheKeyStrategy cacheKeyStrategy, Action<Context, string, Exception> onCacheError = null)
public static AsyncCachePolicy<TResult> CacheAsync<TResult>(IAsyncCacheProvider cacheProvider, ITtlStrategy ttlStrategy, ICacheKeyStrategy cacheKeyStrategy, Action<Context, string, Exception>? onCacheError = null)
{
if (cacheProvider == null) throw new ArgumentNullException(nameof(cacheProvider));

Expand All @@ -93,7 +94,7 @@ public static AsyncCachePolicy<TResult> CacheAsync<TResult>(IAsyncCacheProvider
/// <returns>The policy instance.</returns>
/// <exception cref="ArgumentNullException">cacheProvider</exception>
/// <exception cref="ArgumentNullException">cacheKeyStrategy</exception>
public static AsyncCachePolicy<TResult> CacheAsync<TResult>(IAsyncCacheProvider cacheProvider, TimeSpan ttl, Func<Context, string> cacheKeyStrategy, Action<Context, string, Exception> onCacheError = null)
public static AsyncCachePolicy<TResult> CacheAsync<TResult>(IAsyncCacheProvider cacheProvider, TimeSpan ttl, Func<Context, string> cacheKeyStrategy, Action<Context, string, Exception>? onCacheError = null)
{
if (cacheProvider == null) throw new ArgumentNullException(nameof(cacheProvider));

Expand All @@ -114,7 +115,7 @@ public static AsyncCachePolicy<TResult> CacheAsync<TResult>(IAsyncCacheProvider
/// <exception cref="ArgumentNullException">cacheProvider</exception>
/// <exception cref="ArgumentNullException">ttlStrategy</exception>
/// <exception cref="ArgumentNullException">cacheKeyStrategy</exception>
public static AsyncCachePolicy<TResult> CacheAsync<TResult>(IAsyncCacheProvider cacheProvider, ITtlStrategy ttlStrategy, Func<Context, string> cacheKeyStrategy, Action<Context, string, Exception> onCacheError = null)
public static AsyncCachePolicy<TResult> CacheAsync<TResult>(IAsyncCacheProvider cacheProvider, ITtlStrategy ttlStrategy, Func<Context, string> cacheKeyStrategy, Action<Context, string, Exception>? onCacheError = null)
{
if (cacheProvider == null) throw new ArgumentNullException(nameof(cacheProvider));

Expand Down Expand Up @@ -351,7 +352,7 @@ public static AsyncCachePolicy<TResult> CacheAsync<TResult>(
/// <param name="onCacheError">Delegate to call if an exception is thrown when attempting to get a value from or put a value into the cache, passing the execution context, the cache key, and the exception.</param>
/// <returns>The policy instance.</returns>
/// <exception cref="ArgumentNullException">cacheProvider</exception>
public static AsyncCachePolicy<TResult> CacheAsync<TResult>(IAsyncCacheProvider<TResult> cacheProvider, TimeSpan ttl, Action<Context, string, Exception> onCacheError = null)
public static AsyncCachePolicy<TResult> CacheAsync<TResult>(IAsyncCacheProvider<TResult> cacheProvider, TimeSpan ttl, Action<Context, string, Exception>? onCacheError = null)
=> CacheAsync<TResult>(cacheProvider, new RelativeTtl(ttl), DefaultCacheKeyStrategy.Instance.GetCacheKey, onCacheError);

/// <summary>
Expand All @@ -366,7 +367,7 @@ public static AsyncCachePolicy<TResult> CacheAsync<TResult>(IAsyncCacheProvider<
/// <returns>The policy instance.</returns>
/// <exception cref="ArgumentNullException">cacheProvider</exception>
/// <exception cref="ArgumentNullException">ttlStrategy</exception>
public static AsyncCachePolicy<TResult> CacheAsync<TResult>(IAsyncCacheProvider<TResult> cacheProvider, ITtlStrategy ttlStrategy, Action<Context, string, Exception> onCacheError = null)
public static AsyncCachePolicy<TResult> CacheAsync<TResult>(IAsyncCacheProvider<TResult> cacheProvider, ITtlStrategy ttlStrategy, Action<Context, string, Exception>? onCacheError = null)
=> CacheAsync<TResult>(cacheProvider, ttlStrategy, DefaultCacheKeyStrategy.Instance.GetCacheKey, onCacheError);

/// <summary>
Expand All @@ -381,7 +382,7 @@ public static AsyncCachePolicy<TResult> CacheAsync<TResult>(IAsyncCacheProvider<
/// <returns>The policy instance.</returns>
/// <exception cref="ArgumentNullException">cacheProvider</exception>
/// <exception cref="ArgumentNullException">ttlStrategy</exception>
public static AsyncCachePolicy<TResult> CacheAsync<TResult>(IAsyncCacheProvider<TResult> cacheProvider, ITtlStrategy<TResult> ttlStrategy, Action<Context, string, Exception> onCacheError = null)
public static AsyncCachePolicy<TResult> CacheAsync<TResult>(IAsyncCacheProvider<TResult> cacheProvider, ITtlStrategy<TResult> ttlStrategy, Action<Context, string, Exception>? onCacheError = null)
=> CacheAsync<TResult>(cacheProvider, ttlStrategy, DefaultCacheKeyStrategy.Instance.GetCacheKey, onCacheError);

/// <summary>
Expand All @@ -397,7 +398,7 @@ public static AsyncCachePolicy<TResult> CacheAsync<TResult>(IAsyncCacheProvider<
/// <returns>The policy instance.</returns>
/// <exception cref="ArgumentNullException">cacheProvider</exception>
/// <exception cref="ArgumentNullException">cacheKeyStrategy</exception>
public static AsyncCachePolicy<TResult> CacheAsync<TResult>(IAsyncCacheProvider<TResult> cacheProvider, TimeSpan ttl, ICacheKeyStrategy cacheKeyStrategy, Action<Context, string, Exception> onCacheError = null)
public static AsyncCachePolicy<TResult> CacheAsync<TResult>(IAsyncCacheProvider<TResult> cacheProvider, TimeSpan ttl, ICacheKeyStrategy cacheKeyStrategy, Action<Context, string, Exception>? onCacheError = null)
=> CacheAsync<TResult>(cacheProvider, new RelativeTtl(ttl), cacheKeyStrategy.GetCacheKey, onCacheError);

/// <summary>
Expand All @@ -414,7 +415,7 @@ public static AsyncCachePolicy<TResult> CacheAsync<TResult>(IAsyncCacheProvider<
/// <exception cref="ArgumentNullException">cacheProvider</exception>
/// <exception cref="ArgumentNullException">ttlStrategy</exception>
/// <exception cref="ArgumentNullException">cacheKeyStrategy</exception>
public static AsyncCachePolicy<TResult> CacheAsync<TResult>(IAsyncCacheProvider<TResult> cacheProvider, ITtlStrategy ttlStrategy, ICacheKeyStrategy cacheKeyStrategy, Action<Context, string, Exception> onCacheError = null)
public static AsyncCachePolicy<TResult> CacheAsync<TResult>(IAsyncCacheProvider<TResult> cacheProvider, ITtlStrategy ttlStrategy, ICacheKeyStrategy cacheKeyStrategy, Action<Context, string, Exception>? onCacheError = null)
{
onCacheError = onCacheError ?? ((_, _, _) => { });

Expand All @@ -437,7 +438,7 @@ public static AsyncCachePolicy<TResult> CacheAsync<TResult>(IAsyncCacheProvider<
/// <exception cref="ArgumentNullException">cacheProvider</exception>
/// <exception cref="ArgumentNullException">ttlStrategy</exception>
/// <exception cref="ArgumentNullException">cacheKeyStrategy</exception>
public static AsyncCachePolicy<TResult> CacheAsync<TResult>(IAsyncCacheProvider<TResult> cacheProvider, ITtlStrategy<TResult> ttlStrategy, ICacheKeyStrategy cacheKeyStrategy, Action<Context, string, Exception> onCacheError = null)
public static AsyncCachePolicy<TResult> CacheAsync<TResult>(IAsyncCacheProvider<TResult> cacheProvider, ITtlStrategy<TResult> ttlStrategy, ICacheKeyStrategy cacheKeyStrategy, Action<Context, string, Exception>? onCacheError = null)
{
onCacheError = onCacheError ?? ((_, _, _) => { });

Expand All @@ -459,7 +460,7 @@ public static AsyncCachePolicy<TResult> CacheAsync<TResult>(IAsyncCacheProvider<
/// <returns>The policy instance.</returns>
/// <exception cref="ArgumentNullException">cacheProvider</exception>
/// <exception cref="ArgumentNullException">cacheKeyStrategy</exception>
public static AsyncCachePolicy<TResult> CacheAsync<TResult>(IAsyncCacheProvider<TResult> cacheProvider, TimeSpan ttl, Func<Context, string> cacheKeyStrategy, Action<Context, string, Exception> onCacheError = null)
public static AsyncCachePolicy<TResult> CacheAsync<TResult>(IAsyncCacheProvider<TResult> cacheProvider, TimeSpan ttl, Func<Context, string> cacheKeyStrategy, Action<Context, string, Exception>? onCacheError = null)
=> CacheAsync<TResult>(cacheProvider, new RelativeTtl(ttl), cacheKeyStrategy, onCacheError);

/// <summary>
Expand All @@ -476,7 +477,7 @@ public static AsyncCachePolicy<TResult> CacheAsync<TResult>(IAsyncCacheProvider<
/// <exception cref="ArgumentNullException">cacheProvider</exception>
/// <exception cref="ArgumentNullException">ttlStrategy</exception>
/// <exception cref="ArgumentNullException">cacheKeyStrategy</exception>
public static AsyncCachePolicy<TResult> CacheAsync<TResult>(IAsyncCacheProvider<TResult> cacheProvider, ITtlStrategy ttlStrategy, Func<Context, string> cacheKeyStrategy, Action<Context, string, Exception> onCacheError = null)
public static AsyncCachePolicy<TResult> CacheAsync<TResult>(IAsyncCacheProvider<TResult> cacheProvider, ITtlStrategy ttlStrategy, Func<Context, string> cacheKeyStrategy, Action<Context, string, Exception>? onCacheError = null)
{
onCacheError = onCacheError ?? ((_, _, _) => { });

Expand All @@ -499,7 +500,7 @@ public static AsyncCachePolicy<TResult> CacheAsync<TResult>(IAsyncCacheProvider<
/// <exception cref="ArgumentNullException">cacheProvider</exception>
/// <exception cref="ArgumentNullException">ttlStrategy</exception>
/// <exception cref="ArgumentNullException">cacheKeyStrategy</exception>
public static AsyncCachePolicy<TResult> CacheAsync<TResult>(IAsyncCacheProvider<TResult> cacheProvider, ITtlStrategy<TResult> ttlStrategy, Func<Context, string> cacheKeyStrategy, Action<Context, string, Exception> onCacheError = null)
public static AsyncCachePolicy<TResult> CacheAsync<TResult>(IAsyncCacheProvider<TResult> cacheProvider, ITtlStrategy<TResult> ttlStrategy, Func<Context, string> cacheKeyStrategy, Action<Context, string, Exception>? onCacheError = null)
{
onCacheError = onCacheError ?? ((_, _, _) => { });

Expand Down
5 changes: 3 additions & 2 deletions src/Polly/Policy.TResult.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
namespace Polly;
#nullable enable
namespace Polly;

/// <summary>
/// Transient fault handling policies that can be applied to delegates returning results of type <typeparamref name="TResult"/>
Expand All @@ -19,7 +20,7 @@ internal Policy(ExceptionPredicates exceptionPredicates, ResultPredicates<TResul
/// Constructs a new instance of a derived <see cref="Policy{TResult}"/> type with the passed <paramref name="policyBuilder"/>.
/// </summary>
/// <param name="policyBuilder">A <see cref="PolicyBuilder{TResult}"/> indicating which exceptions and results the policy should handle.</param>
protected Policy(PolicyBuilder<TResult> policyBuilder = null)
protected Policy(PolicyBuilder<TResult>? policyBuilder = null)
: base(policyBuilder)
{
}
Expand Down
5 changes: 3 additions & 2 deletions src/Polly/Policy.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
namespace Polly;
#nullable enable
namespace Polly;

/// <summary>
/// Transient exception handling policies that can be applied to synchronous delegates
Expand All @@ -18,7 +19,7 @@ internal Policy(ExceptionPredicates exceptionPredicates)
/// Constructs a new instance of a derived <see cref="Policy"/> type with the passed <paramref name="policyBuilder"/>.
/// </summary>
/// <param name="policyBuilder">A <see cref="PolicyBuilder"/> specifying which exceptions the policy should handle. </param>
protected Policy(PolicyBuilder policyBuilder = null)
protected Policy(PolicyBuilder? policyBuilder = null)
: base(policyBuilder)
{
}
Expand Down
9 changes: 5 additions & 4 deletions src/Polly/Retry/AsyncRetryEngine.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
namespace Polly.Retry;
#nullable enable
namespace Polly.Retry;

internal static class AsyncRetryEngine
{
Expand All @@ -10,12 +11,12 @@ internal static async Task<TResult> ImplementationAsync<TResult>(
ResultPredicates<TResult> shouldRetryResultPredicates,
Func<DelegateResult<TResult>, TimeSpan, int, Context, Task> onRetryAsync,
int permittedRetryCount = Int32.MaxValue,
IEnumerable<TimeSpan> sleepDurationsEnumerable = null,
Func<int, DelegateResult<TResult>, Context, TimeSpan> sleepDurationProvider = null,
IEnumerable<TimeSpan>? sleepDurationsEnumerable = null,
Func<int, DelegateResult<TResult>, Context, TimeSpan>? sleepDurationProvider = null,
bool continueOnCapturedContext = false)
{
int tryCount = 0;
IEnumerator<TimeSpan> sleepDurationsEnumerator = sleepDurationsEnumerable?.GetEnumerator();
IEnumerator<TimeSpan>? sleepDurationsEnumerator = sleepDurationsEnumerable?.GetEnumerator();

try
{
Expand Down