resourcet-1.3.0: Deterministic allocation and freeing of scarce resources.

Safe Haskell | None
Language | Haskell2010

Control.Monad.Trans.Resource.Internal

Synopsis

- data InvalidAccess = InvalidAccess {
  - functionName :: String
  }
- class MonadIO m => MonadResource (m :: Type -> Type) where
  - liftResourceT :: ResourceT IO a -> m a
- data ReleaseKey = ReleaseKey !(IORef ReleaseMap) !Int
- data ReleaseMap
  - = ReleaseMap !NextKey !RefCount !(IntMap (ReleaseType -> IO ()))
  - | ReleaseMapClosed
- type ResIO = ResourceT IO
- newtype ResourceT (m :: Type -> Type) a = ResourceT {
  - unResourceT :: IORef ReleaseMap -> m a
  }
- stateAlloc :: IORef ReleaseMap -> IO ()
- stateCleanup :: ReleaseType -> IORef ReleaseMap -> IO ()
- transResourceT :: (m a -> n b) -> ResourceT m a -> ResourceT n b
- register' :: IORef ReleaseMap -> IO () -> IO ReleaseKey
- registerType :: IORef ReleaseMap -> (ReleaseType -> IO ()) -> IO ReleaseKey
- data ResourceCleanupException = ResourceCleanupException {
  - rceOriginalException :: !(Maybe SomeException)
  - rceFirstCleanupException :: !SomeException
  - rceOtherCleanupExceptions :: ![SomeException]
  }
- stateCleanupChecked :: Maybe SomeException -> IORef ReleaseMap -> IO ()

# Documentation

data InvalidAccess Source #

