Skip to content

Commit 1b7f8ac

Browse files
committed
WIP creating type to print multiplexer state
1 parent 92ca0ac commit 1b7f8ac

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/PostgresWebsockets/Broadcast.hs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
{-# LANGUAGE DeriveGeneric #-}
2+
13
-- |
24
-- Module : PostgresWebsockets.Broadcast
35
-- Description : Distribute messages from one producer to several consumers.
@@ -26,8 +28,9 @@ where
2628

2729
import Control.Concurrent.STM.TChan
2830
import Control.Concurrent.STM.TQueue
31+
import qualified Data.Aeson as A
2932
import Protolude hiding (toS)
30-
import Protolude.Conv
33+
import Protolude.Conv (toS)
3134
import qualified StmContainers.Map as M
3235

3336
data Message = Message
@@ -43,11 +46,20 @@ data Multiplexer = Multiplexer
4346
reopenProducer :: IO ThreadId
4447
}
4548

49+
data MultiplexerSnapshot = MultiplexerSnapshot
50+
{ channelsSize :: Int,
51+
messageQueueEmpty :: Bool,
52+
producerId :: Text
53+
}
54+
deriving (Generic)
55+
4656
data Channel = Channel
4757
{ broadcast :: TChan Message,
4858
listeners :: Integer
4959
}
5060

61+
instance A.ToJSON MultiplexerSnapshot
62+
5163
-- | Opens a thread that relays messages from the producer thread to the channels forever
5264
relayMessagesForever :: Multiplexer -> IO ThreadId
5365
relayMessagesForever = forkIO . forever . relayMessages

0 commit comments

Comments
 (0)