pituicat/src/Affection/MessageBus.hs
2017-11-26 13:59:59 +01:00

23 lines
558 B
Haskell

module Affection.MessageBus where
import Control.Concurrent.STM as STM
import Data.IORef
class Message msg where
msgPayload :: msg -> Maybe a
type Channel msg = TChan msg
class Participant prt where
partChannel :: (Message msg) => prt -> IORef (Channel msg)
partConnectChannel :: (Message msg) => prt -> (Channel msg) -> IO ()
partListen :: (Message msg) => prt -> IO msg
partBroadcast :: (Message msg) => prt -> msg -> IO ()
newBroadcastChannel :: IO (Channel msg)
newBroadcastChannel = atomically $ newBroadcastTChan