[erlang-questions] Why have a supervisor behaviour?

Jesper Louis Andersen jesper.louis.andersen@REDACTED
Thu May 21 16:23:53 CEST 2015


On Thu, May 21, 2015 at 4:11 PM, Roger Lipscombe <roger@REDACTED>
wrote:

> I find myself writing a custom supervisor (because I need restarts to
> be delayed[1]), and I find myself wondering why OTP has a supervisor
> behaviour?
>

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
something such.


> 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.



-- 
J.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20150521/7fdbee7f/attachment.htm>


More information about the erlang-questions mailing list