packages feed

raketka-1.2.0: src/Control/Distributed/Raketka/Process/Send.hs

module Control.Distributed.Raketka.Process.Send
   (sendRemote,
   sendRemoteAll)  where

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 tag ps s c =>
    tag (Server ps s) -> ProcessId -> Message c -> STM ()
sendRemote taggedServer pid pmsg = writeTChan (proxychan server) (send pid pmsg)
   where server = untag taggedServer

{- | broadcast message to all known peers -}
sendRemoteAll :: Content tag ps s c =>
    tag (Server ps s) -> Message c -> STM ()
sendRemoteAll taggedServer0 pmsg0 = do
    pids1 <- readTVar servers1
    mapM_
         (\pid1 -> sendRemote taggedServer0 pid1 pmsg0) $
         peer_pids pids1
    where servers1 = servers $ untag taggedServer0