Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminsampica authored and skwasjer committed Mar 24, 2023
1 parent 2665891 commit 8804b3d
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/MockHttp/Responses/TimeoutBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,21 @@ public Task HandleAsync(MockHttpRequestContext requestContext, HttpResponseMessa
.ContinueWith(_ =>
{
var tcs = new TaskCompletionSource<HttpResponseMessage>();
#if (NETSTANDARD2_1_OR_GREATER || NET5_0_OR_GREATER)
bool isNetCore3 = RuntimeInformation.FrameworkDescription.StartsWith(".NET Core 3", StringComparison.OrdinalIgnoreCase); // Shim for .NET 5 being EOL and no longer producing an assembly for it.
bool isNotNet5OrGreater = true;

if (!cancellationToken.IsCancellationRequested && !isNetCore3)
#if NETSTANDARD2_1_OR_GREATER || NET5_0_OR_GREATER
isNotNet5OrGreater = RuntimeInformation.FrameworkDescription.StartsWith(".NET Core 3", StringComparison.OrdinalIgnoreCase); // Shim for .NET 5 being EOL and no longer producing an assembly for it.
#endif

if (cancellationToken.IsCancellationRequested || isNotNet5OrGreater)
{
tcs.TrySetException(new TaskCanceledException(null, new TimeoutException()));
tcs.TrySetCanceled();
}
else
{
tcs.TrySetCanceled();
tcs.TrySetException(new TaskCanceledException(null, new TimeoutException()));
}
#else
tcs.TrySetCanceled();
#endif

return tcs.Task;
},
TaskScheduler.Current)
Expand Down

0 comments on commit 8804b3d

Please sign in to comment.