Fix some bugs caused by order of operations.

This commit is contained in:
2023-05-14 19:53:47 -05:00
parent f21a170eb1
commit 841dbccc29
2 changed files with 11 additions and 6 deletions

View File

@@ -32,10 +32,14 @@ public class ShogiSocket : IDisposable
public async Task OpenAsync(string token)
{
uriBuilder.Query = new QueryBuilder
{
{ "token", token }
}.ToQueryString().Value;
if (this.socket.State == WebSocketState.Open)
{
await this.socket.CloseAsync(WebSocketCloseStatus.NormalClosure, "Closing before opening a new connection.", CancellationToken.None);
}
uriBuilder.Query = new QueryBuilder { { "token", token } }.ToQueryString().Value;
Console.WriteLine("ShogiSocket.OpenAsync socket state is {0}", this.socket.State.ToString());
await socket.ConnectAsync(this.uriBuilder.Uri, cancelToken.Token);
// Fire and forget! I'm way too lazy to write my own javascript interop to a web worker. Nooo thanks.
@@ -102,8 +106,8 @@ public class ShogiSocket : IDisposable
{
if (disposing)
{
//socket.Dispose(); // This is handled by the DI container.
cancelToken.Cancel();
socket.Dispose();
memoryOwner.Dispose();
}
disposedValue = true;