postgrest-ws-0.2.0.0: PostgREST extension to map LISTEN/NOTIFY messages to Websockets

Safe HaskellNone
LanguageHaskell2010

PostgRESTWS.Broadcast

Contents

Description

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 

onMessage :: Multiplexer -> ByteString -> (TChan 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

openChannelProducer :: Multiplexer -> ByteString -> STM () Source #

Open a multiplexer's channel

closeChannelProducer :: Multiplexer -> ByteString -> STM () Source #

Close a multiplexer's channel

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.