aboutsummaryrefslogtreecommitdiff
path: root/src/eco_time.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/eco_time.erl')
-rw-r--r--src/eco_time.erl30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/eco_time.erl b/src/eco_time.erl
new file mode 100644
index 0000000..587cca5
--- /dev/null
+++ b/src/eco_time.erl
@@ -0,0 +1,30 @@
+-module(eco_time).
+-export([ticker/4]).
+
+ticker(Watcher, Interval, ProcList, Timeout) ->
+ receive
+ {From, stop} ->
+ From ! {ok, stopped},
+ {ok, stopped}
+ after Interval ->
+ handle_tick(self(), ProcList, Timeout),
+ receive
+ {ok, endtick} ->
+ Watcher ! {endtick, self()},
+ ticker(Watcher, Interval, ProcList, Timeout);
+ {error, notock, Proc} ->
+ Watcher ! {error, notock, Proc, self()},
+ {error, notock, Proc}
+ end
+ end.
+
+handle_tick(Ticker, [], _) ->
+ Ticker ! {ok, endtick};
+handle_tick(Ticker, [This | Next], Timeout) ->
+ This ! {self(), tick},
+ receive
+ {This, tock} ->
+ handle_tick(Ticker, Next, Timeout)
+ after Timeout ->
+ Ticker ! {error, notock, This}
+ end.