git.iko.soy/distributed-process
on master help sign in
Merge branch 'master' of github:haskell-distributed/distributed-process
3f4370bghc722
distributed-process/src/Control/Distributed/Process.hs+14−3
@@ -291,12 +291,23 @@ spawnMonitor nid proc = do
291
291
292-- | Run a process remotely and wait for it to reply
292-- | Run a process remotely and wait for it to reply
293--
293--
294−-- We link to the remote process, so that if it dies, we die too.
294+-- We monitor the remote process; if it dies before it can send a reply, we die
295+-- too
295call :: SerializableDict a -> NodeId -> Closure (Process a) -> Process a
296call :: SerializableDict a -> NodeId -> Closure (Process a) -> Process a
296call sdict@SerializableDict nid proc = do
297call sdict@SerializableDict nid proc = do
297 us <- getSelfPid
298 us <- getSelfPid
298− _ <- spawnLink nid (proc `cpBind` sendClosure sdict us)
299+ (_, mRef) <- spawnMonitor nid (proc `cpBind` sendClosure sdict us)
299− expect
300+ -- We are guaranteed to receive the reply before the monitor notification
301+ -- (if a reply is sent at all)
302+ -- NOTE: This might not be true if we switch to unreliable delivery.
303+ mResult <- receiveWait
304+ [ match (return . Right)
305+ , matchIf (\(ProcessMonitorNotification ref _ _) -> ref == mRef)
306+ (\(ProcessMonitorNotification _ _ reason) -> return (Left reason))
307+ ]
308+ case mResult of
309+ Right a -> unmonitor mRef >> return a
310+ Left err -> fail $ "call: remote process died: " ++ show err
300
311
301-- | Spawn a child process, have the child link to the parent and the parent
312-- | Spawn a child process, have the child link to the parent and the parent
302-- monitor the child
313-- monitor the child