Update GH URI
[cellular-automata.git] / src / life_god.erl
1 -module(life_god).
2 -behaviour(supervisor).
3
4
5 %% API
6 -export([start_link/3]).
7
8 %% Callbacks
9 -export([init/1]).
10
11
12 %% Helper macro for declaring children of supervisor
13 -define(CHILD(Type, I, Args), {I, {I, start_link, Args}, permanent, 5000, Type, [I]}).
14
15
16 %% ============================================================================
17 %% API
18 %% ============================================================================
19
20 start_link(X, Y, CellData) ->
21 supervisor:start_link({local, ?MODULE}, ?MODULE, [X, Y, CellData]).
22
23
24 %% ============================================================================
25 %% Callbacks
26 %% ============================================================================
27
28 init([X, Y, CellData]) ->
29 CellNames = [Name || {_, Name, _} <- CellData],
30 RestartStrategy = {one_for_one, 1000000, 1},
31 Cells = [spec_cell(Datum) || Datum <- CellData],
32 Time = ?CHILD(worker, life_time, [X, Y, CellNames]),
33 Children = Cells ++ [Time],
34 {ok, {RestartStrategy, Children}}.
35
36
37 spec_cell({_, Name, _}=Datum) ->
38 M = life_cell,
39 F = start_link,
40 A = [Datum],
41 {Name, {M, F, A}, permanent, 5000, worker, [M]}.
This page took 0.061882 seconds and 4 git commands to generate.