Skip to content

Commit 1630358

Browse files
alvaromlgjosevalim
authored andcommitted
Added missing code changes on GenStage documentation #210 (#211)
1 parent 9b7be08 commit 1630358

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

lib/gen_stage.ex

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,21 @@ defmodule GenStage do
241241
GenStage.start_link(C, :ok)
242242
GenStage.start_link(C, :ok)
243243
244-
In a supervision tree, this is often done by starting multiple workers:
244+
In a supervision tree, this is often done by starting multiple workers. Typically
245+
we update each `c:start_link/1` call to start a named process:
246+
247+
def start_link(number) do
248+
GenStage.start_link(A, number, name: A)
249+
end
250+
251+
And the same for module `B`:
252+
253+
def start_link(number) do
254+
GenStage.start_link(B, number, name: B)
255+
end
256+
257+
Module `C` does not need to be updated because it won't be subscribed to.
258+
Then we can define our supervision tree like this:
245259
246260
children = [
247261
worker(A, [0]),
@@ -254,9 +268,9 @@ defmodule GenStage do
254268
255269
Supervisor.start_link(children, strategy: :rest_for_one)
256270
257-
Having multiple consumers is often the easiest and simplest way to
258-
leverage concurrency in a GenStage pipeline, especially if events can
259-
be processed out of order.
271+
Having multiple consumers is often the easiest and simplest way to leverage
272+
concurrency in a GenStage pipeline, especially if events can be processed out
273+
of order.
260274
261275
Also note that we set the supervision strategy to `:rest_for_one`. This
262276
is important because if the producer A terminates, all of the other

0 commit comments

Comments
 (0)