-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsample_cycle.erl
37 lines (31 loc) · 944 Bytes
/
sample_cycle.erl
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
30
31
32
33
34
35
36
37
-module(sample_cycle).
-behaviour(gen_cycle).
-export([start/1, start/2,
init_cycle/1,
handle_cycle/1,
handle_info/2]).
start(Args) ->
gen_cycle:start_supervised(?MODULE, Args).
start(Name, Args) ->
gen_cycle:start_supervised(Name, ?MODULE, Args).
init_cycle(abort) ->
ignore;
init_cycle([TestProcess, Interval, CallbackReply]) ->
{ok, {Interval, {TestProcess, CallbackReply}}};
init_cycle([TestProcess, Interval]) ->
{ok, {Interval, TestProcess}};
init_cycle([Interval]) ->
{ok, {Interval, noop}}.
handle_cycle({TestProcess, CallbackReply})
when is_pid(TestProcess) ->
TestProcess ! cycle_handled,
CallbackReply;
handle_cycle(TestProcess)
when is_pid(TestProcess) ->
TestProcess ! cycle_handled,
{continue, TestProcess};
handle_cycle(noop) ->
{continue, noop}.
handle_info(Msg, TestProcess) ->
TestProcess ! {info_handled, Msg},
{continue, TestProcess}.