[erlang-questions] Re: supervisors

Wes James comptekki@REDACTED
Fri Apr 1 20:32:34 CEST 2011


I go this figured out.  I tried to add

register(name(?MODULE, Name), self()),

in the supervisor init() -> but it failed.  I looked back in the supervisor docs

http://www.erlang.org/doc/man/supervisor.html

and found:

If SupName={local,Name} the supervisor is registered locally as Name
using register/2. If SupName={global,Name} the supervisor is
registered globally as Name using global:register_name/2. If no name
is provided, the supervisor is not registered.

so I change

start_link(Name) ->
	supervisor:start_link({local, ?MODULE}, ?MODULE, Name).

to

start_link(Name) ->
	supervisor:start_link({local, name(?MODULE,Name)}, ?MODULE, Name).

name() is a fun to combine ?MODULE ++ "-" ++ Name

it now all it works to run eapp_sup:start_a(a_sup,a2). and it get's
registered to a_sup_a2.

-wes



More information about the erlang-questions mailing list