git.iko.soy/distributed-process
on master help sign in
Clarify the sync/async nature of some primitives
65b2798Edsko de Vries
distributed-process/src/Control/Distributed/Process/Internal/Primitives.hs+22−9
@@ -297,7 +297,12 @@ link = sendCtrlMsg Nothing . Link . ProcessIdentifier
297monitor :: ProcessId -> Process MonitorRef
297monitor :: ProcessId -> Process MonitorRef
298monitor = monitor' . ProcessIdentifier
298monitor = monitor' . ProcessIdentifier
299
299
300−-- | Remove a link (synchronous)
300+-- | Remove a link
301+--
302+-- This is synchronous in the sense that once it returns you are guaranteed
303+-- that no exception will be raised if the remote process dies. However, it is
304+-- asynchronous in the sense that we do not wait for a response from the remote
305+-- node.
301unlink :: ProcessId -> Process ()
306unlink :: ProcessId -> Process ()
302unlink pid = do
307unlink pid = do
303 unlinkAsync pid
308 unlinkAsync pid
@@ -305,7 +310,9 @@ unlink pid = do
305 (\_ -> return ())
310 (\_ -> return ())
306 ]
311 ]
307
312
308−-- | Remove a node link (synchronous)
313+-- | Remove a node link
314+--
315+-- This has the same synchronous/asynchronous nature as 'unlink'.
309unlinkNode :: NodeId -> Process ()
316unlinkNode :: NodeId -> Process ()
310unlinkNode nid = do
317unlinkNode nid = do
311 unlinkNodeAsync nid
318 unlinkNodeAsync nid
@@ -313,7 +320,9 @@ unlinkNode nid = do
313 (\_ -> return ())
320 (\_ -> return ())
314 ]
321 ]
315
322
316−-- | Remove a channel (send port) link (synchronous)
323+-- | Remove a channel (send port) link
324+--
325+-- This has the same synchronous/asynchronous nature as 'unlink'.
317unlinkPort :: SendPort a -> Process ()
326unlinkPort :: SendPort a -> Process ()
318unlinkPort sport = do
327unlinkPort sport = do
319 unlinkPortAsync sport
328 unlinkPortAsync sport
@@ -321,7 +330,9 @@ unlinkPort sport = do
321 (\_ -> return ())
330 (\_ -> return ())
322 ]
331 ]
323
332
324−-- | Remove a monitor (synchronous)
333+-- | Remove a monitor
334+--
335+-- This has the same synchronous/asynchronous nature as 'unlink'.
325unmonitor :: MonitorRef -> Process ()
336unmonitor :: MonitorRef -> Process ()
326unmonitor ref = do
337unmonitor ref = do
327 unmonitorAsync ref
338 unmonitorAsync ref
@@ -388,12 +399,12 @@ spawnAsync nid proc = do
388 sendCtrlMsg (Just nid) $ Spawn proc spawnRef
399 sendCtrlMsg (Just nid) $ Spawn proc spawnRef
389 return spawnRef
400 return spawnRef
390
401
391−-- | Monitor a node
402+-- | Monitor a node (asynchronous)
392monitorNode :: NodeId -> Process MonitorRef
403monitorNode :: NodeId -> Process MonitorRef
393monitorNode =
404monitorNode =
394 monitor' . NodeIdentifier
405 monitor' . NodeIdentifier
395
406
396−-- | Monitor a typed channel
407+-- | Monitor a typed channel (asynchronous)
397monitorPort :: forall a. Serializable a => SendPort a -> Process MonitorRef
408monitorPort :: forall a. Serializable a => SendPort a -> Process MonitorRef
398monitorPort (SendPort cid) =
409monitorPort (SendPort cid) =
399 monitor' (SendPortIdentifier cid)
410 monitor' (SendPortIdentifier cid)
@@ -403,11 +414,11 @@ unmonitorAsync :: MonitorRef -> Process ()
403unmonitorAsync =
414unmonitorAsync =
404 sendCtrlMsg Nothing . Unmonitor
415 sendCtrlMsg Nothing . Unmonitor
405
416
406−-- | Link to a node
417+-- | Link to a node (asynchronous)
407linkNode :: NodeId -> Process ()
418linkNode :: NodeId -> Process ()
408linkNode = link' . NodeIdentifier
419linkNode = link' . NodeIdentifier
409
420
410−-- | Link to a channel (send port)
421+-- | Link to a channel (asynchronous)
411linkPort :: SendPort a -> Process ()
422linkPort :: SendPort a -> Process ()
412linkPort (SendPort cid) =
423linkPort (SendPort cid) =
413 link' (SendPortIdentifier cid)
424 link' (SendPortIdentifier cid)
@@ -471,7 +482,7 @@ unregisterRemote :: NodeId -> String -> Process ()
471unregisterRemote nid label =
482unregisterRemote nid label =
472 sendCtrlMsg (Just nid) (Register label Nothing)
483 sendCtrlMsg (Just nid) (Register label Nothing)
473
484
474−-- | Query the local process registry (synchronous).
485+-- | Query the local process registry
475whereis :: String -> Process (Maybe ProcessId)
486whereis :: String -> Process (Maybe ProcessId)
476whereis label = do
487whereis label = do
477 sendCtrlMsg Nothing (WhereIs label)
488 sendCtrlMsg Nothing (WhereIs label)
@@ -480,6 +491,8 @@ whereis label = do
480 ]
491 ]
481
492
482-- | Query a remote process registry (synchronous)
493-- | Query a remote process registry (synchronous)
494+--
495+-- TODO: what if the remote node is unreachable?
483whereisRemote :: NodeId -> String -> Process (Maybe ProcessId)
496whereisRemote :: NodeId -> String -> Process (Maybe ProcessId)
484whereisRemote nid label = do
497whereisRemote nid label = do
485 whereisRemoteAsync nid label
498 whereisRemoteAsync nid label