-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_trace2.erl
More file actions
40 lines (36 loc) · 1.3 KB
/
Copy pathtest_trace2.erl
File metadata and controls
40 lines (36 loc) · 1.3 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
34
35
36
37
38
39
40
-module(test_trace2).
-compile(export_all).
test() ->
Term = wf_term:par([
wf_term:task(x, #{
function => fun(Ctx) ->
io:format("Task X running~n"),
{ok, Ctx#{x_ran => true}}
end
}),
wf_term:task(y, #{
function => fun(Ctx) ->
io:format("Task Y running~n"),
{ok, Ctx#{y_ran => true}}
end
})
]),
{ok, {Bytecode, Metadata}} = wf_compile:compile(Term),
ExecState0 = wf_exec:new({Bytecode, Metadata}),
io:format("=== Step by step ===~n"),
ExecState1 = step_n(ExecState0, 10),
io:format("=== Final State ===~n"),
io:format("Status: ~p~n", [ExecState1#exec_state.status]),
io:format("IP: ~p~n", [ExecState1#exec_state.ip]),
io:format("Tokens: ~p~n", [[{TID, T#token.status, T#token.ip} || {TID, T} <- maps:to_list(ExecState1#exec_state.tokens)]]).
step_n(ExecState, 0) -> ExecState;
step_n(ExecState, N) ->
case wf_exec:step(ExecState, deterministic) of
{running, ExecState1} -> step_n(ExecState1, N-1);
{done, ExecState1} ->
io:format("Done at step ~p~n", [10-N]),
ExecState1;
{blocked, ExecState1} ->
io:format("Blocked at step ~p~n", [10-N]),
ExecState1
end.