@@ -9,13 +9,13 @@
9module Streamly.Internal.Data.Stream.Exception
9module Streamly.Internal.Data.Stream.Exception
12− , after_
12+ , afterUnsafe
14− , bracket_
14+ , bracketUnsafe
15 , bracketIO
15 , bracketIO
16 , bracket3IO
16 , bracket3IO
17 , onException
17 , onException
18− , finally_
18+ , finallyUnsafe
19 , finallyIO
19 , finallyIO
@@ -59,13 +59,13 @@ before action xs = fromStreamD $ D.before action $ toStreamD xs
60-- Same as the following, but with stream fusion:
60-- Same as the following, but with stream fusion:
62−-- >>> after_ action xs = xs <> Stream.nilM action
62+-- >>> afterUnsafe action xs = xs <> Stream.nilM action
64-- /Pre-release/
64-- /Pre-release/
66−{-# INLINE after_ #-}
66+{-# INLINE afterUnsafe #-}
67−after_ :: Monad m => m b -> Stream m a -> Stream m a
67+afterUnsafe :: Monad m => m b -> Stream m a -> Stream m a
68−after_ action xs = fromStreamD $ D.after_ action $ toStreamD xs
68+afterUnsafe action xs = fromStreamD $ D.after_ action $ toStreamD xs
70-- | Run the action @IO b@ whenever the stream stream stops normally, or
70-- | Run the action @IO b@ whenever the stream stream stops normally, or
71-- if it is garbage collected after a partial lazy evaluation.
71-- if it is garbage collected after a partial lazy evaluation.
@@ -73,7 +73,7 @@ after_ action xs = fromStreamD $ D.after_ action $ toStreamD xs
73-- The semantics of the action @IO b@ are similar to the semantics of cleanup
73-- The semantics of the action @IO b@ are similar to the semantics of cleanup
74-- action in 'bracketIO'.
74-- action in 'bracketIO'.
76−-- /See also 'after_'/
76+-- /See also 'afterUnsafe'/
78{-# INLINE afterIO #-}
78{-# INLINE afterIO #-}
79afterIO :: MonadIO m => IO b -> Stream m a -> Stream m a
79afterIO :: MonadIO m => IO b -> Stream m a -> Stream m a
@@ -98,9 +98,9 @@ onException action xs = fromStreamD $ D.onException action $ toStreamD xs
99-- /Pre-release/
99-- /Pre-release/
101−{-# INLINE finally_ #-}
101+{-# INLINE finallyUnsafe #-}
102−finally_ :: MonadCatch m => m b -> Stream m a -> Stream m a
102+finallyUnsafe :: MonadCatch m => m b -> Stream m a -> Stream m a
103−finally_ action xs = fromStreamD $ D.finally_ action $ toStreamD xs
103+finallyUnsafe action xs = fromStreamD $ D.finally_ action $ toStreamD xs
105-- | Run the action @IO b@ whenever the stream stream stops normally, aborts
105-- | Run the action @IO b@ whenever the stream stream stops normally, aborts
106-- due to an exception or if it is garbage collected after a partial lazy
106-- due to an exception or if it is garbage collected after a partial lazy
@@ -111,7 +111,7 @@ finally_ action xs = fromStreamD $ D.finally_ action $ toStreamD xs
112-- >>> finallyIO release = Stream.bracketIO (return ()) (const release)
112-- >>> finallyIO release = Stream.bracketIO (return ()) (const release)
114−-- /See also 'finally_'/
114+-- /See also 'finallyUnsafe'/
116-- /Inhibits stream fusion/
116-- /Inhibits stream fusion/
@@ -131,11 +131,10 @@ finallyIO action xs = fromStreamD $ D.finally action $ toStreamD xs
132-- /Pre-release/
132-- /Pre-release/
134−{-# INLINE bracket_ #-}
134+{-# INLINE bracketUnsafe #-}
135−bracket_ :: MonadCatch m
135+bracketUnsafe :: MonadCatch m
136 => m b -> (b -> m c) -> (b -> Stream m a) -> Stream m a
136 => m b -> (b -> m c) -> (b -> Stream m a) -> Stream m a
137−bracket_ bef aft bet = fromStreamD $
138− D.bracket_ bef aft (toStreamD . bet)
137+bracketUnsafe bef aft bet = fromStreamD $ D.bracket_ bef aft (toStreamD . bet)
140-- | Run the alloc action @IO b@ with async exceptions disabled but keeping
139-- | Run the alloc action @IO b@ with async exceptions disabled but keeping
141-- blocking operations interruptible (see 'Control.Exception.mask'). Use the
140-- blocking operations interruptible (see 'Control.Exception.mask'). Use the
@@ -154,7 +153,7 @@ bracket_ bef aft bet = fromStreamD $
154-- immediately in the current thread context, whereas in other cases it runs in
153-- immediately in the current thread context, whereas in other cases it runs in
155-- the GC context, therefore, cleanup may be delayed until the GC gets to run.
154-- the GC context, therefore, cleanup may be delayed until the GC gets to run.
157−-- /See also: 'bracket_'/
156+-- /See also: 'bracketUnsafe'/
159-- /Inhibits stream fusion/
158-- /Inhibits stream fusion/
@@ -167,11 +166,17 @@ bracketIO bef aft = bracket3IO bef aft aft aft
167-- the process in case of exception or garbage collection, but waits for the
166-- the process in case of exception or garbage collection, but waits for the
168-- process to terminate in normal cases.
167-- process to terminate in normal cases.
170−-- | Like 'bracketIO' but can use separate cleanup actions depending on the mode
169+-- | Like 'bracketIO' but can use 3 separate cleanup actions depending on the
170+-- mode of termination:
172+-- 1. When the stream stops normally
173+-- 2. When the stream is garbage collected
174+-- 3. When the stream encounters an exception
171−-- of termination. @bracket3IO before onStop onGC onException action@ runs
176+-- @bracket3IO before onStop onGC onException action@ runs @action@ using the
172−-- @action@ using the result of @before@. If the stream stops, @onStop@ action
177+-- result of @before@. If the stream stops, @onStop@ action is executed, if the
173−-- is executed, if the stream is abandoned @onGC@ is executed, if the stream
178+-- stream is abandoned @onGC@ is executed, if the stream encounters an
174−-- encounters an exception @onException@ is executed.
179+-- exception @onException@ is executed.
176-- /Pre-release/
181-- /Pre-release/
177{-# INLINE bracket3IO #-}
182{-# INLINE bracket3IO #-}