OTP: running GenEvent under control named

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 workerand that when something explodes.

iex(1)> {:ok, sup} = Supervisor.start_link([], strategy: :one_for_one)
{:ok, #PID<0.127.0>}
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?

+4
source share
1 answer

(This answer comes from asongein #elixiron irc.freenode.net. Thanks!)

args Supervisor.Spec.worker , . GenEvent.start_link\1 , . , , ( args start_link), , start_link. , worker Supervisor.Spec.worker(GenEvent, [[name: {:global, :x}]], []).

+2

Source: https://habr.com/ru/post/1611053/


All Articles