Skip to content

Commit 5a97f5f

Browse files
Use the new child supervisor specifications for gen_event example (#262)
1 parent b5d1772 commit 5a97f5f

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

examples/gen_event.exs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ defmodule Broadcaster do
2121
@doc """
2222
Starts the broadcaster.
2323
"""
24-
def start_link() do
24+
def start_link(_args) do
2525
GenStage.start_link(__MODULE__, :ok, name: __MODULE__)
2626
end
2727

@@ -64,7 +64,7 @@ defmodule Consumer do
6464

6565
use GenStage
6666

67-
def start_link() do
67+
def start_link(_args) do
6868
GenStage.start_link(__MODULE__, :ok)
6969
end
7070

@@ -87,27 +87,25 @@ end
8787
defmodule App do
8888
@moduledoc """
8989
Your application entry-point.
90-
91-
For actual applications, start/0 should be start/2.
9290
"""
91+
use Supervisor
9392

94-
def start do
95-
import Supervisor.Spec
96-
93+
@impl true
94+
def init(_arg) do
9795
children = [
98-
worker(Broadcaster, []),
99-
worker(Consumer, [], id: 1),
100-
worker(Consumer, [], id: 2),
101-
worker(Consumer, [], id: 3),
102-
worker(Consumer, [], id: 4)
96+
Supervisor.child_spec({Broadcaster, []}, id: 1),
97+
Supervisor.child_spec({Consumer, []}, id: 2),
98+
Supervisor.child_spec({Consumer, []}, id: 3),
99+
Supervisor.child_spec({Consumer, []}, id: 4),
100+
Supervisor.child_spec({Consumer, []}, id: 5),
103101
]
104102

105103
Supervisor.start_link(children, strategy: :one_for_one)
106104
end
107105
end
108106

109107
# Start the app
110-
App.start
108+
App.init(0)
111109

112110
# Broadcast events
113111
Broadcaster.sync_notify(1)
@@ -117,4 +115,4 @@ Broadcaster.sync_notify(4)
117115
Broadcaster.sync_notify(5)
118116

119117
# Wait for them to be printed
120-
Process.sleep(2000)
118+
Process.sleep(2000)

0 commit comments

Comments
 (0)