feat(battle-node): capture session-scoped CT in BattleSession.RunAsync

This commit is contained in:
gamer147
2026-06-01 11:11:31 -04:00
parent e4691d616b
commit 0764b8646f

View File

@@ -18,6 +18,19 @@ public sealed class BattleSession
private readonly WebSocket _ws;
private readonly ILogger<BattleSession> _log;
/// <summary>
/// Cancellation token for the session lifetime, captured from <see cref="RunAsync"/>'s
/// parameter. Read by all send helpers so host shutdown promptly terminates pending
/// writes (was <c>CancellationToken.None</c> on every send pre-this-slice).
/// </summary>
/// <remarks>
/// Defaults to <see cref="CancellationToken.None"/> when <see cref="RunAsync"/> hasn't
/// run — e.g. unit tests that drive <see cref="ComputeResponses"/> directly without
/// going through the WS pump. None of those tests exercise send code, so the default
/// is safe.
/// </remarks>
private CancellationToken _sessionCt;
public string BattleId { get; }
public long ViewerId { get; }
public BattleSessionPhase Phase { get; internal set; } = BattleSessionPhase.AwaitingInitNetwork;
@@ -37,6 +50,7 @@ public sealed class BattleSession
/// </summary>
public async Task RunAsync(CancellationToken cancellation)
{
_sessionCt = cancellation;
await SendEioOpenAsync(cancellation);
var buffer = new byte[8192];