Skip to content

Commit

Permalink
Updates from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
lyonsil committed Apr 4, 2023
1 parent 2697e4b commit 3d2b379
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions c-sharp/MessageTransports/PapiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ static PapiClient()
public PapiClient()
{
_webSocket = new ClientWebSocket();
_messageHandlingThread = new(new ThreadStart(HandleMessages));
_messageHandlingThread = new(HandleMessages);
_messageHandlersByMessageType[MessageType.Event] = new MessageHandlerEvent();
_messageHandlersByMessageType[MessageType.Request] =
new MessageHandlerRequestByRequestType();
Expand All @@ -71,19 +71,19 @@ public void Dispose()

private void Dispose(bool isDisposing)
{
if (!_isDisposed)
if (_isDisposed)
return;

if (isDisposing)
{
if (isDisposing)
{
_webSocket.Dispose();
_cancellationTokenSource.Dispose();
_messageHandlingComplete.Dispose();
}
_webSocket.Dispose();
_cancellationTokenSource.Dispose();
_messageHandlingComplete.Dispose();
}

_messageHandlersForMyRequests.Clear();
_messageHandlersForMyRequests.Clear();

_isDisposed = true;
}
_isDisposed = true;
}

#endregion
Expand Down Expand Up @@ -134,6 +134,8 @@ public async Task DisconnectAsync()
// Start a graceful disconnection process before disposing
_cancellationTokenSource.Cancel();
_messageHandlingComplete.Set();
if (!_messageHandlingThread.Join(TimeSpan.FromSeconds(2)))
Console.Error.WriteLine("Message handling thread did not shut down properly");
await _webSocket.CloseAsync(
WebSocketCloseStatus.NormalClosure,
string.Empty,
Expand Down

0 comments on commit 3d2b379

Please sign in to comment.