on master help sign in
Added comments.
c5d0871Shlok Datye
src/Streamly/Internal/Data/Stream/StreamD.hs+4
@@ -2951,6 +2951,10 @@ gbracketIO bef exc aft fexc fnormal =
2951 -- weak pointer to us.
2951 -- weak pointer to us.
2952 {-# INLINE_LATE step #-}
2952 {-# INLINE_LATE step #-}
2953 step _ GBracketIOInit = do
2953 step _ GBracketIOInit = do
2954+ -- We mask asynchronous exceptions to make the execution
2955+ -- of 'bef' and the registration of 'aft' atomic.
2956+ -- A similar thing is done in the resourcet package: https://git.io/JvKV3
2957+ -- Tutorial: https://markkarpov.com/tutorial/exceptions.html
2954 (r, ref) <- liftBaseOp_ mask_ $ do
2958 (r, ref) <- liftBaseOp_ mask_ $ do
2955 r <- bef
2959 r <- bef
2956 ref <- newFinalizedIORef (aft r)
2960 ref <- newFinalizedIORef (aft r)
src/Streamly/Internal/Data/Unfold.hs+4
@@ -788,6 +788,8 @@ gbracketIO bef exc aft (Unfold estep einject) (Unfold step1 inject1) =
788 where
788 where
789
789
790 inject x = do
790 inject x = do
791+ -- Mask asynchronous exceptions to make the execution of 'bef' and
792+ -- the registration of 'aft' atomic. See comment in 'D.gbracketIO'.
791 (r, ref) <- liftBaseOp_ mask_ $ do
793 (r, ref) <- liftBaseOp_ mask_ $ do
792 r <- bef x
794 r <- bef x
793 ref <- D.newFinalizedIORef (aft r)
795 ref <- D.newFinalizedIORef (aft r)
@@ -1040,6 +1042,8 @@ bracketIO bef aft (Unfold step1 inject1) = Unfold step inject
1040 where
1042 where
1041
1043
1042 inject x = do
1044 inject x = do
1045+ -- Mask asynchronous exceptions to make the execution of 'bef' and
1046+ -- the registration of 'aft' atomic. See comment in 'D.gbracketIO'.
1043 (r, ref) <- liftBaseOp_ mask_ $ do
1047 (r, ref) <- liftBaseOp_ mask_ $ do
1044 r <- bef x
1048 r <- bef x
1045 ref <- D.newFinalizedIORef (aft r)
1049 ref <- D.newFinalizedIORef (aft r)