2-- Module : Streamly.Internal.Data.Fold.Concurrent.Channel
3-- Copyright : (c) 2022 Composewell Technologies
4-- License : BSD-3-Clause
5-- Maintainer : streamly@composewell.com
6-- Stability : experimental
9module Streamly.Internal.Data.Fold.Concurrent.Channel
24import Control.Concurrent (takeMVar)
25import Control.Monad (void, when)
26import Control.Monad.IO.Class (MonadIO(liftIO))
27import Data.IORef (writeIORef)
28import Streamly.Internal.Control.Concurrent (MonadAsync)
29import Streamly.Internal.Data.Fold (Fold(..), Step (..))
30import Streamly.Internal.Data.Stream.Channel.Worker (sendWithDoorBell)
31import Streamly.Internal.Data.Time.Clock (Clock(Monotonic), getTime)
33import Streamly.Internal.Data.Fold.Concurrent.Channel.Type
34import Streamly.Internal.Data.Stream.Channel.Types
36-------------------------------------------------------------------------------
38-------------------------------------------------------------------------------
40-- XXX Cleanup the fold if the stream is interrupted. Add a GC hook.
42-- | Evaluate the fold asynchronously in a worker thread separate from the
45{-# INLINABLE parEval #-}
46parEval :: MonadAsync m => (Config -> Config) -> Fold m a b -> Fold m a b
48 Fold step initial extract
52 initial = Partial <$> newChannel modifier f
54 -- XXX This is not truly asynchronous. If the fold is done we only get to
55 -- know when we send the next input unless the stream ends. We could
56 -- potentially throw an async exception to the driver to inform it
57 -- asynchronously. Alternatively, the stream should not block forever, it
58 -- should keep polling the fold status. We can insert a timer tick in the
59 -- input stream to do that.
61 -- A polled stream abstraction may be useful, it would consist of normal
62 -- events and tick events, latter are guaranteed to arrive.
64 status <- sendToWorker chan a
65 return $ case status of
66 Nothing -> Partial chan
75 status <- checkFoldStatus chan
80 (svarInspectMode chan)
82 "parEval: waiting to drain"
83 $ takeMVar (outputDoorBellFromConsumer chan)
84 -- XXX remove recursion
87 when (svarInspectMode chan) $ liftIO $ do
88 t <- getTime Monotonic
89 writeIORef (svarStopTime (svarStats chan)) (Just t)
90 printSVar (dumpSVar chan) "SVar Done"
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list