Skip to content

Commit 770c7ee

Browse files
danielmarbachlukebakken
authored andcommitted
Make connection implement IAsyncDisposable
1 parent 7701fbd commit 770c7ee

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

projects/RabbitMQ.Client/IConnection.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ namespace RabbitMQ.Client
5050
/// Alternatively, an API tutorial can be found in the User Guide.
5151
/// </para>
5252
/// <para>
53-
/// Extends the <see cref="IDisposable"/> interface, so that the "using"
53+
/// Extends the <see cref="IDisposable"/> and the <see cref="IAsyncDisposable"/> interface, so that the "using"
5454
/// statement can be used to scope the lifetime of a connection when
5555
/// appropriate.
5656
/// </para>
5757
/// </remarks>
58-
public interface IConnection : INetworkConnection, IDisposable
58+
public interface IConnection : INetworkConnection, IAsyncDisposable, IDisposable
5959
{
6060
/// <summary>
6161
/// The maximum channel number this connection supports (0 if unlimited).

projects/RabbitMQ.Client/Impl/AutorecoveringConnection.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,9 @@ await RecordChannelAsync(channel, channelsSemaphoreHeld: false, cancellationToke
264264
return channel;
265265
}
266266

267-
public void Dispose()
267+
public void Dispose() => DisposeAsync().AsTask().GetAwaiter().GetResult();
268+
269+
public async ValueTask DisposeAsync()
268270
{
269271
if (_disposed)
270272
{
@@ -273,7 +275,8 @@ public void Dispose()
273275

274276
try
275277
{
276-
_innerConnection.Dispose();
278+
await _innerConnection.DisposeAsync()
279+
.ConfigureAwait(false);
277280
}
278281
catch (OperationInterruptedException)
279282
{

projects/RabbitMQ.Client/Impl/Connection.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,9 @@ internal ValueTask WriteAsync(RentedMemory frames, CancellationToken cancellatio
485485
return _frameHandler.WriteAsync(frames, cancellationToken);
486486
}
487487

488-
public void Dispose()
488+
public void Dispose() => DisposeAsync().AsTask().GetAwaiter().GetResult();
489+
490+
public async ValueTask DisposeAsync()
489491
{
490492
if (_disposed)
491493
{
@@ -496,7 +498,8 @@ public void Dispose()
496498
{
497499
if (IsOpen)
498500
{
499-
this.AbortAsync().GetAwaiter().GetResult();
501+
await this.AbortAsync()
502+
.ConfigureAwait(false);
500503
}
501504

502505
_session0.Dispose();

0 commit comments

Comments
 (0)