|
Supervisors with no children?: msg#00332lang.erlang.general
There are two ways of adding a worker to a supervisor dynamically; the simple_one_for_one method and the completely dynamic method. When you create a supervisor with a simple_one_for_one restart strategy you include exactly one child specification in the return from the init/1 callback. Calls to supervisor:start_child/2 start new instances of the same child specification. When the supervisor has a restart strategy other than simple_one_for_one calls to supervisor:start_child/2 specify the child specification for the worker which is added to the list of child specifications managed by that supervisor. You must delete this entry when it is no longer needed (i.e. the worker has exited). You might have a gen_server process starting workers: handle_cast(Event, State) -> ... supervisor:start_child(Supervisor, ChildSpec), {noreply, State}. A gen_* process running as a worker would need to signal back to the gen_server to clean up after it died: terminate(_Reason, _StateName, _State) -> gen_server:cast(State#state.parent, {stopped, State#state.supref}). So the gen_server can clean up the supervisor: handle_cast({stopped, SupRef}, State) -> supervisor:delete_child(State#state.sup, SupRef), {noreply, State}. One thing I found I wanted to do but was unable to was to start a supervisor with an empty list of child specifications. If we can add and delete the child specifications why not be able to start the supervisor with no children to begin with? -Vance |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: New supervisor restart strategy: 00332, Chandrashekhar Mullaparthi |
|---|---|
| Next by Date: | Re: ets concurrency: 00332, Bengt Kleberg (AL/EAB) |
| Previous by Thread: | Re: New supervisor restart strategyi: 00332, Vance Shipley |
| Next by Thread: | Distribution problems: 00332, Rocio Lopez |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |