[erlang-questions] Why have a supervisor behaviour?

Roger Lipscombe <>
Thu May 21 17:49:05 CEST 2015


On 21 May 2015 at 15:58, Roger Lipscombe <> wrote:
> On 21 May 2015 at 15:23, Jesper Louis Andersen
> <> wrote:
>> 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.
>
> But the supervisor's not supposed to _do_ anything, right? It only has
> Mod:init. If you want an ETS table, you should have it owned by the
> supervisor's first child, right?

OK. On thinking about this more, it makes sense: if you've got an ETS
table that every child needs to access, having it owned by the
supervisor might make sense in some scenarios. Gotcha.


More information about the erlang-questions mailing list