git.iko.soy/distributed-process
on master help sign in
add withMonitorRef primitive.
6dfd5b1Alexander Vershilov
src/Control/Distributed/Process.hs+2
@@ -102,6 +102,7 @@ module Control.Distributed.Process
102 , monitorPort
102 , monitorPort
103 , unmonitor
103 , unmonitor
104 , withMonitor
104 , withMonitor
105+ , withMonitorRef
105 , MonitorRef -- opaque
106 , MonitorRef -- opaque
106 , ProcessLinkException(..)
107 , ProcessLinkException(..)
107 , NodeLinkException(..)
108 , NodeLinkException(..)
@@ -267,6 +268,7 @@ import Control.Distributed.Process.Internal.Primitives
267 , monitorPort
268 , monitorPort
268 , unmonitor
269 , unmonitor
269 , withMonitor
270 , withMonitor
271+ , withMonitorRef
270 -- Logging
272 -- Logging
271 , say
273 , say
272 -- Registry
274 -- Registry
src/Control/Distributed/Process/Internal/Primitives.hs+11−1
@@ -77,6 +77,7 @@ module Control.Distributed.Process.Internal.Primitives
77 , monitor
77 , monitor
78 , unmonitor
78 , unmonitor
79 , withMonitor
79 , withMonitor
80+ , withMonitorRef
80 -- * Logging
81 -- * Logging
81 , say
82 , say
82 -- * Registry
83 -- * Registry
@@ -887,12 +888,21 @@ monitor = monitor' . ProcessIdentifier
887-- messages in the queue.
888-- messages in the queue.
888--
889--
889withMonitor :: ProcessId -> Process a -> Process a
890withMonitor :: ProcessId -> Process a -> Process a
890−withMonitor pid code = bracket (monitor pid) unmonitor (\_ -> code)
891+withMonitor pid = withMonitorRef pid . const
891 -- unmonitor blocks waiting for the response, so there's a possibility
892 -- unmonitor blocks waiting for the response, so there's a possibility
892 -- that an exception might interrupt withMonitor before the unmonitor
893 -- that an exception might interrupt withMonitor before the unmonitor
893 -- has completed. I think that's better than making the unmonitor
894 -- has completed. I think that's better than making the unmonitor
894 -- uninterruptible.
895 -- uninterruptible.
895
896
897+-- | Establishes temporary monitoring of another process.
898+--
899+-- @withMonitorRef pid code@ sets up monitoring of @pid@ for the duration
900+-- of @code@. Note: although monitoring is no longer active when
901+-- @withMonitorRef@ returns, there might still be unreceived monitor
902+-- messages in the queue.
903+withMonitorRef :: ProcessId -> (MonitorRef -> Process a) -> Process a
904+withMonitorRef pid code = bracket (monitor pid) unmonitor code
905+
896-- | Remove a link
906-- | Remove a link
897--
907--
898-- This is synchronous in the sense that once it returns you are guaranteed
908-- This is synchronous in the sense that once it returns you are guaranteed