git.iko.soy/distributed-process
on master help sign in
Merge pull request #279 from haskell-distributed/with-monitor-ref

add withMonitorRef primitive.

commite54dcf1815728521988562df05c4803376f5c80b authorFacundo Domínguez <facundominguez@gmail.com> dateThu 10 Mar 2016, 21:13 (11 years ago) parent8b74cce6dfd5b1
2 files changed+13−1
src/Control/Distributed/Process.hs+2 src/Control/Distributed/Process/Internal/Primitives.hs+11−1
src/Control/Distributed/Process.hs+2
@@ -102,6 +102,7 @@ module Control.Distributed.Process
102102 , monitorPort
103103 , unmonitor
104104 , withMonitor
105+ , withMonitorRef
105106 , MonitorRef -- opaque
106107 , ProcessLinkException(..)
107108 , NodeLinkException(..)
@@ -267,6 +268,7 @@ import Control.Distributed.Process.Internal.Primitives
267268 , monitorPort
268269 , unmonitor
269270 , withMonitor
271+ , withMonitorRef
270272 -- Logging
271273 , say
272274 -- Registry
src/Control/Distributed/Process/Internal/Primitives.hs+11−1
@@ -77,6 +77,7 @@ module Control.Distributed.Process.Internal.Primitives
7777 , monitor
7878 , unmonitor
7979 , withMonitor
80+ , withMonitorRef
8081 -- * Logging
8182 , say
8283 -- * Registry
@@ -887,12 +888,21 @@ monitor = monitor' . ProcessIdentifier
887888-- messages in the queue.
888889--
889890withMonitor :: ProcessId -> Process a -> Process a
890−withMonitor pid code = bracket (monitor pid) unmonitor (\_ -> code)
891+withMonitor pid = withMonitorRef pid . const
891892 -- unmonitor blocks waiting for the response, so there's a possibility
892893 -- that an exception might interrupt withMonitor before the unmonitor
893894 -- has completed. I think that's better than making the unmonitor
894895 -- uninterruptible.
895896
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+
896906-- | Remove a link
897907--
898908-- This is synchronous in the sense that once it returns you are guaranteed