resourcet 1.2.6 → 1.3.0
raw patch · 6 files changed
+52/−16 lines, 6 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
- Data.Acquire: ReleaseException :: ReleaseType
- Data.Acquire.Internal: ReleaseException :: ReleaseType
- Data.Acquire.Internal: instance GHC.Classes.Eq Data.Acquire.Internal.ReleaseType
- Data.Acquire.Internal: instance GHC.Classes.Ord Data.Acquire.Internal.ReleaseType
- Data.Acquire.Internal: instance GHC.Enum.Bounded Data.Acquire.Internal.ReleaseType
- Data.Acquire.Internal: instance GHC.Enum.Enum Data.Acquire.Internal.ReleaseType
- Data.Acquire.Internal: instance GHC.Read.Read Data.Acquire.Internal.ReleaseType
+ Data.Acquire: ReleaseExceptionWith :: SomeException -> ReleaseType
+ Data.Acquire: pattern ReleaseException :: ReleaseType
+ Data.Acquire.Internal: ReleaseExceptionWith :: SomeException -> ReleaseType
+ Data.Acquire.Internal: pattern ReleaseException :: ReleaseType
Files
- ChangeLog.md +7/−0
- Control/Monad/Trans/Resource.hs +4/−4
- Control/Monad/Trans/Resource/Internal.hs +1/−1
- Data/Acquire/Internal.hs +11/−5
- resourcet.cabal +1/−1
- test/main.hs +28/−5
ChangeLog.md view
@@ -1,5 +1,12 @@ # ChangeLog for resourcet +## 1.3.0++* Include the exception in ReleaseTypes indicating exceptional exit.++ Only backwards-incompatible in code relying on instances of ReleaseType+ other than Show, or constructing ReleaseException directly.+ ## 1.2.6 * Add `allocateU` [#490](https://github.com/snoyberg/conduit/pull/490)
Control/Monad/Trans/Resource.hs view
@@ -206,13 +206,13 @@ bracket_ :: MonadUnliftIO m => IO () -- ^ allocate -> IO () -- ^ normal cleanup- -> IO () -- ^ exceptional cleanup+ -> (E.SomeException -> IO ()) -- ^ exceptional cleanup -> m a -> m a bracket_ alloc cleanupNormal cleanupExc inside = withRunInIO $ \run -> E.mask $ \restore -> do alloc- res <- restore (run inside) `E.onException` cleanupExc+ res <- restore (run inside) `E.catch` (\e -> cleanupExc e >> E.throwIO e) cleanupNormal return res @@ -254,11 +254,11 @@ bracket_ (stateAlloc r) (return ())- (return ())+ (const $ return ()) (g $ bracket_ (return ()) (stateCleanup ReleaseNormal r)- (stateCleanup ReleaseException r)+ (\e -> stateCleanup (ReleaseExceptionWith e) r) (restore $ run $ f r)) -- | Launch a new reference counted resource context using @forkIO@.
Control/Monad/Trans/Resource/Internal.hs view
@@ -387,7 +387,7 @@ try :: IO () -> IO (Maybe SomeException) try io = fmap (either Just (\() -> Nothing)) (E.try io) - rtype = maybe ReleaseNormal (const ReleaseException) morig+ rtype = maybe ReleaseNormal ReleaseExceptionWith morig -- Note that this returns values in reverse order, which is what we -- want in the specific case of this function.
Data/Acquire/Internal.hs view
@@ -4,12 +4,13 @@ {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE PatternSynonyms #-} module Data.Acquire.Internal ( Acquire (..) , Allocated (..) , with , mkAcquire- , ReleaseType (..)+ , ReleaseType (.., ReleaseException) , mkAcquireType ) where @@ -25,9 +26,14 @@ -- @since 1.1.2 data ReleaseType = ReleaseEarly | ReleaseNormal- | ReleaseException- deriving (Show, Read, Eq, Ord, Enum, Bounded, Typeable)+ | ReleaseExceptionWith E.SomeException+ deriving (Show, Typeable) +{-# COMPLETE ReleaseEarly, ReleaseNormal, ReleaseException #-}+{-# DEPRECATED ReleaseException "Use `ReleaseExceptionWith`, which has the exception in the constructor. This pattern synonym hides the exception and can obscure problems." #-}+pattern ReleaseException :: ReleaseType+pattern ReleaseException <- ReleaseExceptionWith _+ data Allocated a = Allocated !a !(ReleaseType -> IO ()) -- | A method for acquiring a scarce resource, providing the means of freeing@@ -56,7 +62,7 @@ Acquire f >>= g' = Acquire $ \restore -> do Allocated x free1 <- f restore let Acquire g = g' x- Allocated y free2 <- g restore `E.onException` free1 ReleaseException+ Allocated y free2 <- g restore `E.catch` (\e -> free1 (ReleaseExceptionWith e) >> E.throwIO e) return $! Allocated y (\rt -> free2 rt `E.finally` free1 rt) instance MonadIO Acquire where@@ -115,6 +121,6 @@ -> m b with (Acquire f) g = withRunInIO $ \run -> E.mask $ \restore -> do Allocated x free <- f restore- res <- restore (run (g x)) `E.onException` free ReleaseException+ res <- restore (run (g x)) `E.catch` (\e -> free (ReleaseExceptionWith e) >> E.throwIO e) free ReleaseNormal return res
resourcet.cabal view
@@ -1,5 +1,5 @@ Name: resourcet-Version: 1.2.6+Version: 1.3.0 Synopsis: Deterministic allocation and freeing of scarce resources. description: Hackage documentation generation is not reliable. For up to date documentation, please see: <http://www.stackage.org/package/resourcet>. License: BSD3
test/main.hs view
@@ -88,32 +88,32 @@ runResourceT $ do (releaseKey, ()) <- allocateAcquire acq release releaseKey- readIORef ref >>= (`shouldBe` Just ReleaseEarly)+ readIORef ref >>= (`shouldSatisfy` just releaseEarly) it "normal" $ do ref <- newIORef Nothing let acq = mkAcquireType (return ()) $ \() -> writeIORef ref . Just runResourceT $ do (_releaseKey, ()) <- allocateAcquire acq return ()- readIORef ref >>= (`shouldBe` Just ReleaseNormal)+ readIORef ref >>= (`shouldSatisfy` just releaseNormal) it "exception" $ do ref <- newIORef Nothing let acq = mkAcquireType (return ()) $ \() -> writeIORef ref . Just Left Dummy <- try $ runResourceT $ do (_releaseKey, ()) <- allocateAcquire acq liftIO $ throwIO Dummy- readIORef ref >>= (`shouldBe` Just ReleaseException)+ readIORef ref >>= (`shouldSatisfy` just (releaseException dummy)) describe "with" $ do it "normal" $ do ref <- newIORef Nothing let acq = mkAcquireType (return ()) $ \() -> writeIORef ref . Just with acq $ const $ return ()- readIORef ref >>= (`shouldBe` Just ReleaseNormal)+ readIORef ref >>= (`shouldSatisfy` just releaseNormal) it "exception" $ do ref <- newIORef Nothing let acq = mkAcquireType (return ()) $ \() -> writeIORef ref . Just Left Dummy <- try $ with acq $ const $ throwIO Dummy- readIORef ref >>= (`shouldBe` Just ReleaseException)+ readIORef ref >>= (`shouldSatisfy` just (releaseException dummy)) describe "runResourceTChecked" $ do it "catches exceptions" $ do eres <- try $ runResourceTChecked $ void $ register $ throwIO Dummy@@ -149,3 +149,26 @@ data Dummy2 = Dummy2 deriving (Show, Typeable) instance Exception Dummy2++-- Helpers needed due to lack of 'Eq' on 'ReleaseType'++releaseEarly :: ReleaseType -> Bool+releaseEarly ReleaseEarly = True+releaseEarly _ = False++releaseNormal :: ReleaseType -> Bool+releaseNormal ReleaseNormal = True+releaseNormal _ = False++releaseException :: (Exception e) => Selector e -> ReleaseType -> Bool+releaseException sel (ReleaseExceptionWith se) = case fromException se of+ Just e -> sel e+ Nothing -> False+releaseException _ _ = False++just :: (a -> Bool) -> Maybe a -> Bool+just sel (Just x) = sel x+just _ Nothing = False++dummy :: Selector Dummy+dummy Dummy = True