Skip to content

Use new Task.WaitAsync() to cancel an await call #1206

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

Merged
Merged
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: 4 additions & 1 deletion projects/RabbitMQ.Client/client/impl/SocketFrameHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;

using RabbitMQ.Client.Exceptions;
using RabbitMQ.Client.Logging;

Expand All @@ -48,6 +47,9 @@ internal static class TaskExtensions
{
public static async Task TimeoutAfter(this Task task, TimeSpan timeout)
{
#if NET6_0_OR_GREATER
await task.WaitAsync(timeout).ConfigureAwait(false);
#else
if (task == await Task.WhenAny(task, Task.Delay(timeout)).ConfigureAwait(false))
{
await task.ConfigureAwait(false);
Expand All @@ -57,6 +59,7 @@ public static async Task TimeoutAfter(this Task task, TimeSpan timeout)
Task supressErrorTask = task.ContinueWith((t, s) => t.Exception.Handle(e => true), null, CancellationToken.None, TaskContinuationOptions.OnlyOnFaulted | TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default);
throw new TimeoutException();
}
#endif
}
}

Expand Down