on master help sign in
Do not lose stream state in ahead stream

When executing a stream in ahead composition where we have composed multiple streams using `ahead`, we are executing each element of the stream using the fresh state from SVar at the fork point. This fix changes it such that we only use the fresh state from SVar only at the start of stream execution and not for each element of the stream. When yielding subsequent elements we have to carry any state changes made when we yielded the previous elements.

commit37452d9ff991d8a3344661c80fa199555bc428b8 authorHarendra Kumar <harendra.kumar@gmail.com> dateThu 16 Jan 2020, 14:16 (7 years ago) parent60cee48
1 file changed+3−3
src/Streamly/Internal/Data/Stream/Ahead.hs+3−3
src/Streamly/Internal/Data/Stream/Ahead.hs+3−3
@@ -300,7 +300,7 @@ processHeap q heap st sv winfo entry sno stopping = loopHeap sno entry
300300 let stop = do
301301 liftIO (incrementYieldLimit sv)
302302 nextHeap seqNo
303− foldStreamSVar sv st
303+ foldStreamShared st
304304 (yieldStreamFromHeap seqNo)
305305 (singleStreamFromHeap seqNo)
306306 stop
@@ -437,7 +437,7 @@ processWithToken q heap st sv winfo action sno = do
437437 let stop = do
438438 liftIO (incrementYieldLimit sv)
439439 loopWithToken (seqNo + 1)
440− foldStreamSVar sv st
440+ foldStreamShared st
441441 (yieldOutput seqNo)
442442 (singleOutput seqNo)
443443 stop
@@ -468,7 +468,7 @@ processWithToken q heap st sv winfo action sno = do
468468 let stop = do
469469 liftIO (incrementYieldLimit sv)
470470 loopWithToken (seqNo + 1)
471− foldStreamSVar sv st
471+ foldStreamShared st
472472 (yieldOutput seqNo)
473473 (singleOutput seqNo)
474474 stop