X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=GHC%2FIO.hs;h=ad98a5ebf5460392c3e8523d65cffe74388a6f50;hb=be2750a0a11b919fb03cc070074e430f88bdfa90;hp=d5272ba8661d3f212c5eef8ae2ecafaf76dfa253;hpb=1523de9c11a0663e538f00679f6a4a682295b2de;p=ghc-base.git diff --git a/GHC/IO.hs b/GHC/IO.hs index d5272ba..ad98a5e 100644 --- a/GHC/IO.hs +++ b/GHC/IO.hs @@ -1,5 +1,10 @@ +{-# LANGUAGE NoImplicitPrelude + , BangPatterns + , RankNTypes + , MagicHash + , UnboxedTuples + #-} {-# OPTIONS_GHC -funbox-strict-fields #-} -{-# LANGUAGE NoImplicitPrelude, BangPatterns, RankNTypes #-} {-# OPTIONS_HADDOCK hide #-} ----------------------------------------------------------------------------- -- | @@ -31,7 +36,7 @@ module GHC.IO ( mask, mask_, uninterruptibleMask, uninterruptibleMask_, MaskingState(..), getMaskingState, block, unblock, blocked, unsafeUnmask, - onException, finally, evaluate + onException, bracket, finally, evaluate ) where import GHC.Base @@ -337,6 +342,7 @@ getMaskingState = IO $ \s -> 1# -> MaskedUninterruptible _ -> MaskedInterruptible #) +{-# DEPRECATED blocked "use Control.Exception.getMaskingState instead" #-} -- | returns True if asynchronous exceptions are blocked in the -- current thread. blocked :: IO Bool @@ -426,6 +432,18 @@ uninterruptibleMask io = do MaskedInterruptible -> blockUninterruptible $ io block MaskedUninterruptible -> io id +bracket + :: IO a -- ^ computation to run first (\"acquire resource\") + -> (a -> IO b) -- ^ computation to run last (\"release resource\") + -> (a -> IO c) -- ^ computation to run in-between + -> IO c -- returns the value from the in-between computation +bracket before after thing = + mask $ \restore -> do + a <- before + r <- restore (thing a) `onException` after a + _ <- after a + return r + finally :: IO a -- ^ computation to run first -> IO b -- ^ computation to run afterward (even if an exception -- was raised)