如何命名工人?

时间:2017-09-06 12:27:26

标签: phoenix-framework

我厌倦了使用GenServer作为工人:

defmodule CSVServer do
    use GenServer


    def start_link(_opts \\ []) do
        GenServer.start_link(__MODULE__, %{}, name: __MODULE__)
    end


    def process!(csvs_params), do: GenServer.call(__MODULE__, %{csvs_params: csvs_params})

    def handle_call(%{csvs_params: csvs_params}, _from, state) do

    ...

    end

在我的应用程序中:

def start(_type, _args) do
    import Supervisor.Spec, warn: false

    children = [
      # Start the endpoint when the application starts
      supervisor(MyApp.Endpoint, []),

      # Start the Ecto repository
      supervisor(MyApp.Repo, []),

      worker(CSVServer, [], name: "CSVServer"),
    ]

问题是,我是否必须明确指定工人?于:

worker(CSVServer, [], name: "CSVServer"),

它已经在GenServer命名为:

GenServer.start_link(__MODULE__, %{}, name: __MODULE__)

修改

在生成的myapp.ex中,我可以看到:

# Here you could define other workers and supervisors as children
# worker(MyApp.SomeWorker, [], name: SomeWorker),

0 个答案:

没有答案