Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- withResource :: forall m a b. (MonadBaseControl IO m) => Pool a -> (a -> m (Bool, b)) -> m b
- {-# SPECIALIZE withResource :: Pool a -> (a -> IO (Bool,b)) -> IO b #-}
- withResource pool act = fmap snd result
- where
- result :: m (Bool, b)
- result = control $ runInIO -> mask $ restore -> do
- resource <- takeResource pool
- ret <- restore (runInIO (act resource)) `onException`
- destroyResource pool resource
- void . runInIO $ do
- (keep, _) <- restoreM ret :: m (Bool, b)
- if keep
- then liftBaseWith $ _ -> putResource pool resource
- else liftBaseWith $ _ -> destroyResource pool resource
- return ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement