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

Safe HaskellSafe
LanguageHaskell98

Data.Acquire.Internal

Synopsis

Documentation

newtype Acquire a Source #

A method for acquiring a scarce resource, providing the means of freeing it when no longer needed. This data type provides FunctorApplicativeMonad 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 Source # 

Methods

(>>=) :: Acquire a -> (a -> Acquire b) -> Acquire b #

(>>) :: Acquire a -> Acquire b -> Acquire b #

return :: a -> Acquire a #

fail :: String -> Acquire a #

Functor Acquire Source # 

Methods

fmap :: (a -> b) -> Acquire a -> Acquire b #

(<$) :: a -> Acquire b -> Acquire a #

Applicative Acquire Source # 

Methods

pure :: a -> Acquire a #

(<*>) :: Acquire (a -> b) -> Acquire a -> Acquire b #

liftA2 :: (a -> b -> c) -> Acquire a -> Acquire b -> Acquire c #

(*>) :: Acquire a -> Acquire b -> Acquire b #

(<*) :: Acquire a -> Acquire b -> Acquire a #

MonadIO Acquire Source # 

Methods

liftIO :: IO a -> Acquire a #

data Allocated a Source #

Constructors

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

with :: MonadUnliftIO m => Acquire a -> (a -> m b) -> m b Source #

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

mkAcquire Source #

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

mkAcquireType Source #

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