@@ -36,6 +36,7 @@ module Control.Distributed.Process.Internal.Primitives
38 , unmonitor
38 , unmonitor
39 -- * Logging
40 -- * Logging
41 -- * Registry
42 -- * Registry
@@ -436,6 +437,20 @@ link = sendCtrlMsg Nothing . Link . ProcessIdentifier
436monitor :: ProcessId -> Process MonitorRef
437monitor :: ProcessId -> Process MonitorRef
437monitor = monitor' . ProcessIdentifier
438monitor = monitor' . ProcessIdentifier
440+-- | Establishes temporary monitoring of another process.
442+-- @withMonitor pid code@ sets up monitoring of @pid@ for the duration
443+-- of @code@. Note: although monitoring is no longer active when
444+-- @withMonitor@ returns, there might still be unreceived monitor
445+-- messages in the queue.
447+withMonitor :: ProcessId -> Process a -> Process a
448+withMonitor pid code = bracket (monitor pid) unmonitor (\_ -> code)
449+ -- unmonitor blocks waiting for the response, so there's a possibility
450+ -- that an exception might interrupt withMonitor before the unmonitor
451+ -- has completed. I think that's better than making the unmonitor
439-- | Remove a link
454-- | Remove a link
441-- This is synchronous in the sense that once it returns you are guaranteed
456-- This is synchronous in the sense that once it returns you are guaranteed