resourcet 0.4.4 → 0.4.5
raw patch · 3 files changed
+25/−5 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Control.Monad.Trans.Resource: unprotect :: MonadIO m => ReleaseKey -> m (Maybe (IO ()))
Files
- Control/Monad/Trans/Resource.hs +16/−4
- resourcet.cabal +1/−1
- test/main.hs +8/−0
Control/Monad/Trans/Resource.hs view
@@ -36,6 +36,7 @@ , allocate , register , release+ , unprotect , resourceMask -- * Type class/associated types , MonadResource (..)@@ -208,8 +209,18 @@ -- -- Since 0.3.0 release :: MonadIO m => ReleaseKey -> m ()-release (ReleaseKey istate rk) = liftIO $ release' istate rk+release (ReleaseKey istate rk) = liftIO $ release' istate rk + (maybe (return ()) id) +-- | Unprotect resource from cleanup actions, this allowes you to send+-- resource into another resourcet process and reregister it there.+-- It returns an release action that should be run in order to clean +-- resource or Nothing in case if resource is already freed.+--+-- Since 0.4.5+unprotect :: MonadIO m => ReleaseKey -> m (Maybe (IO ()))+unprotect (ReleaseKey istate rk) = liftIO $ release' istate rk return+ -- | Perform some allocation, and automatically register a cleanup action. -- -- This is almost identical to calling the allocation and then@@ -298,10 +309,11 @@ release' :: I.IORef ReleaseMap -> Int- -> IO ()-release' istate key = E.mask $ \restore -> do+ -> (Maybe (IO ()) -> IO a)+ -> IO a+release' istate key act = E.mask $ \restore -> do maction <- I.atomicModifyIORef istate lookupAction- maybe (return ()) restore maction+ restore (act maction) where lookupAction rm@(ReleaseMap next rf m) = case IntMap.lookup key m of
resourcet.cabal view
@@ -1,5 +1,5 @@ Name: resourcet-Version: 0.4.4+Version: 0.4.5 Synopsis: Deterministic allocation and freeing of scarce resources. Description: This package was originally included with the conduit package, and has since been split off. For more information, please see <http://www.yesodweb.com/book/conduits>.
test/main.hs view
@@ -29,6 +29,14 @@ describe "forking" $ do forkHelper "resourceForkIO" resourceForkIO --forkHelper "lifted fork" fork+ describe "unprotecting" $ do+ it "unprotect keeps resource from being cleared" $ do+ x <- newIORef 0+ runResourceT $ do+ key <- register $ writeIORef x 1+ unprotect key+ y <- readIORef x+ y `shouldBe` 0 forkHelper s fork' = describe s $ do it "waits for all threads" $ do