@@ -137,9 +137,14 @@ import System.Timeout (timeout)
137import Control.Monad (when)
137import Control.Monad (when)
138import Control.Monad.Reader (ask)
138import Control.Monad.Reader (ask)
139import Control.Monad.IO.Class (liftIO)
139import Control.Monad.IO.Class (liftIO)
140−import Control.Applicative ((<$>))
140+import Control.Monad.Catch
141−import Control.Exception (Exception(..), throw, throwIO, SomeException)
141+ ( Exception
142−import qualified Control.Exception as Ex (catch, mask, mask_, try)
146+import qualified Control.Monad.Catch as Catch
147+import Control.Applicative
143import Control.Distributed.Process.Internal.StrictMVar
148import Control.Distributed.Process.Internal.StrictMVar
144 ( StrictMVar
149 ( StrictMVar
145 , modifyMVar
150 , modifyMVar
@@ -203,7 +208,6 @@ import Control.Distributed.Process.Internal.Types
203 , isEncoded
208 , isEncoded
204 , createMessage
209 , createMessage
205 , createUnencodedMessage
210 , createUnencodedMessage
207 , ImplicitReconnect( NoImplicitReconnect)
211 , ImplicitReconnect( NoImplicitReconnect)
208 , LocalProcessState
212 , LocalProcessState
209 , LocalSendPortId
213 , LocalSendPortId
@@ -227,6 +231,7 @@ import Control.Distributed.Process.Internal.WeakTQueue
227 , readTQueue
231 , readTQueue
228 , mkWeakTQueue
232 , mkWeakTQueue
231import Unsafe.Coerce
236import Unsafe.Coerce
@@ -699,7 +704,7 @@ instance Exception ProcessTerminationException
700-- | Terminate immediately (throws a ProcessTerminationException)
705-- | Terminate immediately (throws a ProcessTerminationException)
701terminate :: Process a
706terminate :: Process a
702−terminate = liftIO $ throwIO ProcessTerminationException
707+terminate = throwM ProcessTerminationException
704-- [Issue #110]
709-- [Issue #110]
705-- | Die immediately - throws a 'ProcessExitException' with the given @reason@.
710-- | Die immediately - throws a 'ProcessExitException' with the given @reason@.
@@ -709,7 +714,7 @@ die reason = do
709-- could be decoded by a handler passed to 'catchExit', re-thrown or even
714-- could be decoded by a handler passed to 'catchExit', re-thrown or even
710-- passed to another process via the tracing mechanism.
715-- passed to another process via the tracing mechanism.
711 pid <- getSelfPid
716 pid <- getSelfPid
712− liftIO $ throwIO (ProcessExitException pid (createMessage reason))
717+ throwM (ProcessExitException pid (createMessage reason))
714-- | Forceful request to kill a process. Where 'exit' provides an exception
719-- | Forceful request to kill a process. Where 'exit' provides an exception
715-- that can be caught and handled, 'kill' throws an unexposed exception type
720-- that can be caught and handled, 'kill' throws an unexposed exception type
@@ -742,12 +747,12 @@ catchExit :: forall a b . (Show a, Serializable a)
742 => Process b
747 => Process b
743 -> (ProcessId -> a -> Process b)
748 -> (ProcessId -> a -> Process b)
744 -> Process b
749 -> Process b
745−catchExit act exitHandler = catch act handleExit
750+catchExit act exitHandler = Catch.catch act handleExit
747 handleExit ex@(ProcessExitException from msg) =
752 handleExit ex@(ProcessExitException from msg) =
748 if messageFingerprint msg == fingerprint (undefined :: a)
753 if messageFingerprint msg == fingerprint (undefined :: a)
749 then exitHandler from decoded
754 then exitHandler from decoded
750− else liftIO $ throwIO ex
755+ else throwM ex
752 decoded :: a
757 decoded :: a
753 -- Make sure the value is fully decoded so that we don't hang to
758 -- Make sure the value is fully decoded so that we don't hang to
@@ -766,12 +771,12 @@ catchExit act exitHandler = catch act handleExit
766catchesExit :: Process b
771catchesExit :: Process b
767 -> [(ProcessId -> Message -> (Process (Maybe b)))]
772 -> [(ProcessId -> Message -> (Process (Maybe b)))]
768 -> Process b
773 -> Process b
769−catchesExit act handlers = catch act ((flip handleExit) handlers)
774+catchesExit act handlers = Catch.catch act ((flip handleExit) handlers)
771 handleExit :: ProcessExitException
776 handleExit :: ProcessExitException
772 -> [(ProcessId -> Message -> Process (Maybe b))]
777 -> [(ProcessId -> Message -> Process (Maybe b))]
773 -> Process b
778 -> Process b
774− handleExit ex [] = liftIO $ throwIO ex
779+ handleExit ex [] = throwM ex
775 handleExit ex@(ProcessExitException from msg) (h:hs) = do
780 handleExit ex@(ProcessExitException from msg) (h:hs) = do
776 r <- h from msg
781 r <- h from msg
777 case r of
782 case r of
@@ -936,56 +941,43 @@ unmonitor ref = do
937-- | Lift 'Control.Exception.catch'
942-- | Lift 'Control.Exception.catch'
938catch :: Exception e => Process a -> (e -> Process a) -> Process a
943catch :: Exception e => Process a -> (e -> Process a) -> Process a
939−catch p h = do
944+catch = Catch.catch
940− lproc <- ask
945+{-# DEPRECATED catch "Use Control.Monad.Catch.catch instead" #-}
941− liftIO $ Ex.catch (runLocalProcess lproc p) (runLocalProcess lproc . h)
943-- | Lift 'Control.Exception.try'
947-- | Lift 'Control.Exception.try'
944try :: Exception e => Process a -> Process (Either e a)
948try :: Exception e => Process a -> Process (Either e a)
945−try p = do
949+try = Catch.try
946− lproc <- ask
950+{-# DEPRECATED try "Use Control.Monad.Catch.mask_ instead" #-}
947− liftIO $ Ex.try (runLocalProcess lproc p)
949-- | Lift 'Control.Exception.mask'
952-- | Lift 'Control.Exception.mask'
950mask :: ((forall a. Process a -> Process a) -> Process b) -> Process b
953mask :: ((forall a. Process a -> Process a) -> Process b) -> Process b
951−mask p = do
954+mask = Catch.mask
952− lproc <- ask
955+{-# DEPRECATED mask "Use Control.Monad.Catch.mask_ instead" #-}
953− liftIO $ Ex.mask $ \restore ->
954− runLocalProcess lproc (p (liftRestore restore))
956− liftRestore :: (forall a. IO a -> IO a)
957− -> (forall a. Process a -> Process a)
958− liftRestore restoreIO = \p2 -> do
960− liftIO $ restoreIO $ runLocalProcess ourLocalProc p2
962-- | Lift 'Control.Exception.mask_'
957-- | Lift 'Control.Exception.mask_'
963mask_ :: Process a -> Process a
958mask_ :: Process a -> Process a
964−mask_ p = do
959+mask_ = Catch.mask_
965− lproc <- ask
960+{-# DEPRECATED mask_ "Use Control.Monad.Catch.mask_ instead" #-}
966− liftIO $ Ex.mask_ $ runLocalProcess lproc p
968-- | Lift 'Control.Exception.onException'
962-- | Lift 'Control.Exception.onException'
969onException :: Process a -> Process b -> Process a
963onException :: Process a -> Process b -> Process a
970−onException p what = p `catch` \e -> do _ <- what
964+onException = Catch.onException
971− liftIO $ throwIO (e :: SomeException)
965+{-# DEPRECATED onException "Use Control.Monad.Catch.onException instead" #-}
973-- | Lift 'Control.Exception.bracket'
967-- | Lift 'Control.Exception.bracket'
974bracket :: Process a -> (a -> Process b) -> (a -> Process c) -> Process c
968bracket :: Process a -> (a -> Process b) -> (a -> Process c) -> Process c
975−bracket before after thing =
969+bracket = Catch.bracket
976− mask $ \restore -> do
970+{-# DEPRECATED bracket "Use Control.Monad.Catch.bracket instead" #-}
978− r <- restore (thing a) `onException` after a
982-- | Lift 'Control.Exception.bracket_'
972-- | Lift 'Control.Exception.bracket_'
983bracket_ :: Process a -> Process b -> Process c -> Process c
973bracket_ :: Process a -> Process b -> Process c -> Process c
984−bracket_ before after thing = bracket before (const after) (const thing)
974+bracket_ = Catch.bracket_
975+{-# DEPRECATED bracket_ "Use Control.Monad.Catch.bracket_ instead" #-}
986-- | Lift 'Control.Exception.finally'
977-- | Lift 'Control.Exception.finally'
987finally :: Process a -> Process b -> Process a
978finally :: Process a -> Process b -> Process a
988−finally a sequel = bracket_ (return ()) sequel a
979+finally = Catch.finally
980+{-# DEPRECATED finally "Use Control.Monad.Catch.finally instead" #-}
990-- | You need this when using 'catches'
982-- | You need this when using 'catches'
991data Handler a = forall e . Exception e => Handler (e -> Process a)
983data Handler a = forall e . Exception e => Handler (e -> Process a)
@@ -995,10 +987,10 @@ instance Functor Handler where
996-- | Lift 'Control.Exception.catches'
988-- | Lift 'Control.Exception.catches'
997catches :: Process a -> [Handler a] -> Process a
989catches :: Process a -> [Handler a] -> Process a
998−catches proc handlers = proc `catch` catchesHandler handlers
990+catches proc handlers = proc `Catch.catch` catchesHandler handlers
1000catchesHandler :: [Handler a] -> SomeException -> Process a
992catchesHandler :: [Handler a] -> SomeException -> Process a
1001−catchesHandler handlers e = foldr tryHandler (throw e) handlers
993+catchesHandler handlers e = foldr tryHandler (throwM e) handlers
1002 where tryHandler (Handler handler) res
994 where tryHandler (Handler handler) res
1003 = case fromException e of
995 = case fromException e of
1004 Just e' -> handler e'
996 Just e' -> handler e'
@@ -1138,7 +1130,7 @@ unregister label = do
1138handleRegistrationReply :: String -> Bool -> Maybe ProcessId -> Process ()
1130handleRegistrationReply :: String -> Bool -> Maybe ProcessId -> Process ()
1139handleRegistrationReply label ok owner =
1131handleRegistrationReply label ok owner =
1140 when (not ok) $
1132 when (not ok) $
1141− liftIO $ throwIO $ ProcessRegistrationException label owner
1133+ throwM $ ProcessRegistrationException label owner
1143-- | Remove a process from a remote registry (asynchronous).
1135-- | Remove a process from a remote registry (asynchronous).