@@ -241,7 +241,21 @@ defmodule GenStage do
241
241
GenStage.start_link(C, :ok)
242
242
GenStage.start_link(C, :ok)
243
243
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:
245
259
246
260
children = [
247
261
worker(A, [0]),
@@ -254,9 +268,9 @@ defmodule GenStage do
254
268
255
269
Supervisor.start_link(children, strategy: :rest_for_one)
256
270
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.
260
274
261
275
Also note that we set the supervision strategy to `:rest_for_one`. This
262
276
is important because if the producer A terminates, all of the other
0 commit comments