I am trying to create a GenEvent process with a specific name (for this question I am going with {:global, :x}
). If I usually create a GenEvent, for example, GenEvent.start_link([name: {:global, :x}])
I can access a GenEvent with this name. It's good. But I also want to create a GenEvent under the supervision tree. To do this, I put the genevent into the Supervision.Spec specification worker
and that when something explodes.
iex(1)> {:ok, sup} = Supervisor.start_link([], strategy: :one_for_one)
{:ok,
iex(2)> Supervisor.start_child(sup, Supervisor.Spec.worker(GenEvent, [name: {:global, :x}], []))
{:error,
{{:EXIT,
{:function_clause,
[{GenEvent, :start_link, [name: {:global, :x}],
[file: 'lib/gen_event.ex', line: 358]},
{:supervisor, :do_start_child, 2, [file: 'supervisor.erl', line: 343]},
{:supervisor, :handle_start_child, 2, [file: 'supervisor.erl', line: 715]},
{:supervisor, :handle_call, 3, [file: 'supervisor.erl', line: 400]},
{:gen_server, :try_handle_call, 4, [file: 'gen_server.erl', line: 629]},
{:gen_server, :handle_msg, 5, [file: 'gen_server.erl', line: 661]},
{:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 239]}]}},
{:child, :undefined, GenEvent, {GenEvent, :start_link, [name: {:global, :x}]},
:permanent, 5000, :worker, :dynamic}}}
What am I doing wrong?