postgres-websockets-0.11.2.2: Middleware to map LISTEN/NOTIFY messages to Websockets
Safe HaskellSafe-Inferred
LanguageHaskell2010

PostgresWebsockets.Broadcast

Contents

Description

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

Documentation

data Message Source #

Constructors

Message 

Fields

Instances

Instances details
Show Message Source # 
Instance details

Defined in PostgresWebsockets.Broadcast

Eq Message Source # 
Instance details

Defined in PostgresWebsockets.Broadcast

Methods

(==) :: Message -> Message -> Bool #

(/=) :: Message -> Message -> Bool #

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.

readTChan :: TChan a -> STM a #

Read the next value from the TChan.