Switch to TVar
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing

This commit is contained in:
qvalentin 2023-06-19 17:53:40 +02:00
parent 03985cede2
commit 1e318817a4
7 changed files with 33 additions and 17 deletions

View file

@ -17,12 +17,12 @@ data Client = Client
joinedRoom :: Bool
}
type ConnectedClientsState = MVar ConnectedClients
type ConnectedClientsState = TVar ConnectedClients
type ConnectedClients = [Client]
initConnectionsState :: IO ConnectedClientsState
initConnectionsState = newMVar newConnectedClients
initConnectionsState = newTVarIO newConnectedClients
newConnectedClients :: ConnectedClients
newConnectedClients = []

View file

@ -12,10 +12,10 @@ import ClassyPrelude
import State.RoomDataState (MonadRoomDataStateRead (getRoomDataState))
import Types.RoomData (RoomsData)
type RoomsState = MVar RoomsData
type RoomsState = TVar RoomsData
initRoomsState :: IO RoomsState
initRoomsState = newMVar []
initRoomsState = newTVarIO []
class HasRoomsState a where
getRoomsState :: a -> RoomsState
@ -29,7 +29,7 @@ updateRoomState ::
m ()
updateRoomState newData = do
state <- getRoomsState <$> ask
_ <- swapMVar state newData
_ <- atomically $ swapTVar state newData
return ()
getRoomState ::
@ -40,7 +40,7 @@ getRoomState ::
m RoomsData
getRoomState = do
state <- getRoomsState <$> ask
readMVar state
readTVarIO state
roomStateDiffers ::
( MonadRoomDataStateRead m