git.iko.soy/distributed-process
on master help sign in
Remove monitor message in unmonitor.

Thanks to Victor Portnov. Addresses #55.

commit1e0284f172c1f4d24b6575568398a34e36b5d261 authorFacundo Domínguez <facundo.dominguez@tweag.io> dateFri 29 Jan 2016, 15:42 (11 years ago) parent286c54c
1 file changed+11−1
src/Control/Distributed/Process/Internal/Primitives.hs+11−1
src/Control/Distributed/Process/Internal/Primitives.hs+11−1
@@ -134,7 +134,7 @@ import Data.Time.Format (defaultTimeLocale)
134134import System.Locale (defaultTimeLocale)
135135#endif
136136import System.Timeout (timeout)
137−import Control.Monad (when)
137+import Control.Monad (when, void)
138138import Control.Monad.Reader (ask)
139139import Control.Monad.IO.Class (liftIO)
140140import Control.Monad.Catch
@@ -184,6 +184,7 @@ import Control.Distributed.Process.Internal.Types
184184 , SpawnRef(..)
185185 , ProcessSignal(..)
186186 , NodeMonitorNotification(..)
187+ , ProcessMonitorNotification(..)
187188 , monitorCounter
188189 , spawnCounter
189190 , SendPort(..)
@@ -928,12 +929,21 @@ unlinkPort sport = do
928929-- | Remove a monitor
929930--
930931-- This has the same synchronous/asynchronous nature as 'unlink'.
932+--
933+-- ProcessMonitorNotification messages for the given MonitorRef are removed from
934+-- the mailbox.
931935unmonitor :: MonitorRef -> Process ()
932936unmonitor ref = do
933937 unmonitorAsync ref
934938 receiveWait [ matchIf (\(DidUnmonitor ref') -> ref' == ref)
935939 (\_ -> return ())
936940 ]
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+ ]
937947
938948--------------------------------------------------------------------------------
939949-- Exception handling --