I’m a newcomer to Elixir and trying the tutorial exercises in the official site. I’m up to this page:
https://elixir-lang.org/getting-started/mix-otp/supervisor-and-application.html
I’ve entered the code as requested, but it does not seem to be running the start function in the main module when I run the iex shell (with iex.bat -S mix (the .bat is needed because I’m doing this in Windows)).
PS C:\Users\dan\Documents\Projects\elixir\kv> iex.bat -S mix
Interactive Elixir (1.13.4) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> KV.Registry.create(KV.Registry, “shopping”)
:ok
iex(2)> KV.Registry.lookup(KV.Registry, “shopping”)
** (exit) exited in: GenServer.call(KV.Registry, {:lookup, “shopping”}, 5000)
** (EXIT) no process: the process is not alive or there’s no process currently associated with the given name, possibly because its application isn’t started
(elixir 1.13.4) lib/gen_server.ex:1019: GenServer.call/3
iex(2)>
By the example text on the page, this should have resulted in a response, not an error.
It did start up the application:
iex(2)> Application.start(:kv)
{:error, {:already_started, :kv}}
but not the supervisor process.
When I manually start the supervisor it works:
iex(3)> KV.Supervisor.start_link(name: KV.Supervisor)
{:ok, #PID<0.152.0>}
iex(4)> KV.Registry.create(KV.Registry, “shopping”)
:ok
iex(5)> KV.Registry.lookup(KV.Registry, “shopping”)
{:ok, #PID<0.156.0>}
Also, when I create a test for it:
defmodule KVTest do
use ExUnit.Case
doctest KVtest “spawns registry” do
assert KV.Registry.lookup(KV.Registry, “shopping”) == :errorKV.Registry.create(KV.Registry, "shopping") assert {:ok, bucket} = KV.Registry.lookup(KV.Registry, "shopping") KV.Bucket.put(bucket, "milk", 1) assert KV.Bucket.get(bucket, "milk") == 1
end
end
that test passes, so it’s starting the supervisor then, just not when I invoke the shell.
What am I missing?