forked from tegioz/world
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworld_carsup.erl
More file actions
executable file
·29 lines (19 loc) · 840 Bytes
/
world_carsup.erl
File metadata and controls
executable file
·29 lines (19 loc) · 840 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
-module(world_carsup).
-include("world_types.hrl").
-behaviour(supervisor).
-export([start_link/0, init/1]).
-export([createCarrots/1]).
start_link() ->
supervisor:start_link({local, ?MODULE}, ?MODULE, []).
init(_Args) ->
gen_event:notify(eventhandler, {world_carsup, init}),
{ok, {{one_for_one, 100, 1}, []}}.
%-------------------------------------------------------------------------------------
createCarrots(WorldInfo) ->
newCarrot(0, WorldInfo#world_info.carrots, WorldInfo).
newCarrot(Created, Total, WorldInfo) when Created < Total ->
Carrot = {{carrot, Created+1}, {world_carrot, start_link, [WorldInfo]}, permanent, brutal_kill, worker, [world_carrot]},
supervisor:start_child(world_carsup, Carrot),
newCarrot(Created+1, Total, WorldInfo);
newCarrot(_Created, _Total, _WorldInfo) ->
done.