Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
PostgresWebsockets functions to broadcast messages to several listening clients This module provides a type called Multiplexer. The multiplexer contains a map of channels and a producer thread.
This module avoids any database implementation details, it is used by HasqlBroadcast where the database logic is combined.
Synopsis
- data Multiplexer
- data Message = Message {}
- newMultiplexer :: (TQueue Message -> IO a) -> (Either SomeException a -> IO ()) -> IO Multiplexer
- onMessage :: Multiplexer -> Text -> (Message -> IO ()) -> IO ()
- relayMessages :: Multiplexer -> IO ()
- relayMessagesForever :: Multiplexer -> IO ThreadId
- superviseMultiplexer :: Multiplexer -> Int -> IO Bool -> IO ()
- readTQueue :: TQueue a -> STM a
- writeTQueue :: TQueue a -> a -> STM ()
- readTChan :: TChan a -> STM a
Documentation
data Multiplexer Source #
Instances
newMultiplexer :: (TQueue Message -> IO a) -> (Either SomeException a -> IO ()) -> IO Multiplexer Source #
onMessage :: Multiplexer -> Text -> (Message -> IO ()) -> IO () Source #
Adds a listener to a certain multiplexer's channel. The listener must be a function that takes a 'TChan Message' and perform any IO action. All listeners run in their own thread. The first listener will open the channel, when a listener dies it will check if there acquire any others and close the channel when that's the case.
relayMessages :: Multiplexer -> IO () Source #
Reads the messages from the producer and relays them to the active listeners in their respective channels.
relayMessagesForever :: Multiplexer -> IO ThreadId Source #
Opens a thread that relays messages from the producer thread to the channels forever
superviseMultiplexer :: Multiplexer -> Int -> IO Bool -> IO () Source #
Given a multiplexer, a number of milliseconds and an IO computation that returns a boolean Runs the IO computation at every interval of milliseconds interval and reopens the multiplexer producer if the resulting boolean is true When interval is 0 this is NOOP, so the minimum interval is 1ms Call this in case you want to ensure the producer thread is killed and restarted under a certain condition
Re-exports
readTQueue :: TQueue a -> STM a #
Read the next value from the TQueue
.
writeTQueue :: TQueue a -> a -> STM () #
Write a value to a TQueue
.