Cancel CPU turns immediately when host ends game
Convert CPU turn chain to a cancellable asyncio.Task tracked on Room, so ending the game or leaving no longer blocks waiting for CPU sleeps. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -473,6 +473,15 @@ async def handle_end_game(data: dict, ctx: ConnectionContext, *, room_manager, c
|
||||
await ctx.websocket.send_json({"type": "error", "message": "Only the host can end the game"})
|
||||
return
|
||||
|
||||
# Cancel any running CPU turn task so the game ends immediately
|
||||
if ctx.current_room.cpu_turn_task:
|
||||
ctx.current_room.cpu_turn_task.cancel()
|
||||
try:
|
||||
await ctx.current_room.cpu_turn_task
|
||||
except (asyncio.CancelledError, Exception):
|
||||
pass
|
||||
ctx.current_room.cpu_turn_task = None
|
||||
|
||||
await ctx.current_room.broadcast({
|
||||
"type": "game_ended",
|
||||
"reason": "Host ended the game",
|
||||
|
||||
Reference in New Issue
Block a user