2
在Elixir's intro to GenServer,客戶端API開始與:ok
參數Elixir的GenServer示例中的ok init參數有什麼意義?
def start_link(opts \\ []) do
GenServer.start_link(__MODULE__, :ok, opts)
end
,並且服務器的init
功能服務器需要它的參數是:ok
def init(:ok) do
{:ok, HashDict.new}
end
什麼是傳球和驗證:ok
點?如果我們忽略這一點,它會有什麼不同嗎,而不是寫下類似的東西
def start_link(opts \\ []) do
GenServer.start_link(__MODULE__, nil, opts)
end
def init(_) do
{:ok, HashDict.new}
end
?
我不認爲它很重要的測試,如果你使用仍然可以通過':ok'或'nil'。通過':ok'並使用'init(:ok)'可能只是通過模式匹配進行的附加檢查 – AbM