-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_trace7.erl
More file actions
33 lines (29 loc) · 1.21 KB
/
Copy pathtest_trace7.erl
File metadata and controls
33 lines (29 loc) · 1.21 KB
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
-module(test_trace7).
-compile(export_all).
test() ->
Term = wf_term:par([
wf_term:task(x, #{function => fun(Ctx) -> io:format('Task X~n'), {ok, Ctx#{x_ran => true}} end}),
wf_term:task(y, #{function => fun(Ctx) -> io:format('Task Y~n'), {ok, Ctx#{y_ran => true}} end})
]),
{ok, {Bytecode, Metadata}} = wf_compile:compile(Term),
ExecState0 = wf_exec:new({Bytecode, Metadata}),
%% Run 5 steps
run_n(ExecState0, 5).
run_n(ES, 0) -> ok;
run_n(ES, N) ->
io:format('~n--- Step ~p ---~n', [6-N]),
TokenCount = maps:size(ES#exec_state.tokens),
io:format('Tokens: ~p~n', [TokenCount]),
ActiveCount = length([T || T <- maps:values(ES#exec_state.tokens), T#token.status =:= active]),
io:format('Active: ~p~n', [ActiveCount]),
Current = ES#exec_state.current_token,
Token = maps:get(Current, ES#exec_state.tokens),
io:format('Current: status=~p, ip=~p~n', [Token#token.status, Token#token.ip]),
case wf_exec:run(ES, 1, deterministic) of
{done, Final} ->
io:format('DONE!~n'),
io:format('FinalCtx: ~p~n', [wf_exec:get_ctx(Final)]);
{yield, Next} ->
io:format('Yielded~n'),
run_n(Next, N-1)
end.