Skip to content

Commit bb52b3b

Browse files
Implement unsafeNSendRemote.
1 parent 222beb5 commit bb52b3b

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

src/Control/Distributed/Process.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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 ()
11841185
nsendRemote 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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

5859
import 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 ()
8082
nsend 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
8494
send :: Serializable a => ProcessId -> a -> Process ()
8595
send them msg = do

0 commit comments

Comments
 (0)