Skip to content

Commit f8c787f

Browse files
authored
Merge pull request #24 from wojtekmach/wm-child-spec
Use :name in child spec as child ID. Fixed __MODULE__ string interpolation in name.
2 parents 3163843 + 0af4926 commit f8c787f

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

lib/meilisearch.ex

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,16 @@ defmodule Meilisearch do
7878

7979
use GenServer
8080

81-
defp to_name(name), do: :"__MODULE__:#{name}"
81+
def child_spec(opts) do
82+
name = Keyword.fetch!(opts, :name)
83+
84+
%{
85+
id: name,
86+
start: {__MODULE__, :start_link, [opts]}
87+
}
88+
end
89+
90+
defp to_name(name), do: :"#{inspect(__MODULE__)}:#{name}"
8291

8392
@spec start_link(atom(),
8493
endpoint: String.t(),
@@ -91,9 +100,8 @@ defmodule Meilisearch do
91100
do: start_link([name: name] ++ opts)
92101

93102
def start_link(opts) when is_list(opts) do
94-
with {:ok, name} <- Keyword.fetch(opts, :name) do
95-
GenServer.start_link(__MODULE__, opts, name: to_name(name))
96-
end
103+
name = Keyword.fetch!(opts, :name)
104+
GenServer.start_link(__MODULE__, opts, name: to_name(name))
97105
end
98106

99107
@impl true

0 commit comments

Comments
 (0)