2017-11-27 00:43:43 +00:00
|
|
|
{-# LANGUAGE MultiParamTypeClasses #-}
|
2017-11-26 21:26:41 +00:00
|
|
|
module Affection.MessageBus.Class where
|
|
|
|
|
|
|
|
import Affection.MessageBus.Message
|
2017-11-27 22:30:11 +00:00
|
|
|
import Affection.Types
|
2017-11-26 21:26:41 +00:00
|
|
|
|
2017-12-12 12:12:27 +00:00
|
|
|
class (Message m) => Participant prt m where
|
|
|
|
-- | get the outbound 'Channel' of the 'Participant'
|
|
|
|
partChannel
|
|
|
|
:: prt -- ^ The 'Participant'
|
|
|
|
-> Channel m -- ^ Outbound 'Channel'
|
2017-11-26 21:26:41 +00:00
|
|
|
|
2017-12-12 12:12:27 +00:00
|
|
|
-- | Initialize the 'Participant' with an inbound 'Channel'
|
|
|
|
partInit
|
|
|
|
:: Channel m -- ^ Inbound 'Channel' the 'Participant' will listen to
|
|
|
|
-> Affection sd prt -- ^ The constructed and initialized 'Participant'
|
2017-11-26 21:26:41 +00:00
|
|
|
|
2017-12-12 12:12:27 +00:00
|
|
|
-- Get the 'Participant' to listen to its inbound 'Channel'
|
|
|
|
partListen
|
|
|
|
:: prt -- ^ The 'Participant'
|
|
|
|
-> Affection sd (Maybe m) -- ^ The optional 'Message' peeked from the 'Channel'
|
2017-11-26 21:26:41 +00:00
|
|
|
|
2017-12-12 12:12:27 +00:00
|
|
|
-- Get the 'Participant' to emit a Message on its outbound 'Channel'
|
|
|
|
partEmit
|
|
|
|
:: prt -- ^ The 'Participant'
|
|
|
|
-> m -- ^ The 'Message' to emit
|
|
|
|
-> Affection sd ()
|
|
|
|
|
|
|
|
-- data Envelope = Envelope
|
|
|
|
-- { envFrom :: (Participant a _) => a
|
|
|
|
-- , envTo :: (Participant b _) => b
|
|
|
|
-- , envMessage :: (Message msg) => msg
|
|
|
|
-- }
|