git.iko.soy/distributed-process
on master help sign in
Implement unsafeNSendRemote.
commitbb52b3b9a9bcc319d8ffbf5186eafc9959fa5ec8 authorFacundo Domínguez <facundo.dominguez@tweag.io> dateFri 27 Nov 2015, 15:19 (11 years ago) parent222beb5
3 files changed+20
src/Control/Distributed/Process.hs+2 src/Control/Distributed/Process/Internal/Primitives.hs+8 src/Control/Distributed/Process/UnsafePrimitives.hs+10
src/Control/Distributed/Process.hs+2
@@ -43,6 +43,7 @@ module Control.Distributed.Process
4343 , unsafeUSend
4444 , unsafeSendChan
4545 , unsafeNSend
46+ , unsafeNSendRemote
4647 , unsafeWrapMessage
4748 -- * Advanced messaging
4849 , Match
@@ -216,6 +217,7 @@ import Control.Distributed.Process.Internal.Primitives
216217 , unsafeUSend
217218 , unsafeSendChan
218219 , unsafeNSend
220+ , unsafeNSendRemote
219221 -- Advanced messaging
220222 , Match
221223 , receiveWait
src/Control/Distributed/Process/Internal/Primitives.hs+8
@@ -26,6 +26,7 @@ module Control.Distributed.Process.Internal.Primitives
2626 , unsafeUSend
2727 , unsafeSendChan
2828 , unsafeNSend
29+ , unsafeNSendRemote
2930 -- * Advanced messaging
3031 , Match
3132 , receiveWait
@@ -1184,6 +1185,13 @@ nsendRemote :: Serializable a => NodeId -> String -> a -> Process ()
11841185nsendRemote nid label msg =
11851186 sendCtrlMsg (Just nid) (NamedSend label (createMessage msg))
11861187
1188+-- | Named send to a process in a remote registry (asynchronous)
1189+-- This function makes /no/ attempt to serialize and (in the case when the
1190+-- destination process resides on the same local node) therefore ensure that
1191+-- the payload is fully evaluated before it is delivered.
1192+unsafeNSendRemote :: Serializable a => NodeId -> String -> a -> Process ()
1193+unsafeNSendRemote = Unsafe.nsendRemote
1194+
11871195--------------------------------------------------------------------------------
11881196-- Closures --
11891197--------------------------------------------------------------------------------
src/Control/Distributed/Process/UnsafePrimitives.hs+10
@@ -45,6 +45,7 @@ module Control.Distributed.Process.UnsafePrimitives
4545 send
4646 , sendChan
4747 , nsend
48+ , nsendRemote
4849 , usend
4950 , wrapMessage
5051 ) where
@@ -57,6 +58,7 @@ import Control.Distributed.Process.Internal.Messaging
5758
5859import Control.Distributed.Process.Internal.Types
5960 ( ProcessId(..)
61+ , NodeId(..)
6062 , LocalNode(..)
6163 , LocalProcess(..)
6264 , Process(..)
@@ -80,6 +82,14 @@ nsend :: Serializable a => String -> a -> Process ()
8082nsend label msg =
8183 sendCtrlMsg Nothing (NamedSend label (unsafeCreateUnencodedMessage msg))
8284
85+-- | Named send to a process in a remote registry (asynchronous)
86+nsendRemote :: Serializable a => NodeId -> String -> a -> Process ()
87+nsendRemote nid label msg = do
88+ proc <- ask
89+ if localNodeId (processNode proc) == nid
90+ then nsend label msg
91+ else sendCtrlMsg (Just nid) (NamedSend label (createMessage msg))
92+
8393-- | Send a message
8494send :: Serializable a => ProcessId -> a -> Process ()
8595send them msg = do