Browse files

Use controlIO directly instead of Control.Exception.Control.onException

This should be slightly more efficient in case an exception is thrown
because the exception handler is already an IO computation.
  • Loading branch information...
1 parent 4aa471d commit 595df934af75a4b98054a713fe51ca706d4005c5 @basvandijk basvandijk committed Jul 14, 2011
Showing with 3 additions and 4 deletions.
  1. +3 −4 Data/Pool.hs
7 Data/Pool.hs
@@ -28,11 +28,10 @@ module Data.Pool
import Control.Applicative ((<$>))
import Control.Concurrent (forkIO, killThread, myThreadId, threadDelay)
import Control.Concurrent.STM
-import Control.Exception (SomeException, catch)
-import Control.Exception.Control (onException)
+import Control.Exception (SomeException, catch, onException)
import Control.Monad (forM_, forever, join, liftM2, unless, when)
import Control.Monad.IO.Class (liftIO)
-import Control.Monad.IO.Control (MonadControlIO)
+import Control.Monad.IO.Control (MonadControlIO, controlIO)
import Data.Hashable (hash)
import Data.List (partition)
import Data.Time.Clock (NominalDiffTime, UTCTime, diffUTCTime, getCurrentTime)
@@ -180,7 +179,7 @@ withResource Pool{..} act = do
writeTVar inUse $! used + 1
return $
create `onException` atomically (modifyTVar_ inUse (subtract 1))
- ret <- act resource `onException` (liftIO $ do
+ ret <- controlIO $ \runInIO -> runInIO (act resource) `onException` (do
destroy resource `catch` \(_::SomeException) -> return ()
atomically (modifyTVar_ inUse (subtract 1)))
liftIO $ do

0 comments on commit 595df93

Please sign in to comment.