Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add missing MonadCatch instance #501

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion conduit/src/Conduit.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module Conduit
, MonadIO (..)
, MonadTrans (..)
, MonadThrow (..)
, MonadCatch (..)
, MonadUnliftIO (..)
, PrimMonad (..)
-- * ResourceT
Expand All @@ -39,5 +40,5 @@ import Control.Monad.Primitive (PrimMonad (..), PrimState)
import Data.Conduit.Lift
import Data.Conduit.Combinators.Unqualified
import Data.Functor.Identity (Identity (..))
import Control.Monad.Trans.Resource (MonadResource, MonadThrow (..), runResourceT, ResourceT)
import Control.Monad.Trans.Resource (MonadResource, MonadThrow (..), MonadCatch (..), runResourceT, ResourceT)
import Data.Acquire hiding (with)
4 changes: 3 additions & 1 deletion conduit/src/Data/Conduit.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
module Data.Conduit
( -- * Core interface
-- ** Types
ConduitT
ConduitT(..)
, Pipe(..)
-- *** Deprecated
, Source
, Conduit
Expand Down Expand Up @@ -101,6 +102,7 @@ module Data.Conduit
) where

import Data.Conduit.Internal.Conduit
import Data.Conduit.Internal.Pipe (Pipe(..))
import Data.Void (Void)
import Data.Functor.Identity (Identity, runIdentity)
import Control.Monad.Trans.Resource (ResourceT, runResourceT)
Expand Down
11 changes: 11 additions & 0 deletions conduit/src/Data/Conduit/Internal/Conduit.hs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,17 @@ instance MonadFail m => MonadFail (ConduitT i o m) where
instance MonadThrow m => MonadThrow (ConduitT i o m) where
throwM = lift . throwM

instance MonadCatch m => MonadCatch (ConduitT i o m) where
catch (ConduitT c0) f = ConduitT $ \rest ->
let go (HaveOutput p o) = HaveOutput (go p) o
go (NeedInput p c) = NeedInput (\i -> go (p i)) (\u -> go (c u))
go (Done x) = rest x
go (PipeM mp) =
PipeM $ catch (liftM go mp) $ \e -> do
return $ unConduitT (f e) rest
go (Leftover p i) = Leftover (go p) i
in go (c0 Done)

instance MonadIO m => MonadIO (ConduitT i o m) where
liftIO = lift . liftIO
{-# INLINE liftIO #-}
Expand Down
3 changes: 2 additions & 1 deletion resourcet/Control/Monad/Trans/Resource.hs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ module Control.Monad.Trans.Resource
, closeInternalState
-- * Reexport
, MonadThrow (..)
, MonadCatch (..)
) where

import qualified Data.IntMap as IntMap
Expand All @@ -65,7 +66,7 @@ import Control.Monad.Trans.Resource.Internal

import Control.Concurrent (ThreadId, forkIO)

import Control.Monad.Catch (MonadThrow, throwM)
import Control.Monad.Catch (MonadThrow (..), MonadCatch (..))
import Data.Acquire.Internal (ReleaseType (..))


Expand Down