eventuo11y-0.5.0.0: An event-oriented observability library
CopyrightCopyright 2022 Shea Levy.
LicenseApache-2.0
Maintainershea@shealevy.com
Safe HaskellSafe-Inferred
LanguageHaskell2010

Control.Monad.Cleanup

Description

 
Synopsis

Documentation

class Monad m => MonadCleanup m where Source #

Monads that can cleanup within a single monadic scope.

MonadCleanups allow for acquiring some resource and guaranteeing that it will be released, if computation might continue within that monad.

This is very similar to MonadMask, with the following differences:

  1. MonadCleanups may not be able to throw or catch exceptions (no MonadCatch superclass) or mask exceptions.
  2. The guarantee of generalCleanup is not as absolute as generalBracket (though the latter always has the SIGKILL/power goes out exception). If we can't handle exceptions at all in the monad (at least not without unsafePerformIO), then sometimes the cleanup function won't be called, but only in cases where the entire computation the monad is running is going to be aborted.

This allows MonadCleanup to be used in pure contexts (see CleanupNoException) and still provide meaningful semantics.

Methods

generalCleanup Source #

Arguments

:: m a

Acquire some resource

-> (a -> ExitCase b -> m c)

Release the resource, observing the outcome of the inner action

-> (a -> m b)

Inner action to perform with the resource

-> m (b, c) 

Acquire some resource, use it, and clean it up.

cleanup is guaranteed to run if computation in the surrounding monadic scope might continue.

Similar to generalBracket, see documentation of MonadCleanup for the differences.

Instances

Instances details
MonadCleanup Identity Source # 
Instance details

Defined in Control.Monad.Cleanup

Methods

generalCleanup :: Identity a -> (a -> ExitCase b -> Identity c) -> (a -> Identity b) -> Identity (b, c) Source #

MonadCleanup IO Source # 
Instance details

Defined in Control.Monad.Cleanup

Methods

generalCleanup :: IO a -> (a -> ExitCase b -> IO c) -> (a -> IO b) -> IO (b, c) Source #

MonadCleanup (ST s) Source # 
Instance details

Defined in Control.Monad.Cleanup

Methods

generalCleanup :: ST s a -> (a -> ExitCase b -> ST s c) -> (a -> ST s b) -> ST s (b, c) Source #

MonadMask m => MonadCleanup (CleanupFromMask m) Source # 
Instance details

Defined in Control.Monad.Cleanup

Methods

generalCleanup :: CleanupFromMask m a -> (a -> ExitCase b -> CleanupFromMask m c) -> (a -> CleanupFromMask m b) -> CleanupFromMask m (b, c) Source #

Monad m => MonadCleanup (CleanupNoException m) Source # 
Instance details

Defined in Control.Monad.Cleanup

MonadCleanup m => MonadCleanup (MaybeT m) Source # 
Instance details

Defined in Control.Monad.Cleanup

Methods

generalCleanup :: MaybeT m a -> (a -> ExitCase b -> MaybeT m c) -> (a -> MaybeT m b) -> MaybeT m (b, c) Source #

MonadCleanup m => MonadCleanup (ExceptT e m) Source # 
Instance details

Defined in Control.Monad.Cleanup

Methods

generalCleanup :: ExceptT e m a -> (a -> ExitCase b -> ExceptT e m c) -> (a -> ExceptT e m b) -> ExceptT e m (b, c) Source #

MonadCleanup m => MonadCleanup (IdentityT m) Source # 
Instance details

Defined in Control.Monad.Cleanup

Methods

generalCleanup :: IdentityT m a -> (a -> ExitCase b -> IdentityT m c) -> (a -> IdentityT m b) -> IdentityT m (b, c) Source #

MonadCleanup m => MonadCleanup (ReaderT r m) Source # 
Instance details

Defined in Control.Monad.Cleanup

Methods

generalCleanup :: ReaderT r m a -> (a -> ExitCase b -> ReaderT r m c) -> (a -> ReaderT r m b) -> ReaderT r m (b, c) Source #

MonadCleanup m => MonadCleanup (StateT s m) Source # 
Instance details

Defined in Control.Monad.Cleanup

Methods

generalCleanup :: StateT s m a -> (a -> ExitCase b -> StateT s m c) -> (a -> StateT s m b) -> StateT s m (b, c) Source #

MonadCleanup m => MonadCleanup (StateT s m) Source # 
Instance details

Defined in Control.Monad.Cleanup

Methods

generalCleanup :: StateT s m a -> (a -> ExitCase b -> StateT s m c) -> (a -> StateT s m b) -> StateT s m (b, c) Source #

(MonadCleanup m, Monoid w) => MonadCleanup (WriterT w m) Source # 
Instance details

Defined in Control.Monad.Cleanup

Methods

generalCleanup :: WriterT w m a -> (a -> ExitCase b -> WriterT w m c) -> (a -> WriterT w m b) -> WriterT w m (b, c) Source #

(MonadCleanup m, Monoid w) => MonadCleanup (WriterT w m) Source # 
Instance details

Defined in Control.Monad.Cleanup

Methods

generalCleanup :: WriterT w m a -> (a -> ExitCase b -> WriterT w m c) -> (a -> WriterT w m b) -> WriterT w m (b, c) Source #

(MonadCleanup m, Monoid w) => MonadCleanup (RWST r w s m) Source # 
Instance details

Defined in Control.Monad.Cleanup

Methods

generalCleanup :: RWST r w s m a -> (a -> ExitCase b -> RWST r w s m c) -> (a -> RWST r w s m b) -> RWST r w s m (b, c) Source #

(MonadCleanup m, Monoid w) => MonadCleanup (RWST r w s m) Source # 
Instance details

Defined in Control.Monad.Cleanup

Methods

generalCleanup :: RWST r w s m a -> (a -> ExitCase b -> RWST r w s m c) -> (a -> RWST r w s m b) -> RWST r w s m (b, c) Source #

withCleanup :: MonadCleanup m => m a -> (Maybe SomeException -> a -> m b) -> (a -> m c) -> m c Source #

Acquire some resource, use it, and clean it up.

This is to bracketWithError as generalCleanup is to generalBracket, see documentation of generalCleanup for more details.

newtype CleanupFromMask m a Source #

A DerivingVia helper for deriving MonadCleanup from MonadMask.

Constructors

CleanupFromMask (m a) 

Instances

Instances details
Applicative m => Applicative (CleanupFromMask m) Source # 
Instance details

Defined in Control.Monad.Cleanup

Functor m => Functor (CleanupFromMask m) Source # 
Instance details

Defined in Control.Monad.Cleanup

Methods

fmap :: (a -> b) -> CleanupFromMask m a -> CleanupFromMask m b #

(<$) :: a -> CleanupFromMask m b -> CleanupFromMask m a #

Monad m => Monad (CleanupFromMask m) Source # 
Instance details

Defined in Control.Monad.Cleanup

MonadMask m => MonadCleanup (CleanupFromMask m) Source # 
Instance details

Defined in Control.Monad.Cleanup

Methods

generalCleanup :: CleanupFromMask m a -> (a -> ExitCase b -> CleanupFromMask m c) -> (a -> CleanupFromMask m b) -> CleanupFromMask m (b, c) Source #

newtype CleanupNoException m a Source #

A DerivingVia for deriving MonadCleanup in a Monad which can't handle exceptions.

If cleanup runs at all, it will run in ExitCaseSuccess

Note that the associated MonadCleanup instance is invalid if it is possible to catch exceptions in the monad!

Constructors

CleanupNoException (m a)