Skip to content

Commit f4090c1

Browse files
committed
Merge pull request elixir-lang#710 from toraritte/patch-1
Remove empty parentheses from genserver.markdown
2 parents dd530e4 + 61149e1 commit f4090c1

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

getting-started/mix-otp/genserver.markdown

+6-6
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ defmodule KV.Registry do
5555
@doc """
5656
Starts the registry.
5757
"""
58-
def start_link() do
58+
def start_link do
5959
GenServer.start_link(__MODULE__, :ok, [])
6060
end
6161

@@ -89,7 +89,7 @@ defmodule KV.Registry do
8989
if Map.has_key?(names, name) do
9090
{:noreply, names}
9191
else
92-
{:ok, bucket} = KV.Bucket.start_link()
92+
{:ok, bucket} = KV.Bucket.start_link
9393
{:noreply, Map.put(names, name, bucket)}
9494
end
9595
end
@@ -186,11 +186,11 @@ iex> Process.monitor(pid)
186186
#Reference<0.0.0.551>
187187
iex> Agent.stop(pid)
188188
:ok
189-
iex> flush()
189+
iex> flush
190190
{:DOWN, #Reference<0.0.0.551>, :process, #PID<0.66.0>, :normal}
191191
```
192192

193-
Note `Process.monitor(pid)` returns a unique reference that allows us to match upcoming messages to that monitoring reference. After we stop the agent, we can `flush()` all messages and notice a `:DOWN` message arrived, with the exact reference returned by monitor, notifying that the bucket process exited with reason `:normal`.
193+
Note `Process.monitor(pid)` returns a unique reference that allows us to match upcoming messages to that monitoring reference. After we stop the agent, we can `flush/0` all messages and notice a `:DOWN` message arrived, with the exact reference returned by monitor, notifying that the bucket process exited with reason `:normal`.
194194

195195
Let's reimplement the server callbacks to fix the bug and make the test pass. First, we will modify the GenServer state to two dictionaries: one that contains `name -> pid` and another that holds `ref -> name`. Then we need to monitor the buckets on `handle_cast/2` as well as implement a `handle_info/2` callback to handle the monitoring messages. The full server callbacks implementation is shown below:
196196

@@ -211,7 +211,7 @@ Let's reimplement the server callbacks to fix the bug and make the test pass. Fi
211211
if Map.has_key?(names, name) do
212212
{:noreply, {names, refs}}
213213
else
214-
{:ok, pid} = KV.Bucket.start_link()
214+
{:ok, pid} = KV.Bucket.start_link
215215
ref = Process.monitor(pid)
216216
refs = Map.put(refs, ref, name)
217217
names = Map.put(names, name, pid)
@@ -257,7 +257,7 @@ Links are bi-directional. If you link two process and one of them crashes, the o
257257
Returning to our `handle_cast/2` implementation, you can see the registry is both linking and monitoring the buckets:
258258

259259
```elixir
260-
{:ok, pid} = KV.Bucket.start_link()
260+
{:ok, pid} = KV.Bucket.start_link
261261
ref = Process.monitor(pid)
262262
```
263263

0 commit comments

Comments
 (0)