Skip to content

[DevEx]: Refactor to consolidate check-game-state-for-win and check-game-state-for-win-sync #1325

@itsalaidbacklife

Description

@itsalaidbacklife

Improvement Summary

We currently have async and synchronous versions of checkGameStateForWin(). We should combine these single, synchronous version that's used everywhere, adding additional processing to the consumers of the current async check-game-state-for-win method to individually handle the side effects added by the async version

Detailed Description

checkGameStateForWin() (the async version) handles side effects of:

  • Adding the game to its match
  • Updating the game's status to GameStatus.FINISHED and setting the winner field if the game is over

It works this way because the method already computes whether a player has won and this is the key info needed to decide whether to clean up the game record as described.

The only place that those side effects really should be applied are in the move and ai-move controller endpoints e.g. when a new move is made, if it ends the game, we should then clean up.

This means we should remove the existing implementation of checkWinGameState() and rename checkWinGameStateSync() to simply checkWinGameState() (keeping it sync without the cleanup side effects), then update all consumers of either method to call checkWinGameState() and for the places that use the previously async version to conditionally execute the cleanup logic (setting game status + winner) in the endpoint itself

Metadata

Metadata

Assignees

No one assigned

    Labels

    backendRequires changes to the (node) backend webserverdev experienceImprovements to the code base that make it easier/better/more enjoyable to contribute to Cuttleversion-patchAn update that warrants a bumping the project's patch version (e.g. 4.0.0 => 4.0.1)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions