From 5ce06f28f06518030e1ea39ee4cb152260f06243 Mon Sep 17 00:00:00 2001 From: linomp Date: Sat, 30 Mar 2024 20:22:09 +0100 Subject: [PATCH] add nullcheck for publishing func --- mvp/server/core/game/GameSession.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mvp/server/core/game/GameSession.py b/mvp/server/core/game/GameSession.py index 593a402..8163c4b 100644 --- a/mvp/server/core/game/GameSession.py +++ b/mvp/server/core/game/GameSession.py @@ -66,7 +66,8 @@ def check_if_game_over(self) -> bool: return self.is_game_over - async def advance_one_turn(self, publishing_func: Callable[['GameSession'], None]) -> list[MachineState]: + async def advance_one_turn(self, publishing_func: Callable[['GameSession'], None] | None = None) -> list[ + MachineState]: collected_machine_states_during_turn = [] self.last_updated = datetime.now() @@ -85,7 +86,9 @@ async def advance_one_turn(self, publishing_func: Callable[['GameSession'], None self.available_funds += math.ceil(REVENUE_PER_DAY / TIMESTEPS_PER_MOVE) self._log() - publishing_func(self) + if publishing_func is not None: + publishing_func(self) + await asyncio.sleep(GAME_TICK_INTERVAL) self.machine_state.update_prediction(