feat(battle-node): capture session-scoped CT in BattleSession.RunAsync
This commit is contained in:
@@ -18,6 +18,19 @@ public sealed class BattleSession
|
|||||||
private readonly WebSocket _ws;
|
private readonly WebSocket _ws;
|
||||||
private readonly ILogger<BattleSession> _log;
|
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 string BattleId { get; }
|
||||||
public long ViewerId { get; }
|
public long ViewerId { get; }
|
||||||
public BattleSessionPhase Phase { get; internal set; } = BattleSessionPhase.AwaitingInitNetwork;
|
public BattleSessionPhase Phase { get; internal set; } = BattleSessionPhase.AwaitingInitNetwork;
|
||||||
@@ -37,6 +50,7 @@ public sealed class BattleSession
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public async Task RunAsync(CancellationToken cancellation)
|
public async Task RunAsync(CancellationToken cancellation)
|
||||||
{
|
{
|
||||||
|
_sessionCt = cancellation;
|
||||||
await SendEioOpenAsync(cancellation);
|
await SendEioOpenAsync(cancellation);
|
||||||
|
|
||||||
var buffer = new byte[8192];
|
var buffer = new byte[8192];
|
||||||
|
|||||||
Reference in New Issue
Block a user