From 2d45e5d3a6d9e2c92ba62347784b80d543889e45 Mon Sep 17 00:00:00 2001 From: Luke Bakken Date: Tue, 30 Jul 2024 08:01:14 -0700 Subject: [PATCH] Consistently use `Task` or `ValueTask` in APIs Fixes #1645 * Start with `IFrameHandler` as pointed out by @danielmarbach --- .../RabbitMQ.Client/client/impl/AutorecoveringConnection.cs | 2 +- projects/RabbitMQ.Client/client/impl/IFrameHandler.cs | 4 ++-- projects/RabbitMQ.Client/client/impl/SocketFrameHandler.cs | 4 ++-- projects/Test/Integration/TestConnectionShutdown.cs | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.cs b/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.cs index 19391278ce..f4b89fc6c0 100644 --- a/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.cs +++ b/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.cs @@ -183,7 +183,7 @@ public async ValueTask CreateNonRecoveringChannelAsync(Can public override string ToString() => $"AutorecoveringConnection({InnerConnection.Id},{Endpoint},{GetHashCode()})"; - internal Task CloseFrameHandlerAsync() + internal ValueTask CloseFrameHandlerAsync() { return InnerConnection.FrameHandler.CloseAsync(CancellationToken.None); } diff --git a/projects/RabbitMQ.Client/client/impl/IFrameHandler.cs b/projects/RabbitMQ.Client/client/impl/IFrameHandler.cs index f65e0ffdee..672f6a3bb4 100644 --- a/projects/RabbitMQ.Client/client/impl/IFrameHandler.cs +++ b/projects/RabbitMQ.Client/client/impl/IFrameHandler.cs @@ -54,7 +54,7 @@ internal interface IFrameHandler ///Socket write timeout. System.Threading.Timeout.InfiniteTimeSpan signals "infinity". TimeSpan WriteTimeout { set; } - Task CloseAsync(CancellationToken cancellationToken); + ValueTask CloseAsync(CancellationToken cancellationToken); ///Read a frame from the underlying ///transport. Returns null if the read operation timed out @@ -66,7 +66,7 @@ internal interface IFrameHandler /// bool TryReadFrame(InboundFrame frame); - Task SendProtocolHeaderAsync(CancellationToken cancellationToken); + ValueTask SendProtocolHeaderAsync(CancellationToken cancellationToken); ValueTask WriteAsync(RentedMemory frames, CancellationToken cancellationToken); } diff --git a/projects/RabbitMQ.Client/client/impl/SocketFrameHandler.cs b/projects/RabbitMQ.Client/client/impl/SocketFrameHandler.cs index ec970fe93c..6f6cbf3435 100644 --- a/projects/RabbitMQ.Client/client/impl/SocketFrameHandler.cs +++ b/projects/RabbitMQ.Client/client/impl/SocketFrameHandler.cs @@ -157,7 +157,7 @@ public static async Task CreateAsync(AmqpTcpEndpoint amqpTcp return socketFrameHandler; } - public async Task CloseAsync(CancellationToken cancellationToken) + public async ValueTask CloseAsync(CancellationToken cancellationToken) { if (_closed) { @@ -216,7 +216,7 @@ public bool TryReadFrame(InboundFrame frame) _amqpTcpEndpoint.MaxInboundMessageBodySize, frame); } - public async Task SendProtocolHeaderAsync(CancellationToken cancellationToken) + public async ValueTask SendProtocolHeaderAsync(CancellationToken cancellationToken) { await _pipeWriter.WriteAsync(Amqp091ProtocolHeader, cancellationToken) .ConfigureAwait(false); diff --git a/projects/Test/Integration/TestConnectionShutdown.cs b/projects/Test/Integration/TestConnectionShutdown.cs index 568a7ff8e0..902421967b 100644 --- a/projects/Test/Integration/TestConnectionShutdown.cs +++ b/projects/Test/Integration/TestConnectionShutdown.cs @@ -100,13 +100,13 @@ public async Task TestDisposedWithSocketClosedOutOfBand() }; var c = (AutorecoveringConnection)_conn; - Task frameHandlerCloseTask = c.CloseFrameHandlerAsync(); + ValueTask frameHandlerCloseTask = c.CloseFrameHandlerAsync(); try { _conn.Dispose(); await WaitAsync(tcs, WaitSpan, "channel shutdown"); - await frameHandlerCloseTask.WaitAsync(WaitSpan); + await frameHandlerCloseTask.AsTask().WaitAsync(WaitSpan); } finally {