git.iko.soy/distributed-process
on master help sign in
Merge pull request #183 from tweag/call-monitor-race
f5f67eaAlexander Vershilov
src/Control/Distributed/Process/Internal/Spawn.hs+9−5
@@ -38,6 +38,8 @@ import Control.Distributed.Process.Internal.Closure.BuiltIn
38 , cpSend
38 , cpSend
39 , cpNewChan
39 , cpNewChan
40 , cpDelayed
40 , cpDelayed
41+ , returnCP
42+ , sdictUnit
41 )
43 )
42import Control.Distributed.Process.Internal.Primitives
44import Control.Distributed.Process.Internal.Primitives
43 ( -- Basic messaging
45 ( -- Basic messaging
@@ -109,12 +111,14 @@ call :: Serializable a
109 -> Process a
111 -> Process a
110call dict nid proc = do
112call dict nid proc = do
111 us <- getSelfPid
113 us <- getSelfPid
112− (pid, mRef) <- spawnMonitor nid (proc `bindCP` cpSend dict us)
114+ (pid, mRef) <- spawnMonitor nid (proc `bindCP`
113− -- We are guaranteed to receive the reply before the monitor notification
115+ cpSend dict us `seqCP`
114− -- (if a reply is sent at all)
116+ -- Delay so the process does not terminate
115− -- NOTE: This might not be true if we switch to unreliable delivery.
117+ -- before the response arrives.
118+ cpDelayed us (returnCP sdictUnit ())
119+ )
116 mResult <- receiveWait
120 mResult <- receiveWait
117− [ match (return . Right)
121+ [ match $ \a -> send pid () >> return (Right a)
118 , matchIf (\(ProcessMonitorNotification ref _ _) -> ref == mRef)
122 , matchIf (\(ProcessMonitorNotification ref _ _) -> ref == mRef)
119 (\(ProcessMonitorNotification _ _ reason) -> return (Left reason))
123 (\(ProcessMonitorNotification _ _ reason) -> return (Left reason))
120 ]
124 ]