New connection control.

This commit is contained in:
AnduinXue
2023-11-28 09:27:48 +00:00
parent b538c49378
commit 64fa2e5dd8
2 changed files with 17 additions and 2 deletions
@@ -66,7 +66,14 @@ public class GamesController : Controller
subscription = channel.Subscribe(async t => { await _pusher.SendMessage(t.Content); });
while (_pusher.Connected)
{
await Task.Delay(10 * 1000);
try
{
await Task.Delay(int.MaxValue, HttpContext.RequestAborted);
}
catch (TaskCanceledException)
{
break;
}
}
}
finally
@@ -114,6 +121,7 @@ public class GamesController : Controller
{
return BadRequest();
}
game.Move(move);
var fen = game.ToFen();
var channel = _database.GetOrAddChannel(id);
@@ -18,7 +18,14 @@ public class WebSocketPusher : IScopedDependency
public async Task SendMessage(string message)
{
await (_ws?.SendMessage(message) ?? throw new InvalidOperationException("WebSocket is not connected!"));
try
{
await (_ws?.SendMessage(message) ?? throw new InvalidOperationException("WebSocket is not connected!"));
}
catch (WebSocketException)
{
_dropped = true;
}
}
public async Task PendingClose()