changes to use dispose

This commit is contained in:
Luke Brown
2022-05-16 22:09:41 -05:00
parent 8bb4cd017c
commit a64eebe79f
9 changed files with 84 additions and 58 deletions

View File

@@ -14,7 +14,7 @@ using Microsoft.Extensions.Logging;
namespace Emby.Server.Implementations.Session
{
public sealed class WebSocketController : ISessionController, IDisposable
public sealed class WebSocketController : ISessionController, IAsyncDisposable, IDisposable
{
private readonly ILogger<WebSocketController> _logger;
private readonly ISessionManager _sessionManager;
@@ -88,15 +88,6 @@ namespace Emby.Server.Implementations.Session
cancellationToken);
}
/// <inheritdoc />
public async Task CloseAllWebSockets(CancellationToken cancellationToken)
{
foreach (var socket in _sockets)
{
await socket.CloseSocket(cancellationToken).ConfigureAwait(false);
}
}
/// <inheritdoc />
public void Dispose()
{
@@ -112,5 +103,25 @@ namespace Emby.Server.Implementations.Session
_disposed = true;
}
public async ValueTask DisposeAsync()
{
if (_disposed)
{
return;
}
foreach (var socket in _sockets)
{
socket.Closed -= OnConnectionClosed;
if (socket is IAsyncDisposable disposableAsync)
{
await disposableAsync.DisposeAsync().ConfigureAwait(false);
}
}
_disposed = true;
}
}
}