raketka-1.0: src/Control/Distributed/Raketka/Process/Send.hs
module Control.Distributed.Raketka.Process.Send
(sendRemote,
sendRemoteAll) where
import Data.Tagged
import Control.Concurrent.STM
import Control.Distributed.Raketka.Type.Server
import Control.Distributed.Process
hiding (Message, mask, finally, handleMessage, proxy)
import Control.Distributed.Raketka.Type.Message
{- | send message to 'ProcessId'.
Other ways of sending messages are not implemented to keep the code basic.
-}
sendRemote::Content c =>
Tagged c Server -> ProcessId -> Message c -> STM ()
sendRemote (Tagged Server{..}) pid pmsg =
writeTChan proxychan (send pid pmsg)
{- | broadcast message to all known peers -}
sendRemoteAll::Content c =>
Tagged c Server -> Message c -> STM ()
sendRemoteAll s1@(Tagged server0@Server{..}) pmsg0 = do
pids1 <- readTVar servers
mapM_ (\pid1 -> sendRemote s1 pid1 pmsg0) pids1