on master help sign in
Do not kill thread on extract

If the fold is used for scan, we will end up killing the thread immediately. Kill it when the fold is done. We are still not killing the thread if the fold is GCed, but it anyway go away on timeout.

commited471dd0905d9399a8aea299bce1a1dfc3c2018c authorHarendra Kumar <harendra@composewell.com> dateThu 10 Dec 2020, 15:05 (6 years ago) parent6e38939
1 file changed+4−6
src/Streamly/Internal/Data/Fold/Types.hs+4−6
src/Streamly/Internal/Data/Fold/Types.hs+4−6
@@ -759,13 +759,11 @@ takeByTime n (Fold step initial done) = Fold step' initial' done'
759759 Done bres -> return $ Done bres
760760 else do
761761 res <- step s a
762− return
763− $ case res of
764− Partial sres -> Partial $ Tuple3' sres mv t
765− Done bres -> Done bres
762+ case res of
763+ Partial fs -> return $ Partial $ Tuple3' fs mv t
764+ Done b -> liftIO (killThread t) >> return (Done b)
766765
767− done' (Tuple3' s _ t) = liftIO (killThread t) >> done s
768− -- XXX thread should be killed at cleanup
766+ done' (Tuple3' s _ _) = done s
769767
770768 timerThread mv = do
771769 liftIO $ threadDelay (round $ n * 1000000)