module Control.Distributed.Process.Management.Internal.Bus
( publishEvent
) where
import Control.Distributed.Process.Internal.CQueue
( enqueue
)
import Control.Distributed.Process.Internal.Types
( MxEventBus(..)
, Message
)
import Data.Foldable (forM_)
import System.Mem.Weak (deRefWeak)
publishEvent :: MxEventBus -> Message -> IO ()
publishEvent :: MxEventBus -> Message -> IO ()
publishEvent MxEventBus
MxEventBusInitialising Message
_ = () -> IO ()
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
publishEvent (MxEventBus ProcessId
_ Tracer
_ Weak (CQueue Message)
wqRef ((TChan Message, TChan Message) -> Process ()) -> IO ProcessId
_) Message
msg = do
Maybe (CQueue Message)
mQueue <- Weak (CQueue Message) -> IO (Maybe (CQueue Message))
forall v. Weak v -> IO (Maybe v)
deRefWeak Weak (CQueue Message)
wqRef
Maybe (CQueue Message) -> (CQueue Message -> IO ()) -> IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ Maybe (CQueue Message)
mQueue ((CQueue Message -> IO ()) -> IO ())
-> (CQueue Message -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \CQueue Message
queue -> CQueue Message -> Message -> IO ()
forall a. CQueue a -> a -> IO ()
enqueue CQueue Message
queue Message
msg