File tree Expand file tree Collapse file tree 3 files changed +31
-0
lines changed Expand file tree Collapse file tree 3 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -40,6 +40,7 @@ module Control.Distributed.Process
40
40
, mergePortsRR
41
41
-- * Unsafe messaging variants
42
42
, unsafeSend
43
+ , unsafeUSend
43
44
, unsafeSendChan
44
45
, unsafeNSend
45
46
, unsafeWrapMessage
@@ -212,6 +213,7 @@ import Control.Distributed.Process.Internal.Primitives
212
213
, mergePortsBiased
213
214
, mergePortsRR
214
215
, unsafeSend
216
+ , unsafeUSend
215
217
, unsafeSendChan
216
218
, unsafeNSend
217
219
-- Advanced messaging
Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ module Control.Distributed.Process.Internal.Primitives
23
23
, mergePortsRR
24
24
-- * Unsafe messaging variants
25
25
, unsafeSend
26
+ , unsafeUSend
26
27
, unsafeSendChan
27
28
, unsafeNSend
28
29
-- * Advanced messaging
@@ -279,6 +280,13 @@ usend them msg = do
279
280
else sendCtrlMsg (Just there) $ UnreliableSend (processLocalId them)
280
281
(createMessage msg)
281
282
283
+ -- | /Unsafe/ variant of 'usend'. This function makes /no/ attempt to serialize
284
+ -- the message when the destination process resides on the same local
285
+ -- node. Therefore, a local receiver would need to be prepared to cope with any
286
+ -- errors resulting from evaluation of the message.
287
+ unsafeUSend :: Serializable a => ProcessId -> a -> Process ()
288
+ unsafeUSend = Unsafe. usend
289
+
282
290
-- | Wait for a message of a specific type
283
291
expect :: forall a . Serializable a => Process a
284
292
expect = receiveWait [match return ]
Original file line number Diff line number Diff line change @@ -45,6 +45,7 @@ module Control.Distributed.Process.UnsafePrimitives
45
45
send
46
46
, sendChan
47
47
, nsend
48
+ , usend
48
49
, wrapMessage
49
50
) where
50
51
@@ -65,6 +66,7 @@ import Control.Distributed.Process.Internal.Types
65
66
, ImplicitReconnect (.. )
66
67
, SendPortId (.. )
67
68
, Message
69
+ , createMessage
68
70
, sendPortProcessId
69
71
, unsafeCreateUnencodedMessage
70
72
)
@@ -96,6 +98,25 @@ send them msg = do
96
98
unsafeSendLocal pid msg' =
97
99
sendCtrlMsg Nothing $ LocalSend pid (unsafeCreateUnencodedMessage msg')
98
100
101
+ -- | Send a message unreliably.
102
+ --
103
+ -- Unlike 'send', this function is insensitive to 'reconnect'. It will
104
+ -- try to send the message regardless of the history of connection failures
105
+ -- between the nodes.
106
+ --
107
+ -- Message passing with 'usend' is ordered for a given sender and receiver
108
+ -- if the messages arrive at all.
109
+ --
110
+ usend :: Serializable a => ProcessId -> a -> Process ()
111
+ usend them msg = do
112
+ proc <- ask
113
+ let there = processNodeId them
114
+ if localNodeId (processNode proc ) == there
115
+ then sendCtrlMsg Nothing $
116
+ LocalSend them (unsafeCreateUnencodedMessage msg)
117
+ else sendCtrlMsg (Just there) $ UnreliableSend (processLocalId them)
118
+ (createMessage msg)
119
+
99
120
-- | Send a message on a typed channel
100
121
sendChan :: Serializable a => SendPort a -> a -> Process ()
101
122
sendChan (SendPort cid) msg = do
You can’t perform that action at this time.
0 commit comments