Skip to content

Commit 396b1e6

Browse files
author
José Valim
committed
Make the exit conditions for GenServer/GenEvent/Supervisor clear
1 parent 9c549b3 commit 396b1e6

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

lib/elixir/lib/gen_event.ex

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,10 @@ defmodule GenEvent do
227227
returns `{:ok, pid}`, where pid is the pid of the server. If there already
228228
exists a process with the specified server name, the function returns
229229
`{:error, {:already_started, pid}}` with the pid of that process.
230+
231+
Note that a `GenEvent` started with `start_link/1` is linked to the
232+
parent process and will exit not only on crashes but also if the parent
233+
process exits with `:normal` reason.
230234
"""
231235
@spec start_link(options) :: on_start
232236
def start_link(options \\ []) when is_list(options) do

lib/elixir/lib/gen_server.ex

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,11 @@ defmodule GenServer do
269269
passing the given `args` to initialize it. To ensure a synchronized start-up
270270
procedure, this function does not return until `init/1` has returned.
271271
272+
Note that a `GenServer` started with `start_link/3` is linked to the
273+
parent process and will exit in case of crashes. The GenServer will also
274+
exit due to the `:normal` reasons in case it is configured to trap exits
275+
in the `init/1` callback.
276+
272277
## Options
273278
274279
The `:name` option is used for name registration as described in the module

lib/elixir/lib/supervisor.ex

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,10 @@ defmodule Supervisor do
195195
an erroneous value, the supervisor will first terminate all already
196196
started child processes with reason `:shutdown` and then terminate
197197
itself and return `{:error, {:shutdown, reason}}`.
198+
199+
Note that the `Supervisor` is linked to the parent process
200+
and will exit not only on crashes but also if the parent process
201+
exits with `:normal` reason.
198202
"""
199203
@spec start_link([tuple], options) :: on_start
200204
def start_link(children, options) when is_list(children) do

0 commit comments

Comments
 (0)