module Data.Acquire
( Acquire
, with
, mkAcquire
, mkAcquireType
, allocateAcquire
, ReleaseType (..)
) where
import Control.Monad.Trans.Resource.Internal
import Control.Monad.Trans.Resource
import Data.Acquire.Internal
import Control.Applicative (Applicative (..))
import Control.Monad.Base (MonadBase (..))
import Control.Monad.IO.Class (MonadIO (..))
import Control.Monad.Trans.Control (MonadBaseControl, control)
import qualified Control.Exception.Lifted as E
import Data.Typeable (Typeable)
import Control.Monad (liftM, ap)
allocateAcquire :: MonadResource m => Acquire a -> m (ReleaseKey, a)
allocateAcquire = liftResourceT . allocateAcquireRIO
allocateAcquireRIO :: Acquire a -> ResourceT IO (ReleaseKey, a)
allocateAcquireRIO (Acquire f) = ResourceT $ \istate -> liftIO $ E.mask $ \restore -> do
Allocated a free <- f restore
key <- registerType istate free
return (key, a)