on master help sign in
Clarify the docs of 'parEval'
commit4032b6425c44acef8343f049be3f6ce0ef23981d authorHarendra Kumar <harendra@composewell.com> dateSun 24 Dec 2023, 02:48 (3 years ago) parent0e73809
2 files changed+37−24
src/Streamly/Data/Stream/Prelude.hs+20−15 src/Streamly/Internal/Data/Stream/Concurrent.hs+17−9
src/Streamly/Data/Stream/Prelude.hs+20−15
@@ -61,25 +61,28 @@ module Streamly.Data.Stream.Prelude
6161 -- | Stream combinators using a concurrent channel.
6262
6363 -- *** Evaluate
64− -- | Evaluates a serial stream asynchronously using a concurency channel.
64+ -- | Evaluate a stream as a whole concurrently with respect to the consumer
65+ -- of the stream.
6566
6667 , parEval
6768
6869 -- *** Generate
69− -- | Uses a concurrency channel to evaluate multiple actions concurrently.
70+ -- | Generate a stream by evaluating multiple actions concurrently.
7071 , parRepeatM
7172 , parReplicateM
7273 , fromCallback
7374
7475 -- *** Map
75− -- | Uses a concurrency channel to evaluate multiple mapped actions
76− -- concurrently.
76+ -- | Map actions on a stream such that the mapped actions are evaluated
77+ -- concurrently with each other.
7778
7879 , parMapM
7980 , parSequence
8081
8182 -- *** Combine two
82− -- | Use a channel for each pair.
83+ -- | Combine two streams such that each stream as a whole is evaluated
84+ -- concurrently with respect to the other stream as well as the consumer of
85+ -- the resulting stream.
8386 , parZipWithM
8487 , parZipWith
8588 , parMergeByM
@@ -157,16 +160,18 @@ import Streamly.Internal.Data.Stream.Prelude
157160-- 'parConcatMap', and 'parConcatIterate', all concurrency combinators can be
158161-- expressed in terms of these.
159162--
160−-- 'parEval', evaluates a single stream asynchronously, a worker thread runs
161−-- the stream and buffers the results, and the consumer of the stream runs in
162−-- another thread consuming it from the buffer, thus decoupling the production
163−-- and consumption of the stream. This can be used to run different stages of a
164−-- pipeline concurrently.
165−--
166−-- 'parConcatMap' is used to evaluate multiple streams concurrently and combine
167−-- the results. A stream generator function is mapped to the input stream and
168−-- all the generated streams are then evaluated concurrently, and the results
169−-- are combined.
163+-- 'parEval' evaluates a stream as a whole asynchronously with respect to
164+-- the consumer of the stream. A worker thread evaluates multiple elements of
165+-- the stream ahead of time and buffers the results; the consumer of the stream
166+-- runs in another thread consuming the elements from the buffer, thus
167+-- decoupling the production and consumption of the stream. 'parEval' can be
168+-- used to run different stages of a pipeline concurrently.
169+--
170+-- 'parConcatMap' is used to evaluate multiple actions in a stream concurrently
171+-- with respect to each other or to evaluate multiple streams concurrently and
172+-- combine the results. A stream generator function is mapped to the input
173+-- stream and all the generated streams are then evaluated concurrently, and
174+-- the results are combined.
170175--
171176-- 'parConcatIterate' is like 'parConcatMap' but iterates a stream generator
172177-- function recursively over the stream. This can be used to traverse trees or
src/Streamly/Internal/Data/Stream/Concurrent.hs+17−9
@@ -147,15 +147,23 @@ parEvalD modifier m = D.Stream step Nothing
147147 D.Stop -> D.Stop
148148-}
149149
150−-- | Evaluate a stream asynchronously. In a serial stream, each element of the
151−-- stream is generated as it is demanded by the consumer. `parEval` evaluates
152−-- multiple elements of the stream ahead of time and serves the results from a
153−-- buffer.
154−--
155−-- Note that the evaluation requires only one thread as only one stream needs
156−-- to be evaluated. Therefore, the concurrency options that are relevant to
157−-- multiple streams won't apply here e.g. maxThreads, eager, interleaved,
158−-- ordered, stopWhen options won't have any effect.
150+-- | 'parEval' evaluates a stream as a whole asynchronously with respect to
151+-- the consumer of the stream. A worker thread evaluates multiple elements of
152+-- the stream ahead of time and buffers the results; the consumer of the stream
153+-- runs in another thread consuming the elements from the buffer, thus
154+-- decoupling the production and consumption of the stream. 'parEval' can be
155+-- used to run different stages of a pipeline concurrently.
156+--
157+-- It is important to note that 'parEval' does not evaluate individual actions
158+-- in the stream concurrently with respect to each other, it merely evaluates
159+-- the stream serially but in a different thread than the consumer thread,
160+-- thus the consumer and producer can run concurrently. See 'parMapM' and
161+-- 'parSequence' to evaluate actions in the stream concurrently.
162+--
163+-- The evaluation requires only one thread as only one stream needs to be
164+-- evaluated. Therefore, the concurrency options that are relevant to multiple
165+-- streams do not apply here e.g. maxThreads, eager, interleaved, ordered,
166+-- stopWhen options do not have any effect on 'parEval'.
159167--
160168-- Useful idioms:
161169--