File tree Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change
1
+ {-# LANGUAGE DeriveGeneric #-}
2
+
1
3
-- |
2
4
-- Module : PostgresWebsockets.Broadcast
3
5
-- Description : Distribute messages from one producer to several consumers.
26
28
27
29
import Control.Concurrent.STM.TChan
28
30
import Control.Concurrent.STM.TQueue
31
+ import qualified Data.Aeson as A
29
32
import Protolude hiding (toS )
30
- import Protolude.Conv
33
+ import Protolude.Conv ( toS )
31
34
import qualified StmContainers.Map as M
32
35
33
36
data Message = Message
@@ -43,11 +46,20 @@ data Multiplexer = Multiplexer
43
46
reopenProducer :: IO ThreadId
44
47
}
45
48
49
+ data MultiplexerSnapshot = MultiplexerSnapshot
50
+ { channelsSize :: Int ,
51
+ messageQueueEmpty :: Bool ,
52
+ producerId :: Text
53
+ }
54
+ deriving (Generic )
55
+
46
56
data Channel = Channel
47
57
{ broadcast :: TChan Message ,
48
58
listeners :: Integer
49
59
}
50
60
61
+ instance A. ToJSON MultiplexerSnapshot
62
+
51
63
-- | Opens a thread that relays messages from the producer thread to the channels forever
52
64
relayMessagesForever :: Multiplexer -> IO ThreadId
53
65
relayMessagesForever = forkIO . forever . relayMessages
You can’t perform that action at this time.
0 commit comments