Erlang Supervisor Behavior Gotcha – Worker Init Params
When starting up a behavior like supervisor, the start_link func looks something like:
start_link() ->
supervisor:start_link({local, ?MODULE}, ?MODULE, []).
Which in turn calls the initialization callback:
init(_Args) -> %% do some stuff.
Notice that the initialization callback takes 1 argument event though the params list (the third parameter) is empty in your start_link func.
So, naturally (am I alone in this?) I assumed that when defining a Child Spec for a Supervisor, the {M, F, A} definition would follow the same pattern:
Childspec = {child1,
{child1, start, []},
permanent, brutal_kill, worker, dynamic},
%% ...
But the above definition does not call child1:start/1, where the one parameter is the emtpy list. Instead, the list items are extracted as individual parameters. So {child1, start, [p1, p2, p3]} would call child1:start/3, and {child1, start, []} calls child1:start/0. Just something to look out for if you’re new to erlang and the supervisor behavior like me.















Naked Bunny with a Whip 7:30 pm on August 9, 2010 Permalink
Holy crap, that's been biting me in the butt all afternoon. Thanks for taking a load off my mind!
Double Jogging Stroller 3:33 am on March 4, 2011 Permalink
Excellent! Great article, I already saved it to my favourite,