git.iko.soy/distributed-process
on master help sign in
Implement unsafeNSendRemote.
bb52b3bFacundo Domínguez
src/Control/Distributed/Process.hs+2
@@ -43,6 +43,7 @@ module Control.Distributed.Process
43 , unsafeUSend
43 , unsafeUSend
44 , unsafeSendChan
44 , unsafeSendChan
45 , unsafeNSend
45 , unsafeNSend
46+ , unsafeNSendRemote
46 , unsafeWrapMessage
47 , unsafeWrapMessage
47 -- * Advanced messaging
48 -- * Advanced messaging
48 , Match
49 , Match
@@ -216,6 +217,7 @@ import Control.Distributed.Process.Internal.Primitives
216 , unsafeUSend
217 , unsafeUSend
217 , unsafeSendChan
218 , unsafeSendChan
218 , unsafeNSend
219 , unsafeNSend
220+ , unsafeNSendRemote
219 -- Advanced messaging
221 -- Advanced messaging
220 , Match
222 , Match
221 , receiveWait
223 , receiveWait
src/Control/Distributed/Process/Internal/Primitives.hs+8
@@ -26,6 +26,7 @@ module Control.Distributed.Process.Internal.Primitives
26 , unsafeUSend
26 , unsafeUSend
27 , unsafeSendChan
27 , unsafeSendChan
28 , unsafeNSend
28 , unsafeNSend
29+ , unsafeNSendRemote
29 -- * Advanced messaging
30 -- * Advanced messaging
30 , Match
31 , Match
31 , receiveWait
32 , receiveWait
@@ -1184,6 +1185,13 @@ nsendRemote :: Serializable a => NodeId -> String -> a -> Process ()
1184nsendRemote nid label msg =
1185nsendRemote nid label msg =
1185 sendCtrlMsg (Just nid) (NamedSend label (createMessage msg))
1186 sendCtrlMsg (Just nid) (NamedSend label (createMessage msg))
1186
1187
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+
1187--------------------------------------------------------------------------------
1195--------------------------------------------------------------------------------
1188-- Closures --
1196-- Closures --
1189--------------------------------------------------------------------------------
1197--------------------------------------------------------------------------------
src/Control/Distributed/Process/UnsafePrimitives.hs+10
@@ -45,6 +45,7 @@ module Control.Distributed.Process.UnsafePrimitives
45 send
45 send
46 , sendChan
46 , sendChan
47 , nsend
47 , nsend
48+ , nsendRemote
48 , usend
49 , usend
49 , wrapMessage
50 , wrapMessage
50 ) where
51 ) where
@@ -57,6 +58,7 @@ import Control.Distributed.Process.Internal.Messaging
57
58
58import Control.Distributed.Process.Internal.Types
59import Control.Distributed.Process.Internal.Types
59 ( ProcessId(..)
60 ( ProcessId(..)
61+ , NodeId(..)
60 , LocalNode(..)
62 , LocalNode(..)
61 , LocalProcess(..)
63 , LocalProcess(..)
62 , Process(..)
64 , Process(..)
@@ -80,6 +82,14 @@ nsend :: Serializable a => String -> a -> Process ()
80nsend label msg =
82nsend label msg =
81 sendCtrlMsg Nothing (NamedSend label (unsafeCreateUnencodedMessage msg))
83 sendCtrlMsg Nothing (NamedSend label (unsafeCreateUnencodedMessage msg))
82
84
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+
83-- | Send a message
93-- | Send a message
84send :: Serializable a => ProcessId -> a -> Process ()
94send :: Serializable a => ProcessId -> a -> Process ()
85send them msg = do
95send them msg = do