Hi, I new to elixir and after reading a few pages of getting started docs (I’m still reading) I’ve found this tutorial by José Valim .
But, when I reach this part of the tutorial:
The last step is to add a function named
shoot/1
to thePortal
module that receives a color and spawns a new door as part of the supervision tree:
@doc """
Shoots a new door with the given `color`.
"""
def shoot(color) do
Supervisor.start_child(Portal.Supervisor, [color])
end
and I try to call “shoot” function from iex, I get:
(ArgumentError) The module Portal.Door was given as a child to a supervisor
but it does not implement child_spec/1.
Then I’ve tried to implement this way (I’m not so sure that it’s correct)
def child_spec(opts)do
%{
id: Portal.Door,
start: {Portal.Door, :start_link,[opts]},
type: :worker,
restart: :permanent,
shutdown: 500
}
end
My code compiles, but when I try to call Poortal.shoot(:orange) I get:
{:error,
{:EXIT,
{:undef,
[
{Portal.Door, :start_link, [, :orange], },
{:supervisor, :do_start_child_i, 3, [file: ‘supervisor.erl’, line: 379]},
{:supervisor, :handle_call, 3, [file: ‘supervisor.erl’, line: 404]},
{:gen_server, :try_handle_call, 4, [file: ‘gen_server.erl’, line: 661]},
{:gen_server, :handle_msg, 6, [file: ‘gen_server.erl’, line: 690]},
{:proc_lib, :init_p_do_apply, 3, [file: ‘proc_lib.erl’, line: 249]}
]}}}
That’s my first tutorial using elixir, so, sorry if it’s some really newbie mistake.