Skip to content
Closed
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
1 change: 1 addition & 0 deletions core/src/Streamly/Data/Stream.hs
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,7 @@ module Streamly.Data.Stream
-- stream of arrays before flattening it to a stream of chars.
--
, onException
, onExceptionE
, handle

-- * Resource Management
Expand Down
10 changes: 8 additions & 2 deletions core/src/Streamly/Internal/Data/Stream/Exception.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ module Streamly.Internal.Data.Stream.Exception

-- * Exceptions
, onException
, onExceptionE
, ghandle
, handle
)
Expand Down Expand Up @@ -280,11 +281,16 @@ afterIO action (Stream step state) = Stream step' Nothing
--
{-# INLINE_NORMAL onException #-}
onException :: MonadCatch m => m b -> Stream m a -> Stream m a
onException action stream =
onException action = onExceptionE $
\(e :: MC.SomeException) -> action >> MC.throwM e

{-# INLINE_NORMAL onExceptionE #-}
onExceptionE :: (Exception e, MonadCatch m) => (forall b. e -> m b) -> Stream m a -> Stream m a
onExceptionE onE stream =
gbracket_
(return ()) -- before
return -- after
(\_ (e :: MC.SomeException) _ -> action >> MC.throwM e)
(\_ e _ -> onE e)
(inline MC.try)
(const stream)

Expand Down
Loading