packages feed

resourcet 1.1.2.3 → 1.1.3

raw patch · 6 files changed

+50/−6 lines, 6 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

- Control.Monad.Trans.Resource.Internal: instance Typeable1 m => Typeable1 (ResourceT m)
- Data.Acquire.Internal: instance Typeable1 Acquire
+ Control.Monad.Trans.Resource.Internal: instance Typeable ResourceT
+ Data.Acquire: withEx :: (MonadMask m, MonadIO m) => Acquire a -> (a -> m b) -> m b
+ Data.Acquire.Internal: instance Typeable Acquire
+ Data.Acquire.Internal: withEx :: (MonadMask m, MonadIO m) => Acquire a -> (a -> m b) -> m b

Files

+ ChangeLog.md view
@@ -0,0 +1,3 @@+## 1.1.3++Provide the `withEx` function to interact nicely with the exceptions package.
Data/Acquire.hs view
@@ -3,6 +3,7 @@ module Data.Acquire     ( Acquire     , with+    , withEx     , mkAcquire     , mkAcquireType     , allocateAcquire
Data/Acquire/Internal.hs view
@@ -7,6 +7,7 @@     ( Acquire (..)     , Allocated (..)     , with+    , withEx     , mkAcquire     , ReleaseType (..)     , mkAcquireType@@ -19,6 +20,8 @@ import qualified Control.Exception.Lifted as E import Data.Typeable (Typeable) import Control.Monad (liftM, ap)+import qualified Control.Monad.Catch as C+import GHC.IO (unsafeUnmask)  -- | The way in which a release is called. --@@ -102,6 +105,29 @@      -> m b with (Acquire f) g = control $ \run -> E.mask $ \restore -> do     Allocated x free <- f restore-    res <- run (g x) `E.onException` free ReleaseException+    res <- restore (run (g x)) `E.onException` free ReleaseException     free ReleaseNormal     return res++-- | Same as @with@, but uses the @MonadMask@ typeclass from exceptions instead+-- of @MonadBaseControl@ from exceptions.+--+-- Since 1.1.3+withEx :: (C.MonadMask m, MonadIO m)+       => Acquire a+       -> (a -> m b)+       -> m b+withEx (Acquire f) g = do+    -- We need to do some funny business, since the restore we get below is+    -- specialized to the m from the result, whereas we need a restore function+    -- in IO. Checking the current masking state is exactly how mask is+    -- implemented in base.+    origMS <- liftIO E.getMaskingState++    C.mask $ \restore -> do+        Allocated x free <- liftIO $ f $ case origMS of+            E.Unmasked -> unsafeUnmask+            _ -> id+        res <- restore (g x) `C.onException` liftIO (free ReleaseException)+        liftIO $ free ReleaseNormal+        return res
+ README.md view
@@ -0,0 +1,5 @@+## resourcet++Please see [the full tutorial on School of Haskell](https://www.fpcomplete.com/user/snoyberg/library-documentation/resourcet).++This package was originally included with the conduit package, but has existed as a separate package for quite a while. It is fully usable outside of conduit.
resourcet.cabal view
@@ -1,10 +1,7 @@ Name:                resourcet-Version:             1.1.2.3+Version:             1.1.3 Synopsis:            Deterministic allocation and freeing of scarce resources.-Description:-    A full tutorial is available at <https://www.fpcomplete.com/user/snoyberg/library-documentation/resourcet>.-    .-	This package was originally included with the conduit package, but has existed as a separate package for quite a while. It is fully usable outside of conduit.+Description:         See README.md License:             BSD3 License-file:        LICENSE Author:              Michael Snoyman@@ -13,6 +10,7 @@ Build-type:          Simple Cabal-version:       >=1.8 Homepage:            http://github.com/snoyberg/conduit+extra-source-files:  ChangeLog.md, README.md  Library   Exposed-modules:     Control.Monad.Trans.Resource
test/main.hs view
@@ -89,6 +89,17 @@                 let acq = mkAcquireType (return ()) $ \() -> writeIORef ref . Just                 Left Dummy <- try $ with acq $ const $ throwIO Dummy                 readIORef ref >>= (`shouldBe` Just ReleaseException)+        describe "withEx" $ do+            it "normal" $ do+                ref <- newIORef Nothing+                let acq = mkAcquireType (return ()) $ \() -> writeIORef ref . Just+                withEx acq $ const $ return ()+                readIORef ref >>= (`shouldBe` Just ReleaseNormal)+            it "exception" $ do+                ref <- newIORef Nothing+                let acq = mkAcquireType (return ()) $ \() -> writeIORef ref . Just+                Left Dummy <- try $ withEx acq $ const $ throwIO Dummy+                readIORef ref >>= (`shouldBe` Just ReleaseException)  data Dummy = Dummy     deriving (Show, Typeable)