2-- Module : Streamly.Internal.Data.Stream.Concurrent.Channel
3-- Copyright : (c) 2017 Composewell Technologies
4-- License : BSD-3-Clause
5-- Maintainer : streamly@composewell.com
6-- Stability : experimental
9module Streamly.Internal.Data.Stream.Concurrent.Channel
20 -- quiesceChannel -- wait for running tasks but do not schedule any more.
43 -- ** Scheduling behavior
53import Streamly.Internal.Control.Concurrent (MonadAsync)
54import Streamly.Internal.Data.Stream (Stream)
55import Streamly.Internal.Data.Stream.Concurrent.Channel.Operations
56 (fromChannel, fromChannelK, toChannel, toChannelK)
58import qualified Streamly.Internal.Data.Stream.Concurrent.Channel.Append
60import qualified Streamly.Internal.Data.Stream.Concurrent.Channel.Interleave
62import qualified Streamly.Internal.Data.StreamK as K
64import Streamly.Internal.Data.Stream.Concurrent.Channel.Type
65import Streamly.Internal.Data.Stream.Channel.Types
67-- | Create a new concurrent stream evaluation channel. The monad
68-- state used to run the stream actions is captured from the call site of
70{-# INLINE newChannel #-}
71newChannel :: MonadAsync m =>
72 (Config -> Config) -> m (Channel m a)
74 let cfg = modifier defaultConfig
75 in if getInterleaved cfg
76 then Interleave.newChannel modifier
77 else Append.newChannel modifier
79-- | Allocate a channel and evaluate the stream using the channel and the
80-- supplied evaluator function. The evaluator is run in a worker thread.
81{-# INLINE withChannelK #-}
82withChannelK :: MonadAsync m =>
85 -> (Channel m b -> K.StreamK m a -> K.StreamK m b)
87withChannelK modifier input evaluator = K.concatEffect action
92 chan <- newChannel modifier
93 toChannelK chan (evaluator chan input)
94 return $ fromChannelK chan
96-- | Allocate a channel and evaluate the stream using the channel and the
97-- supplied evaluator function. The evaluator is run in a worker thread.
98{-# INLINE withChannel #-}
99withChannel :: MonadAsync m =>
102 -> (Channel m b -> Stream m a -> Stream m b)
104withChannel modifier input evaluator =
105 let f chan stream = K.fromStream $ evaluator chan (K.toStream stream)
106 in K.toStream $ withChannelK modifier (K.fromStream input) f
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