[erlang-questions] Why have a supervisor behaviour?
Jesper Louis Andersen
Thu May 21 16:23:53 CEST 2015
On Thu, May 21, 2015 at 4:11 PM, Roger Lipscombe <roger@REDACTED>
> I find myself writing a custom supervisor (because I need restarts to
> be delayed), and I find myself wondering why OTP has a supervisor
Another way around this is to let the supervisor just start the server and
then let the server itself handle the delay by querying a delay_manager, or
> That is: why does it require us to provide the Module:init/1 function?
> Surely we could just pass the restart strategy, child specs, etc. to
> supervisor:start_link directly?
Because init/1 runs in the context of the supervisor process, not the
invoker of start_link/1. If you create an ETS table in the supervisor, for
instance, its protection is relative to who created it. And so is its
lifetime. You can't easily do that if you pass in the data in start_link/1,
since you would have to pass a fun anyway.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the erlang-questions