Skip to content

Commit

Permalink
Consistently use Task or ValueTask in APIs
Browse files Browse the repository at this point in the history
Fixes #1645

* Start with `IFrameHandler` as pointed out by @danielmarbach
  • Loading branch information
lukebakken committed Aug 6, 2024
1 parent 8d10b43 commit 2d45e5d
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public async ValueTask<RecoveryAwareChannel> CreateNonRecoveringChannelAsync(Can
public override string ToString()
=> $"AutorecoveringConnection({InnerConnection.Id},{Endpoint},{GetHashCode()})";

internal Task CloseFrameHandlerAsync()
internal ValueTask CloseFrameHandlerAsync()
{
return InnerConnection.FrameHandler.CloseAsync(CancellationToken.None);
}
Expand Down
4 changes: 2 additions & 2 deletions projects/RabbitMQ.Client/client/impl/IFrameHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ internal interface IFrameHandler
///<summary>Socket write timeout. System.Threading.Timeout.InfiniteTimeSpan signals "infinity".</summary>
TimeSpan WriteTimeout { set; }

Task CloseAsync(CancellationToken cancellationToken);
ValueTask CloseAsync(CancellationToken cancellationToken);

///<summary>Read a frame from the underlying
///transport. Returns null if the read operation timed out
Expand All @@ -66,7 +66,7 @@ internal interface IFrameHandler
///</summary>
bool TryReadFrame(InboundFrame frame);

Task SendProtocolHeaderAsync(CancellationToken cancellationToken);
ValueTask SendProtocolHeaderAsync(CancellationToken cancellationToken);

ValueTask WriteAsync(RentedMemory frames, CancellationToken cancellationToken);
}
Expand Down
4 changes: 2 additions & 2 deletions projects/RabbitMQ.Client/client/impl/SocketFrameHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public static async Task<SocketFrameHandler> CreateAsync(AmqpTcpEndpoint amqpTcp
return socketFrameHandler;
}

public async Task CloseAsync(CancellationToken cancellationToken)
public async ValueTask CloseAsync(CancellationToken cancellationToken)
{
if (_closed)
{
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions projects/Test/Integration/TestConnectionShutdown.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down

0 comments on commit 2d45e5d

Please sign in to comment.