Switch to TVar
This commit is contained in:
parent
03985cede2
commit
1e318817a4
7 changed files with 33 additions and 17 deletions
|
@ -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 = []
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue