aboutsummaryrefslogtreecommitdiff
path: root/src/eco_proc.erl
blob: c179a2607446207ea5252e3cd8c189f25a6bd249 (plain)
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
-module(eco_proc).
-export([proc/6]).

proc(Watcher, _, _, _, 0, _) ->
	Watcher ! {died, self()};
proc(Watcher, Gets, Puts, Pool, Life, MaxLife) ->
	receive
		{From, stop} ->
			From ! {ok, stopped, self()},
			Watcher ! {stopped, self()},
			{ok, stopped};
		{From, tick} ->
			From ! {self(), tock},
			Watcher ! {tick, self()},
			Pool ! {self(), get, Gets},
			receive
				{ok, get, Gets} ->
					Pool ! {self(), put, Puts},
					receive
						{ok, put, Puts} ->
							proc(Watcher, Gets, Puts, Pool, MaxLife, MaxLife)
					end;
				{error, get, Gets} ->
					proc(Watcher, Gets, Puts, Pool, Life - 1, MaxLife)
			end
	end.