Fix server shut down on exit.

If there's a websocket being waited on the shut down won't actually
happen. Add a new event for shut down and send it to break the websocket
out of its loop.
This commit is contained in:
Dan Albert
2022-02-25 17:12:00 -08:00
parent 2efe4f6c80
commit af4a718fc7
3 changed files with 12 additions and 0 deletions

View File

@@ -14,6 +14,10 @@ async def event_stream(websocket: WebSocket) -> None:
await websocket.accept()
while True:
if not (events := await EventStream.get()).empty:
if events.shutting_down:
await websocket.close()
return
await websocket.send_json(
jsonable_encoder(
GameUpdateEventsJs.from_events(events, GameContext.get())