Hi all.
I’m not understanding the different forms of calling start_link for Supervisor and GenServer. I’m reading Programming Elixir by Dave Thomas, and I’m working in the section dedicated to OPT. Here’s the relevant code:
supervisor.ex
defmodule Sequence.Supervisor do
use Supervisor
def start_link(initial_number) do
result = {:ok, sup } = Supervisor.start_link(__MODULE__, [initial_number])
start_workers(sup, initial_number)
result
end
def start_workers(sup, initial_number) do
{:ok, stash} = Supervisor.start_child(sup, worker(Sequence.Stash, [initial_number]))
Supervisor.start_child(sup, supervisor(Sequence.SubSupervisor, [stash]))
end
def init(_) do
supervise [], strategy: :one_for_one
end
end
subsupervisor.ex
defmodule Sequence.SubSupervisor do
use Supervisor
def start_link(stash_pid) do
{:ok, _pid} = Supervisor.start_link(__MODULE__, stash_pid)
end
def init(stash_pid) do
child_processes = [ worker(Sequence.Server, [stash_pid]) ]
supervise child_processes, strategy: :one_for_one
end
end
server.ex
def start_link(stash_pid) do
{:ok, _pid} = GenServer.start_link(__MODULE__, stash_pid, name: __MODULE__)
end
Sometimes stash_pid and initial_number are passed inside of a list, and other times they are passed by themselves. I am having trouble distinguishing between which form I should use and when.
Could someone clarify this for me please?


















