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

Safe Haskell | Trustworthy
Language | Haskell98

Data.Acquire.Internal

Synopsis

- newtype Acquire a = Acquire ((forall b. IO b -> IO b) -> IO (Allocated a))
- data Allocated a = Allocated !a !(ReleaseType -> IO ())
- with :: MonadBaseControl IO m => Acquire a -> (a -> m b) -> m b
- withEx :: (MonadMask m, MonadIO m) => Acquire a -> (a -> m b) -> m b
- mkAcquire :: IO a -> (a -> IO ()) -> Acquire a
- data ReleaseType
  - = ReleaseEarly
  - | ReleaseNormal
  - | ReleaseException
- mkAcquireType :: IO a -> (a -> ReleaseType -> IO ()) -> Acquire a

# Documentation

newtype Acquire a #

A method for acquiring a scarce resource, providing the means of freeing it when no longer needed. This data type provides `Functor` `Applicative` `Monad` instances for composing different resources together. You can allocate these resources using either the `bracket` pattern (via `with`) or using `ResourceT` (via `allocateAcquire`).

This concept was originally introduced by Gabriel Gonzalez and described at: http://www.haskellforall.com/2013/06/the-resource-applicative.html. The implementation in this package is slightly different, due to taking a different approach to async exception safety.

Since 1.1.0

Constructors

Acquire ((forall b. IO b -> IO b) -> IO (Allocated a)) |

Instances

Monad Acquire # |
Methods (>>=) :: Acquire a -> (a -> Acquire b) -> Acquire b # (>>) :: Acquire a -> Acquire b -> Acquire b # return :: a -> Acquire a # fail :: String -> Acquire a #
Functor Acquire # |
Methods fmap :: (a -> b) -> Acquire a -> Acquire b # (<$) :: a -> Acquire b -> Acquire a #
Applicative Acquire # |
Methods pure :: a -> Acquire a # (<*>) :: Acquire (a -> b) -> Acquire a -> Acquire b # (*>) :: Acquire a -> Acquire b -> Acquire b # (<*) :: Acquire a -> Acquire b -> Acquire a #
MonadIO Acquire # |
Methods liftIO :: IO a -> Acquire a #
MonadBase IO Acquire # |
Methods liftBase :: IO α -> Acquire α #

data Allocated a #

Constructors

Allocated !a !(ReleaseType -> IO ()) |

with :: MonadBaseControl IO m => Acquire a -> (a -> m b) -> m b #

Allocate the given resource and provide it to the provided function. The resource will be freed as soon as the inner block is exited, whether normally or via an exception. This function is similar in function to `bracket`.

Since 1.1.0

withEx :: (MonadMask m, MonadIO m) => Acquire a -> (a -> m b) -> m b #

Same as `with`, but uses the `MonadMask` typeclass from exceptions instead of `MonadBaseControl` from exceptions.

Since 1.1.3

mkAcquire #

Arguments

:: IO a | acquire the resource
-> (a -> IO ()) | free the resource
-> Acquire a |

Create an `Acquire` value using the given allocate and free functions.

Since 1.1.0

data ReleaseType #

The way in which a release is called.

Since 1.1.2

Constructors

ReleaseEarly |
ReleaseNormal |
ReleaseException |

Instances

Bounded ReleaseType # |
Methods minBound :: ReleaseType # maxBound :: ReleaseType #
Enum ReleaseType # |
Methods succ :: ReleaseType -> ReleaseType # pred :: ReleaseType -> ReleaseType # toEnum :: Int -> ReleaseType # fromEnum :: ReleaseType -> Int # enumFrom :: ReleaseType -> [ReleaseType] # enumFromThen :: ReleaseType -> ReleaseType -> [ReleaseType] # enumFromTo :: ReleaseType -> ReleaseType -> [ReleaseType] # enumFromThenTo :: ReleaseType -> ReleaseType -> ReleaseType -> [ReleaseType] #
Eq ReleaseType # |
Methods (==) :: ReleaseType -> ReleaseType -> Bool # (/=) :: ReleaseType -> ReleaseType -> Bool #
Ord ReleaseType # |
Methods compare :: ReleaseType -> ReleaseType -> Ordering # (<) :: ReleaseType -> ReleaseType -> Bool # (<=) :: ReleaseType -> ReleaseType -> Bool # (>) :: ReleaseType -> ReleaseType -> Bool # (>=) :: ReleaseType -> ReleaseType -> Bool # max :: ReleaseType -> ReleaseType -> ReleaseType # min :: ReleaseType -> ReleaseType -> ReleaseType #
Read ReleaseType # |
Methods readsPrec :: Int -> ReadS ReleaseType # readList :: ReadS [ReleaseType] # readPrec :: ReadPrec ReleaseType # readListPrec :: ReadPrec [ReleaseType] #
Show ReleaseType # |
Methods showsPrec :: Int -> ReleaseType -> ShowS # show :: ReleaseType -> String # showList :: [ReleaseType] -> ShowS #

mkAcquireType #

Arguments

:: IO a | acquire the resource
-> (a -> ReleaseType -> IO ()) | free the resource
-> Acquire a |

Same as `mkAcquire`, but the cleanup function will be informed of how cleanup was initiated. This allows you to distinguish, for example, between normal and exceptional exits.

Since 1.1.2