Update GH URI
[cellular-automata.git] / life_god.erl
... / ...
CommitLineData
1-module(life_god).
2-behaviour(supervisor).
3
4
5%% API
6-export([start_link/2]).
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
20start_link(X, CellData) ->
21 supervisor:start_link({local, ?MODULE}, ?MODULE, [X, CellData]).
22
23
24%% ============================================================================
25%% Callbacks
26%% ============================================================================
27
28init([X, 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, CellNames]),
33 Children = Cells ++ [Time],
34 {ok, {RestartStrategy, Children}}.
35
36
37spec_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.030831 seconds and 5 git commands to generate.