on master help sign in
Clarify the docs of 'parEval'
4032b64Harendra Kumar
src/Streamly/Data/Stream/Prelude.hs+20−15
@@ -61,25 +61,28 @@ module Streamly.Data.Stream.Prelude
61 -- | Stream combinators using a concurrent channel.
61 -- | Stream combinators using a concurrent channel.
62
62
63 -- *** Evaluate
63 -- *** 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.
65
66
66 , parEval
67 , parEval
67
68
68 -- *** Generate
69 -- *** Generate
69− -- | Uses a concurrency channel to evaluate multiple actions concurrently.
70+ -- | Generate a stream by evaluating multiple actions concurrently.
70 , parRepeatM
71 , parRepeatM
71 , parReplicateM
72 , parReplicateM
72 , fromCallback
73 , fromCallback
73
74
74 -- *** Map
75 -- *** Map
75− -- | Uses a concurrency channel to evaluate multiple mapped actions
76+ -- | Map actions on a stream such that the mapped actions are evaluated
76− -- concurrently.
77+ -- concurrently with each other.
77
78
78 , parMapM
79 , parMapM
79 , parSequence
80 , parSequence
80
81
81 -- *** Combine two
82 -- *** 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.
83 , parZipWithM
86 , parZipWithM
84 , parZipWith
87 , parZipWith
85 , parMergeByM
88 , parMergeByM
@@ -157,16 +160,18 @@ import Streamly.Internal.Data.Stream.Prelude
157-- 'parConcatMap', and 'parConcatIterate', all concurrency combinators can be
160-- 'parConcatMap', and 'parConcatIterate', all concurrency combinators can be
158-- expressed in terms of these.
161-- expressed in terms of these.
159--
162--
160−-- 'parEval', evaluates a single stream asynchronously, a worker thread runs
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
161−-- the stream and buffers the results, and the consumer of the stream runs in
165+-- the stream ahead of time and buffers the results; the consumer of the stream
162−-- another thread consuming it from the buffer, thus decoupling the production
166+-- runs in another thread consuming the elements from the buffer, thus
163−-- and consumption of the stream. This can be used to run different stages of a
167+-- decoupling the production and consumption of the stream. 'parEval' can be
164−-- pipeline concurrently.
168+-- used to run different stages of a pipeline concurrently.
165−--
169+--
166−-- 'parConcatMap' is used to evaluate multiple streams concurrently and combine
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
167−-- the results. A stream generator function is mapped to the input stream and
172+-- combine the results. A stream generator function is mapped to the input
168−-- all the generated streams are then evaluated concurrently, and the results
173+-- stream and all the generated streams are then evaluated concurrently, and
169−-- are combined.
174+-- the results are combined.
170--
175--
171-- 'parConcatIterate' is like 'parConcatMap' but iterates a stream generator
176-- 'parConcatIterate' is like 'parConcatMap' but iterates a stream generator
172-- function recursively over the stream. This can be used to traverse trees or
177-- 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
147 D.Stop -> D.Stop
147 D.Stop -> D.Stop
148-}
148-}
149
149
150−-- | Evaluate a stream asynchronously. In a serial stream, each element of the
150+-- | 'parEval' evaluates a stream as a whole asynchronously with respect to
151−-- stream is generated as it is demanded by the consumer. `parEval` evaluates
151+-- the consumer of the stream. A worker thread evaluates multiple elements of
152−-- multiple elements of the stream ahead of time and serves the results from a
152+-- the stream ahead of time and buffers the results; the consumer of the stream
153−-- buffer.
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.
154−--
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+--
155−-- Note that the evaluation requires only one thread as only one stream needs
163+-- The evaluation requires only one thread as only one stream needs to be
156−-- to be evaluated. Therefore, the concurrency options that are relevant to
164+-- evaluated. Therefore, the concurrency options that are relevant to multiple
157−-- multiple streams won't apply here e.g. maxThreads, eager, interleaved,
165+-- streams do not apply here e.g. maxThreads, eager, interleaved, ordered,
158−-- ordered, stopWhen options won't have any effect.
166+-- stopWhen options do not have any effect on 'parEval'.
159--
167--
160-- Useful idioms:
168-- Useful idioms:
161--
169--