Indicates either an error in the library, or misuse of it (e.g., a `ResourceT`'s state is accessed after being released).

Since 0.3.0

Constructors

InvalidAccess |

Fields

- functionName :: String

#### Instances

Instances details

Exception InvalidAccess Source # |
Instance details Defined in Control.Monad.Trans.Resource.Internal Methods toException :: InvalidAccess -> SomeException Source # fromException :: SomeException -> Maybe InvalidAccess Source # displayException :: InvalidAccess -> String Source # backtraceDesired :: InvalidAccess -> Bool Source #
Show InvalidAccess Source # |
Instance details Defined in Control.Monad.Trans.Resource.Internal Methods showsPrec :: Int -> InvalidAccess -> ShowS Source # show :: InvalidAccess -> String Source # showList :: [InvalidAccess] -> ShowS Source #

class MonadIO m => MonadResource (m :: Type -> Type) where Source #

A `Monad` which allows for safe resource allocation. In theory, any monad transformer stack which includes a `ResourceT` can be an instance of `MonadResource`.

Note: `runResourceT` has a requirement for a `MonadUnliftIO m` monad, which allows control operations to be lifted. A `MonadResource` does not have this requirement. This means that transformers such as `ContT` can be an instance of `MonadResource`. However, the `ContT` wrapper will need to be unwrapped before calling `runResourceT`.

Since 0.3.0

Methods

liftResourceT :: ResourceT IO a -> m a Source #

Lift a `ResourceT IO` action into the current `Monad`.

Since 0.4.0

#### Instances

Instances details

MonadIO m => MonadResource (ResourceT m) Source # |
Instance details Defined in Control.Monad.Trans.Resource.Internal Methods liftResourceT :: ResourceT IO a -> ResourceT m a Source #
MonadResource m => MonadResource (MaybeT m) Source # |
Instance details Defined in Control.Monad.Trans.Resource.Internal Methods liftResourceT :: ResourceT IO a -> MaybeT m a Source #
MonadResource m => MonadResource (ExceptT e m) Source # |
Instance details Defined in Control.Monad.Trans.Resource.Internal Methods liftResourceT :: ResourceT IO a -> ExceptT e m a Source #
MonadResource m => MonadResource (IdentityT m) Source # |
Instance details Defined in Control.Monad.Trans.Resource.Internal Methods liftResourceT :: ResourceT IO a -> IdentityT m a Source #
MonadResource m => MonadResource (ReaderT r m) Source # |
Instance details Defined in Control.Monad.Trans.Resource.Internal Methods liftResourceT :: ResourceT IO a -> ReaderT r m a Source #
MonadResource m => MonadResource (StateT s m) Source # |
Instance details Defined in Control.Monad.Trans.Resource.Internal Methods liftResourceT :: ResourceT IO a -> StateT s m a Source #
MonadResource m => MonadResource (StateT s m) Source # |
Instance details Defined in Control.Monad.Trans.Resource.Internal Methods liftResourceT :: ResourceT IO a -> StateT s m a Source #
(Monoid w, MonadResource m) => MonadResource (WriterT w m) Source # |
Instance details Defined in Control.Monad.Trans.Resource.Internal Methods liftResourceT :: ResourceT IO a -> WriterT w m a Source #
(Monoid w, MonadResource m) => MonadResource (WriterT w m) Source # |
Instance details Defined in Control.Monad.Trans.Resource.Internal Methods liftResourceT :: ResourceT IO a -> WriterT w m a Source #
MonadResource m => MonadResource (ContT r m) Source # |
Instance details Defined in Control.Monad.Trans.Resource.Internal Methods liftResourceT :: ResourceT IO a -> ContT r m a Source #
(Monoid w, MonadResource m) => MonadResource (RWST r w s m) Source # |
Instance details Defined in Control.Monad.Trans.Resource.Internal Methods liftResourceT :: ResourceT IO a -> RWST r w s m a Source #
(Monoid w, MonadResource m) => MonadResource (RWST r w s m) Source # |
Instance details Defined in Control.Monad.Trans.Resource.Internal Methods liftResourceT :: ResourceT IO a -> RWST r w s m a Source #

data ReleaseKey Source #

A lookup key for a specific release action. This value is returned by `register` and `allocate`, and is passed to `release`.

Since 0.3.0

Constructors

ReleaseKey !(IORef ReleaseMap) !Int |

data ReleaseMap Source #

Constructors

ReleaseMap !NextKey !RefCount !(IntMap (ReleaseType -> IO ())) |
ReleaseMapClosed |

type ResIO = ResourceT IO Source #

Convenient alias for `ResourceT IO`.

newtype ResourceT (m :: Type -> Type) a Source #

The Resource transformer. This transformer keeps track of all registered actions, and calls them upon exit (via `runResourceT`). Actions may be registered via `register`, or resources may be allocated atomically via `allocate`. `allocate` corresponds closely to `bracket`.

Releasing may be performed before exit via the `release` function. This is a highly recommended optimization, as it will ensure that scarce resources are freed early. Note that calling `release` will deregister the action, so that a release action will only ever be called once.

Since 0.3.0

Constructors

ResourceT |

Fields

- unResourceT :: IORef ReleaseMap -> m a

#### Instances

Instances details

MonadTrans ResourceT Source # |
Instance details Defined in Control.Monad.Trans.Resource.Internal Methods lift :: Monad m => m a -> ResourceT m a Source #
MonadRWS r w s m => MonadRWS r w s (ResourceT m) Source # |
Instance details Defined in Control.Monad.Trans.Resource.Internal
MonadError e m => MonadError e (ResourceT m) Source # |
Instance details Defined in Control.Monad.Trans.Resource.Internal Methods throwError :: e -> ResourceT m a Source # catchError :: ResourceT m a -> (e -> ResourceT m a) -> ResourceT m a Source #
MonadReader r m => MonadReader r (ResourceT m) Source # |
Instance details Defined in Control.Monad.Trans.Resource.Internal Methods ask :: ResourceT m r Source # local :: (r -> r) -> ResourceT m a -> ResourceT m a Source # reader :: (r -> a) -> ResourceT m a Source #
MonadState s m => MonadState s (ResourceT m) Source # |
Instance details Defined in Control.Monad.Trans.Resource.Internal Methods get :: ResourceT m s Source # put :: s -> ResourceT m () Source # state :: (s -> (a, s)) -> ResourceT m a Source #
MonadWriter w m => MonadWriter w (ResourceT m) Source # |
Instance details Defined in Control.Monad.Trans.Resource.Internal Methods writer :: (a, w) -> ResourceT m a Source # tell :: w -> ResourceT m () Source # listen :: ResourceT m a -> ResourceT m (a, w) Source # pass :: ResourceT m (a, w -> w) -> ResourceT m a Source #
MonadIO m => MonadIO (ResourceT m) Source # |
Instance details Defined in Control.Monad.Trans.Resource.Internal Methods liftIO :: IO a -> ResourceT m a Source #
MonadCatch m => MonadCatch (ResourceT m) Source # |
Instance details Defined in Control.Monad.Trans.Resource.Internal Methods catch :: (HasCallStack, Exception e) => ResourceT m a -> (e -> ResourceT m a) -> ResourceT m a Source #
MonadMask m => MonadMask (ResourceT m) Source # |

Instance details

Defined in Control.Monad.Trans.Resource.Internal

Methods

mask :: HasCallStack => ((forall a. ResourceT m a -> ResourceT m a) -> ResourceT m b) -> ResourceT m b Source #

uninterruptibleMask :: HasCallStack => ((forall a. ResourceT m a -> ResourceT m a) -> ResourceT m b) -> ResourceT m b Source #

generalBracket :: HasCallStack => ResourceT m a -> (a -> ExitCase b -> ResourceT m c) -> (a -> ResourceT m b) -> ResourceT m (b, c) Source #

MonadThrow m => MonadThrow (ResourceT m) Source # |
Instance details Defined in Control.Monad.Trans.Resource.Internal Methods throwM :: (HasCallStack, Exception e) => e -> ResourceT m a Source #
Alternative m => Alternative (ResourceT m) Source # | Since 1.1.5
Instance details Defined in Control.Monad.Trans.Resource.Internal Methods empty :: ResourceT m a Source # (<|>) :: ResourceT m a -> ResourceT m a -> ResourceT m a Source # some :: ResourceT m a -> ResourceT m [a] Source # many :: ResourceT m a -> ResourceT m [a] Source #
Applicative m => Applicative (ResourceT m) Source # |
Instance details Defined in Control.Monad.Trans.Resource.Internal Methods pure :: a -> ResourceT m a Source # (<*>) :: ResourceT m (a -> b) -> ResourceT m a -> ResourceT m b Source # liftA2 :: (a -> b -> c) -> ResourceT m a -> ResourceT m b -> ResourceT m c Source # (*>) :: ResourceT m a -> ResourceT m b -> ResourceT m b Source # (<*) :: ResourceT m a -> ResourceT m b -> ResourceT m a Source #
Functor m => Functor (ResourceT m) Source # |
Instance details Defined in Control.Monad.Trans.Resource.Internal Methods fmap :: (a -> b) -> ResourceT m a -> ResourceT m b Source # (<$) :: a -> ResourceT m b -> ResourceT m a Source #
Monad m => Monad (ResourceT m) Source # |
Instance details Defined in Control.Monad.Trans.Resource.Internal Methods (>>=) :: ResourceT m a -> (a -> ResourceT m b) -> ResourceT m b Source # (>>) :: ResourceT m a -> ResourceT m b -> ResourceT m b Source # return :: a -> ResourceT m a Source #
MonadPlus m => MonadPlus (ResourceT m) Source # | Since 1.1.5
Instance details Defined in Control.Monad.Trans.Resource.Internal Methods mzero :: ResourceT m a Source # mplus :: ResourceT m a -> ResourceT m a -> ResourceT m a Source #
MonadFail m => MonadFail (ResourceT m) Source # | Since: 1.2.2
Instance details Defined in Control.Monad.Trans.Resource.Internal Methods fail :: String -> ResourceT m a Source #
MonadFix m => MonadFix (ResourceT m) Source # | Since: 1.1.8
Instance details Defined in Control.Monad.Trans.Resource.Internal Methods mfix :: (a -> ResourceT m a) -> ResourceT m a Source #
MonadCont m => MonadCont (ResourceT m) Source # |
Instance details Defined in Control.Monad.Trans.Resource.Internal Methods callCC :: ((a -> ResourceT m b) -> ResourceT m a) -> ResourceT m a Source #
PrimMonad m => PrimMonad (ResourceT m) Source # |

Instance details

Defined in Control.Monad.Trans.Resource.Internal

Associated Types

type PrimState (ResourceT m) |
Instance details Defined in Control.Monad.Trans.Resource.Internal type PrimState (ResourceT m) = PrimState m

Methods

primitive :: (State# (PrimState (ResourceT m)) -> (# State# (PrimState (ResourceT m)), a #)) -> ResourceT m a Source #

MonadIO m => MonadResource (ResourceT m) Source # |
Instance details Defined in Control.Monad.Trans.Resource.Internal Methods liftResourceT :: ResourceT IO a -> ResourceT m a Source #
MonadUnliftIO m => MonadUnliftIO (ResourceT m) Source # | Since: 1.1.10
Instance details Defined in Control.Monad.Trans.Resource.Internal Methods withRunInIO :: ((forall a. ResourceT m a -> IO a) -> IO b) -> ResourceT m b Source #
type PrimState (ResourceT m) Source # |
Instance details Defined in Control.Monad.Trans.Resource.Internal type PrimState (ResourceT m) = PrimState m

stateAlloc :: IORef ReleaseMap -> IO () Source #

stateCleanup :: ReleaseType -> IORef ReleaseMap -> IO () Source #

transResourceT :: (m a -> n b) -> ResourceT m a -> ResourceT n b Source #

Transform the monad a `ResourceT` lives in. This is most often used to strip or add new transformers to a stack, e.g. to run a `ReaderT`.

Note that this function is a slight generalization of `hoist`.

Since 0.3.0

register' :: IORef ReleaseMap -> IO () -> IO ReleaseKey Source #

registerType :: IORef ReleaseMap -> (ReleaseType -> IO ()) -> IO ReleaseKey Source #

Since 1.1.2

data ResourceCleanupException Source #

Thrown when one or more cleanup functions themselves throw an exception during cleanup.

Since: 1.1.11

Constructors

ResourceCleanupException |

Fields

- rceOriginalException :: !(Maybe SomeException)

  If the `ResourceT` block exited due to an exception, this is that exception.

  Since: 1.1.11

- rceFirstCleanupException :: !SomeException

  The first cleanup exception. We keep this separate from `rceOtherCleanupExceptions` to prove that there's at least one (i.e., a non-empty list).

  Since: 1.1.11

- rceOtherCleanupExceptions :: ![SomeException]

  All other exceptions in cleanups.

  Since: 1.1.11

#### Instances

Instances details

Exception ResourceCleanupException Source # |
Instance details Defined in Control.Monad.Trans.Resource.Internal Methods toException :: ResourceCleanupException -> SomeException Source # fromException :: SomeException -> Maybe ResourceCleanupException Source # displayException :: ResourceCleanupException -> String Source # backtraceDesired :: ResourceCleanupException -> Bool Source #
Show ResourceCleanupException Source # |
Instance details Defined in Control.Monad.Trans.Resource.Internal Methods showsPrec :: Int -> ResourceCleanupException -> ShowS Source # show :: ResourceCleanupException -> String Source # showList :: [ResourceCleanupException] -> ShowS Source #

stateCleanupChecked Source #

Arguments

:: Maybe SomeException | exception that killed the `ResourceT`, if present
-> IORef ReleaseMap |
-> IO () |

Clean up a release map, but throw a `ResourceCleanupException` if anything goes wrong in the cleanup handlers.

Since: 1.1.11