git.iko.soy/distributed-process
on master help sign in
Implement unsafeUSend.
commit222beb5f7e71c61687459fefbccaad65f9224c0f authorFacundo Domínguez <facundo.dominguez@tweag.io> dateFri 27 Nov 2015, 14:42 (11 years ago) parentdeadc44
3 files changed+31
src/Control/Distributed/Process.hs+2 src/Control/Distributed/Process/Internal/Primitives.hs+8 src/Control/Distributed/Process/UnsafePrimitives.hs+21
src/Control/Distributed/Process.hs+2
@@ -40,6 +40,7 @@ module Control.Distributed.Process
4040 , mergePortsRR
4141 -- * Unsafe messaging variants
4242 , unsafeSend
43+ , unsafeUSend
4344 , unsafeSendChan
4445 , unsafeNSend
4546 , unsafeWrapMessage
@@ -212,6 +213,7 @@ import Control.Distributed.Process.Internal.Primitives
212213 , mergePortsBiased
213214 , mergePortsRR
214215 , unsafeSend
216+ , unsafeUSend
215217 , unsafeSendChan
216218 , unsafeNSend
217219 -- Advanced messaging
src/Control/Distributed/Process/Internal/Primitives.hs+8
@@ -23,6 +23,7 @@ module Control.Distributed.Process.Internal.Primitives
2323 , mergePortsRR
2424 -- * Unsafe messaging variants
2525 , unsafeSend
26+ , unsafeUSend
2627 , unsafeSendChan
2728 , unsafeNSend
2829 -- * Advanced messaging
@@ -279,6 +280,13 @@ usend them msg = do
279280 else sendCtrlMsg (Just there) $ UnreliableSend (processLocalId them)
280281 (createMessage msg)
281282
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+
282290-- | Wait for a message of a specific type
283291expect :: forall a. Serializable a => Process a
284292expect = receiveWait [match return]
src/Control/Distributed/Process/UnsafePrimitives.hs+21
@@ -45,6 +45,7 @@ module Control.Distributed.Process.UnsafePrimitives
4545 send
4646 , sendChan
4747 , nsend
48+ , usend
4849 , wrapMessage
4950 ) where
5051
@@ -65,6 +66,7 @@ import Control.Distributed.Process.Internal.Types
6566 , ImplicitReconnect(..)
6667 , SendPortId(..)
6768 , Message
69+ , createMessage
6870 , sendPortProcessId
6971 , unsafeCreateUnencodedMessage
7072 )
@@ -96,6 +98,25 @@ send them msg = do
9698 unsafeSendLocal pid msg' =
9799 sendCtrlMsg Nothing $ LocalSend pid (unsafeCreateUnencodedMessage msg')
98100
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+
99120-- | Send a message on a typed channel
100121sendChan :: Serializable a => SendPort a -> a -> Process ()
101122sendChan (SendPort cid) msg = do