Skip to content

Commit 9188452

Browse files
update documentation
1 parent db1a477 commit 9188452

File tree

1 file changed

+12
-19
lines changed

1 file changed

+12
-19
lines changed

lib/gen_stage.ex

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -204,21 +204,14 @@ defmodule GenStage do
204204
At this point, the producer has not been asked for more events yet since the demand
205205
didn't go below `:min_demand` yet. When the producer produces the next batch of
206206
`100` events, the consumer will process `50` events and the demand reaches the
207-
minimum of `750`. The consumer sends `250` demand upstream (which is up to `:max_demand`).
208-
of `250` to reach `:min_demand` again, and then consume the `50` events remaining.
209-
`c:handle_demand/2` will be called on the producer with a demand of `250`.
210-
211-
In the example above, B is a `:producer_consumer` and therefore
212-
acts as a buffer. Getting the proper demand values in B is
213-
important: making the buffer too small may make the whole pipeline
214-
slower, making the buffer too big may unnecessarily consume
215-
memory.
216-
217-
When such values are applied to the stages above, it is easy
218-
to see the producer works in batches. The producer A ends-up
219-
emitting batches of 50 items which will take approximately
220-
50 seconds to be consumed by C, which will then request another
221-
batch of 50 items.
207+
minimum of `750`. The consumer sends `250` demand upstream to reach `:max_demand` again,
208+
and then consumes the `50` events remaining. `c:handle_demand/2` will be called on the
209+
producer with a demand of `250`.
210+
211+
In the earlier [example](#module-example), B is a `:producer_consumer` and therefore
212+
acts as a buffer. Getting the proper demand values in B is important: making the buffer
213+
too small may make the whole pipeline slower, making the buffer too big may unnecessarily
214+
consume memory.
222215
223216
### `init` and `:subscribe_to`
224217
@@ -1371,11 +1364,11 @@ defmodule GenStage do
13711364
In case of exits, the same reason is used to exit the consumer.
13721365
In case of cancellations, the reason is wrapped in a `:cancel` tuple.
13731366
1374-
* `:min_demand` - the minimum demand for this subscription. See the module
1375-
documentation for more information.
1367+
* `:min_demand` - the minimum demand for this subscription. Defaults to `max_demand / 2`.
1368+
See the module documentation for more information.
13761369
1377-
* `:max_demand` - the maximum demand for this subscription. See the module
1378-
documentation for more information.
1370+
* `:max_demand` - the maximum demand for this subscription. Defaults to `1000`.
1371+
See the module documentation for more information.
13791372
13801373
Any other option is sent to the producer stage. This may be used by
13811374
dispatchers for custom configuration. For example, if a producer uses

0 commit comments

Comments
 (0)