Skip to content

Commit d89f53f

Browse files
committed
Merge pull request elixir-lang#717 from toraritte/patch
Remove empty parens and fix a typo
2 parents 612ec1b + 8306d5d commit d89f53f

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

getting-started/mix-otp/ets.markdown

+2-2
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ defmodule KV.Registry do
101101
{:ok, _pid} ->
102102
{:noreply, {names, refs}}
103103
:error ->
104-
{:ok, pid} = KV.Bucket.Supervisor.start_bucket()
104+
{:ok, pid} = KV.Bucket.Supervisor.start_bucket
105105
ref = Process.monitor(pid)
106106
refs = Map.put(refs, ref, name)
107107
:ets.insert(names, {name, pid})
@@ -192,7 +192,7 @@ To fix the failure we just need to make `KV.Registry.create/2` synchronous by us
192192
{:ok, pid} ->
193193
{:reply, pid, {names, refs}}
194194
:error ->
195-
{:ok, pid} = KV.Bucket.Supervisor.start_bucket()
195+
{:ok, pid} = KV.Bucket.Supervisor.start_bucket
196196
ref = Process.monitor(pid)
197197
refs = Map.put(refs, ref, name)
198198
:ets.insert(names, {name, pid})

getting-started/mix-otp/supervisor-and-application.markdown

+5-5
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ We have now successfully defined our supervisor which is automatically started (
220220
Remember however that our `KV.Registry` is both linking and monitoring bucket processes in the `handle_cast/2` callback:
221221

222222
```elixir
223-
{:ok, pid} = KV.Bucket.start_link()
223+
{:ok, pid} = KV.Bucket.start_link
224224
ref = Process.monitor(pid)
225225
```
226226

@@ -267,7 +267,7 @@ defmodule KV.Bucket.Supervisor do
267267
# A simple module attribute that stores the supervisor name
268268
@name KV.Bucket.Supervisor
269269

270-
def start_link() do
270+
def start_link do
271271
Supervisor.start_link(__MODULE__, :ok, name: @name)
272272
end
273273

@@ -296,7 +296,7 @@ Run `iex -S mix` so we can give our new supervisor a try:
296296
```iex
297297
iex> {:ok, _} = KV.Bucket.Supervisor.start_link
298298
{:ok, #PID<0.70.0>}
299-
iex> {:ok, bucket} = KV.Bucket.Supervisor.start_bucket()
299+
iex> {:ok, bucket} = KV.Bucket.Supervisor.start_bucket
300300
{:ok, #PID<0.72.0>}
301301
iex> KV.Bucket.put(bucket, "eggs", 3)
302302
:ok
@@ -311,7 +311,7 @@ Let's change the registry to work with the buckets supervisor by rewriting how b
311311
if Map.has_key?(names, name) do
312312
{:noreply, {names, refs}}
313313
else
314-
{:ok, pid} = KV.Bucket.Supervisor.start_bucket()
314+
{:ok, pid} = KV.Bucket.Supervisor.start_bucket
315315
ref = Process.monitor(pid)
316316
refs = Map.put(refs, ref, name)
317317
names = Map.put(names, name, pid)
@@ -343,7 +343,7 @@ This time we have added a supervisor as child, starting it with no arguments. Re
343343

344344
Since we have added more children to the supervisor, it is also important to evaluate if the `:one_for_one` strategy is still correct. One flaw that shows up right away is the relationship between registry and buckets supervisor. If the registry dies, the buckets supervisor must die too, because once the registry dies all information linking the bucket name to the bucket process is lost. If the buckets supervisor is kept alive, it would be impossible to reach those buckets.
345345

346-
We should consider moving to another supervision strategy like `:one_for_all` or `:rest_for_one`. The `:one_for_all` strategy kills and restarts all children whenever one of the children die. This would suit our case but may be too harsh as there is no need to crash the registry once the bucket supervisor dies since the registry supervises every bucket and would be able to clean itself up. That's when the `:rest_for_one` strategy is handy: `:rest_for_one` will only restart the crashed process along side the rest of tree. Let's rewrite our supervision tree to use it:
346+
We should consider moving to another supervision strategy like `:one_for_all` or `:rest_for_one`. The `:one_for_all` strategy kills and restarts all children whenever one of the children die. This would suit our case but may be too harsh as there is no need to crash the registry once the bucket supervisor dies since the registry supervises every bucket and would be able to clean itself up. That's when the `:rest_for_one` strategy is handy: `:rest_for_one` will only restart the crashed process along side the rest of the tree. Let's rewrite our supervision tree to use it:
347347

348348
```elixir
349349
def init(:ok) do

0 commit comments

Comments
 (0)