on master help sign in
rethrow exceptions in gbracket based impls
commita65148c304e1cd323fb6c3167ccd2dd81572d9e0 authorHarendra Kumar <harendra.kumar@gmail.com> dateThu 14 Nov 2019, 13:43 (7 years ago) parent10326ed
1 file changed+4−3
src/Streamly/Internal/Data/Unfold.hs+4−3
src/Streamly/Internal/Data/Unfold.hs+4−3
@@ -705,7 +705,7 @@ _onException :: MonadCatch m => (a -> m c) -> Unfold m a b -> Unfold m a b
705705_onException action unf =
706706 gbracket return MC.try
707707 (\_ -> return ())
708− (nilM (\(a, (_ :: MC.SomeException)) -> action a)) unf
708+ (nilM (\(a, (e :: MC.SomeException)) -> action a >> MC.throwM e)) unf
709709
710710-- | Run a side effect whenever the unfold aborts due to an exception.
711711--
@@ -732,7 +732,7 @@ onException action (Unfold step1 inject1) = Unfold step inject
732732_finally :: MonadCatch m => (a -> m c) -> Unfold m a b -> Unfold m a b
733733_finally action unf =
734734 gbracket return MC.try action
735− (nilM (\(a, (_ :: MC.SomeException)) -> action a)) unf
735+ (nilM (\(a, (e :: MC.SomeException)) -> action a >> MC.throwM e)) unf
736736
737737-- | Run a side effect whenever the unfold stops normally or aborts due to an
738738-- exception.
@@ -760,7 +760,8 @@ finally action (Unfold step1 inject1) = Unfold step inject
760760_bracket :: MonadCatch m
761761 => (a -> m c) -> (c -> m d) -> Unfold m c b -> Unfold m a b
762762_bracket bef aft unf =
763− gbracket bef MC.try aft (nilM (\(a, (_ :: MC.SomeException)) -> aft a)) unf
763+ gbracket bef MC.try aft (nilM (\(a, (e :: MC.SomeException)) -> aft a >>
764+ MC.throwM e)) unf
764765
765766-- | @bracket before after between@ runs the @before@ action and then unfolds
766767-- its output using the @between@ unfold. When the @between@ unfold is done or