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