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
11 module Streamly.Internal.Data.Stream.Concurrent.Channel.Type
12 , module Streamly.Internal.Data.Stream.Concurrent.Channel.Operations
13 , module Streamly.Internal.Data.Stream.Concurrent.Channel.Append
14 , module Streamly.Internal.Data.Stream.Concurrent.Channel.Interleave
15 , module Streamly.Internal.Data.Stream.Concurrent.Channel.Dispatcher
16 , module Streamly.Internal.Data.Stream.Concurrent.Channel.Consumer
23 -- quiesceChannel -- wait for running tasks but do not schedule any more.
46 -- ** Scheduling behavior
56import Streamly.Internal.Control.Concurrent (MonadAsync)
57import Streamly.Internal.Data.Stream (Stream)
59import qualified Streamly.Internal.Data.StreamK as K
61import Streamly.Internal.Data.Channel.Types
63import Streamly.Internal.Data.Stream.Concurrent.Channel.Type
64import Streamly.Internal.Data.Stream.Concurrent.Channel.Operations
65import Streamly.Internal.Data.Stream.Concurrent.Channel.Append
66import Streamly.Internal.Data.Stream.Concurrent.Channel.Interleave
67import Streamly.Internal.Data.Stream.Concurrent.Channel.Dispatcher
68import Streamly.Internal.Data.Stream.Concurrent.Channel.Consumer
70-- | Create a new concurrent stream evaluation channel. The monad
71-- state used to run the stream actions is captured from the call site of
73{-# INLINE newChannel #-}
74newChannel :: MonadAsync m =>
75 (Config -> Config) -> m (Channel m a)
77 let cfg = modifier defaultConfig
78 in if getInterleaved cfg
79 then newInterleaveChannel modifier
80 else newAppendChannel modifier
82-- | Allocate a channel and evaluate the stream using the channel and the
83-- supplied evaluator function. The evaluator is run in a worker thread.
84{-# INLINE withChannelK #-}
85withChannelK :: MonadAsync m =>
88 -> (Channel m b -> K.StreamK m a -> K.StreamK m b)
90withChannelK modifier input evaluator = K.concatEffect action
95 chan <- newChannel modifier
96 toChannelK chan (evaluator chan input)
97 return $ fromChannelK chan
99-- | Allocate a channel and evaluate the stream using the channel and the
100-- supplied evaluator function. The evaluator is run in a worker thread.
101{-# INLINE withChannel #-}
102withChannel :: MonadAsync m =>
105 -> (Channel m b -> Stream m a -> Stream m b)
107withChannel modifier input evaluator =
108 let f chan stream = K.fromStream $ evaluator chan (K.toStream stream)
109 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