Skip to content

Commit

Permalink
enable nullable in benchmarks (#1001)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp authored Jan 7, 2023
1 parent 14dd77b commit c874285
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/Polly.Benchmarks/Cache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public MemoryCacheProvider(IMemoryCache memoryCache)
_cache = memoryCache;
}

public (bool, object) TryGet(string key)
public (bool, object?) TryGet(string key)
{
bool cacheHit = _cache.TryGetValue(key, out var value);
return (cacheHit, value);
Expand Down Expand Up @@ -96,7 +96,7 @@ public void Put(string key, object value, Ttl ttl)
_cache.Set(key, value, options);
}

public Task<(bool, object)> TryGetAsync(string key, CancellationToken cancellationToken, bool continueOnCapturedContext)
public Task<(bool, object?)> TryGetAsync(string key, CancellationToken cancellationToken, bool continueOnCapturedContext)
{
return Task.FromResult(TryGet(key));
}
Expand Down
1 change: 1 addition & 0 deletions src/Polly.Benchmarks/Polly.Benchmarks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<IsPackable>false</IsPackable>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.13.3" />
Expand Down
22 changes: 12 additions & 10 deletions src/Polly.Benchmarks/Workloads.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,23 @@ internal static async Task ActionInfiniteAsync(CancellationToken cancellationTok
}
}

internal static T Func<T>() => default;
internal static T Func<T>()
where T : struct
=> default;

internal static Task<T> FuncAsync<T>() => Task.FromResult<T>(default);
internal static Task<T> FuncAsync<T>()
where T : struct
=> Task.FromResult<T>(default);

internal static Task<T> FuncAsync<T>(CancellationToken cancellationToken) => Task.FromResult<T>(default);
internal static Task<T> FuncAsync<T>(CancellationToken cancellationToken)
where T : struct
=> Task.FromResult<T>(default);

internal static TResult FuncThrows<TResult, TException>()
where TException : Exception, new()
{
throw new TException();
}
=> throw new TException();

internal static Task<TResult> FuncThrowsAsync<TResult, TException>()
where TException : Exception, new()
{
throw new TException();
}
}
=> throw new TException();
}

0 comments on commit c874285

Please sign in to comment.