git.iko.soy/distributed-process
on master help sign in
Remove monitor message in unmonitor.
1e0284fFacundo Domínguez
src/Control/Distributed/Process/Internal/Primitives.hs+11−1
@@ -134,7 +134,7 @@ import Data.Time.Format (defaultTimeLocale)
134import System.Locale (defaultTimeLocale)
134import System.Locale (defaultTimeLocale)
135#endif
135#endif
136import System.Timeout (timeout)
136import System.Timeout (timeout)
137−import Control.Monad (when)
137+import Control.Monad (when, void)
138import Control.Monad.Reader (ask)
138import Control.Monad.Reader (ask)
139import Control.Monad.IO.Class (liftIO)
139import Control.Monad.IO.Class (liftIO)
140import Control.Monad.Catch
140import Control.Monad.Catch
@@ -184,6 +184,7 @@ import Control.Distributed.Process.Internal.Types
184 , SpawnRef(..)
184 , SpawnRef(..)
185 , ProcessSignal(..)
185 , ProcessSignal(..)
186 , NodeMonitorNotification(..)
186 , NodeMonitorNotification(..)
187+ , ProcessMonitorNotification(..)
187 , monitorCounter
188 , monitorCounter
188 , spawnCounter
189 , spawnCounter
189 , SendPort(..)
190 , SendPort(..)
@@ -928,12 +929,21 @@ unlinkPort sport = do
928-- | Remove a monitor
929-- | Remove a monitor
929--
930--
930-- This has the same synchronous/asynchronous nature as 'unlink'.
931-- This has the same synchronous/asynchronous nature as 'unlink'.
932+--
933+-- ProcessMonitorNotification messages for the given MonitorRef are removed from
934+-- the mailbox.
931unmonitor :: MonitorRef -> Process ()
935unmonitor :: MonitorRef -> Process ()
932unmonitor ref = do
936unmonitor ref = do
933 unmonitorAsync ref
937 unmonitorAsync ref
934 receiveWait [ matchIf (\(DidUnmonitor ref') -> ref' == ref)
938 receiveWait [ matchIf (\(DidUnmonitor ref') -> ref' == ref)
935 (\_ -> return ())
939 (\_ -> return ())
936 ]
940 ]
941+ -- Discard the notification if any. With the current NC implementation at most
942+ -- one notification is in the mailbox for any given ref.
943+ void $ receiveTimeout 0
944+ [ matchIf (\(ProcessMonitorNotification ref' _ _) -> ref' == ref)
945+ (const $ return ())
946+ ]
937
947
938--------------------------------------------------------------------------------
948--------------------------------------------------------------------------------
939-- Exception handling --
949-- Exception handling --