Skip to content

Commit

Permalink
Merge pull request #282 from haskell-distributed/with-monitor-ref
Browse files Browse the repository at this point in the history
With monitor ref
  • Loading branch information
mboes committed Mar 29, 2016
2 parents 6f77480 + 077aecb commit 597c674
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/Control/Distributed/Process.hs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ module Control.Distributed.Process
, monitorPort
, unmonitor
, withMonitor
, withMonitorRef
, withMonitor_
, MonitorRef -- opaque
, ProcessLinkException(..)
, NodeLinkException(..)
Expand Down Expand Up @@ -270,7 +270,7 @@ import Control.Distributed.Process.Internal.Primitives
, monitorPort
, unmonitor
, withMonitor
, withMonitorRef
, withMonitor_
-- Logging
, say
-- Registry
Expand Down
22 changes: 10 additions & 12 deletions src/Control/Distributed/Process/Internal/Primitives.hs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ module Control.Distributed.Process.Internal.Primitives
, monitor
, unmonitor
, withMonitor
, withMonitorRef
, withMonitor_
-- * Logging
, say
-- * Registry
Expand Down Expand Up @@ -887,21 +887,19 @@ monitor = monitor' . ProcessIdentifier
-- @withMonitor@ returns, there might still be unreceived monitor
-- messages in the queue.
--
withMonitor :: ProcessId -> Process a -> Process a
withMonitor pid = withMonitorRef pid . const
-- unmonitor blocks waiting for the response, so there's a possibility
-- that an exception might interrupt withMonitor before the unmonitor
-- has completed. I think that's better than making the unmonitor
-- uninterruptible.
withMonitor :: ProcessId -> (MonitorRef -> Process a) -> Process a
withMonitor pid = bracket (monitor pid) unmonitor

-- | Establishes temporary monitoring of another process.
--
-- @withMonitorRef pid code@ sets up monitoring of @pid@ for the duration
-- of @code@. Note: although monitoring is no longer active when
-- @withMonitorRef@ returns, there might still be unreceived monitor
-- @withMonitor_ pid code@ sets up monitoring of @pid@ for the duration
-- of @code@. Note: although monitoring is no longer active when
-- @withMonitor_@ returns, there might still be unreceived monitor
-- messages in the queue.
withMonitorRef :: ProcessId -> (MonitorRef -> Process a) -> Process a
withMonitorRef pid code = bracket (monitor pid) unmonitor code
--
-- Since 0.6.1
withMonitor_ :: ProcessId -> Process a -> Process a
withMonitor_ p = withMonitor p . const

-- | Remove a link
--
Expand Down

0 comments on commit 597c674

Please sign in to comment.