module Control.Distributed.Session.Exception where
import qualified Control.SessionTypes.Indexed as I
import Control.Monad.Catch as C
import Control.SessionTypes.Indexed
import Control.SessionTypes.Codensity (rep)
import Control.Distributed.Session.Session
import Control.Distributed.Session.Eval (evalSessionEq)
import Control.Distributed.Process
instance IxMonadThrow Session s where
throwM e = Session $ \_ -> rep $ lift $ C.throwM e
instance IxMonadCatch Session s where
catch sess h = Session $ \si ->
let p = evalSessionEq sess
in rep $ lift $ C.catch p (\e -> evalSessionEq (h e))
instance IxMonadMask Session s where
mask s = Session $ \si ->
rep $ lift $ C.mask $ \restore -> evalSessionEq (s $ liftRestore restore)
where liftRestore :: (Process a -> Process a) -> Session s s a -> Session s s a
liftRestore restore = \s -> Session $ \si -> rep $ lift $ restore $ evalSessionEq s
uninterruptibleMask s = Session $ \si ->
rep $ lift $ C.uninterruptibleMask $ \restore -> evalSessionEq (s $ liftRestore restore)
where liftRestore :: (Process a -> Process a) -> Session s s a -> Session s s a
liftRestore restore = \s -> Session $ \si -> rep $ lift $ restore $ evalSessionEq s