Skip to content

Commit

Permalink
Use controlIO directly instead of Control.Exception.Control.onException
Browse files Browse the repository at this point in the history
This should be slightly more efficient in case an exception is thrown
because the exception handler is already an IO computation.
  • Loading branch information
basvandijk committed Jul 14, 2011
1 parent 4aa471d commit 595df93
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions Data/Pool.hs
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 595df93

Please sign in to comment.