@@ -60,7 +60,7 @@ gbracket_
60 :: Monad m
60 :: Monad m
61 => m c -- ^ before
61 => m c -- ^ before
62 -> (c -> m d) -- ^ after, on normal stop
62 -> (c -> m d) -- ^ after, on normal stop
63− -> (c -> e -> Stream m b -> Stream m b) -- ^ on exception
63+ -> (c -> e -> Stream m b -> m (Stream m b)) -- ^ on exception
64 -> (forall s. m s -> m (Either e s)) -- ^ try (exception handling)
64 -> (forall s. m s -> m (Either e s)) -- ^ try (exception handling)
65 -> (c -> Stream m b) -- ^ stream generator
65 -> (c -> Stream m b) -- ^ stream generator
66 -> Stream m b
66 -> Stream m b
@@ -83,9 +83,9 @@ gbracket_ bef aft onExc ftry action =
83 Skip s -> return $ Skip (GBracketNormal (Stream step1 s) v)
83 Skip s -> return $ Skip (GBracketNormal (Stream step1 s) v)
84 Stop -> aft v >> return Stop
84 Stop -> aft v >> return Stop
85 -- XXX Do not handle async exceptions, just rethrow them.
85 -- XXX Do not handle async exceptions, just rethrow them.
86− Left e ->
86+ Left e -> do
88− $ Skip (GBracketException (onExc v e (UnStream step1 st)))
87+ strm <- onExc v e (UnStream step1 st)
88+ return $ Skip (GBracketException strm)
89 step gst (GBracketException (UnStream step1 st)) = do
89 step gst (GBracketException (UnStream step1 st)) = do
90 res <- step1 gst st
90 res <- step1 gst st
91 case res of
91 case res of
@@ -265,7 +265,7 @@ onException action stream =
265 gbracket_
265 gbracket_
266 (return ()) -- before
266 (return ()) -- before
267 return -- after
267 return -- after
268− (\_ (e :: MC.SomeException) _ -> nilM (action >> MC.throwM e))
268+ (\_ (e :: MC.SomeException) _ -> action >> MC.throwM e)
269 (inline MC.try)
269 (inline MC.try)
270 (const stream)
270 (const stream)
@@ -301,7 +301,7 @@ bracketUnsafe bef aft =
301 gbracket_
301 gbracket_
304− (\a (e :: SomeException) _ -> nilM (aft a >> MC.throwM e))
304+ (\a (e :: SomeException) _ -> aft a >> MC.throwM e)
305 (inline MC.try)
305 (inline MC.try)
307-- For a use case of this see the "streamly-process" package. It needs to kill
307-- For a use case of this see the "streamly-process" package. It needs to kill
@@ -437,7 +437,7 @@ finallyIO action xs = bracketIO3 (return ()) act act act (const xs)
438{-# INLINE_NORMAL ghandle #-}
438{-# INLINE_NORMAL ghandle #-}
439ghandle :: (MonadCatch m, Exception e)
439ghandle :: (MonadCatch m, Exception e)
440− => (e -> Stream m a -> Stream m a) -> Stream m a -> Stream m a
440+ => (e -> Stream m a -> m (Stream m a)) -> Stream m a -> Stream m a
441ghandle f stream =
441ghandle f stream =
442 gbracket_ (return ()) return (const f) (inline MC.try) (const stream)
442 gbracket_ (return ()) return (const f) (inline MC.try) (const stream)
@@ -448,7 +448,7 @@ ghandle f stream =
449{-# INLINE_NORMAL handle #-}
449{-# INLINE_NORMAL handle #-}
450handle :: (MonadCatch m, Exception e)
450handle :: (MonadCatch m, Exception e)
451− => (e -> Stream m a) -> Stream m a -> Stream m a
451+ => (e -> m (Stream m a)) -> Stream m a -> Stream m a
452handle f stream =
452handle f stream =
453 gbracket_ (return ()) return (\_ e _ -> f e) (inline MC.try) (const stream)
453 gbracket_ (return ()) return (\_ e _ -> f e) (inline MC.try) (const stream)