[erlang-questions] Re: Supervisors as factories *and* registries

Anthony Shipman <>
Tue Mar 23 09:01:32 CET 2010

On Tue, 23 Mar 2010 05:31:49 am Jay Nelson wrote:
> Write a function that is local to your supervisor (this is  
> conceptual, you need to play with return values, errors, restart vs  
> start, and so on):
> launch_child(SupRef, Childspec, ChildKey) ->
>      case supervisor:start_child(Childspec) of
>         {ok, Pid} =
>            ets:insert(?ETS_NAME, {ChildKey, Pid, Childspec}),
>           {ok, Pid};
>         ... other cases ...
>      end.
> Now you can globally access the ets table to lookup a Childspec or  
> Pid using your own key.  Supervisor is no more complicated and works  
> as is.  You need to make sure your launch_child function doesn't  
> crash the supervisor, so try to make it as simple as possible to do  
> what you need.
> jay

But if the child crashes and restarts the pid will be out of date.

Anthony Shipman                    Mamas don't let your babies 
                   grow up to be outsourced.

More information about the erlang-questions mailing list