-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_trace4.erl
More file actions
40 lines (35 loc) · 1.14 KB
/
Copy pathtest_trace4.erl
File metadata and controls
40 lines (35 loc) · 1.14 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_trace4).
-compile(export_all).
test() ->
Term = wf_term:par([
wf_term:task(x, #{
function => fun(Ctx) ->
io:format("Task X running, step ~p~n", [get_step()]),
{ok, Ctx#{x_ran => true}}
end
}),
wf_term:task(y, #{
function => fun(Ctx) ->
io:format("Task Y running, step ~p~n", [get_step()]),
{ok, Ctx#{y_ran => true}}
end
})
]),
{ok, {Bytecode, Metadata}} = wf_compile:compile(Term),
ExecState0 = wf_exec:new({Bytecode, Metadata}),
io:format("Running 10 steps...~n"),
put(step_count, 0),
ExecState1 = run_n(ExecState0, 10),
io:format("~nFinal Status: ~p~n", [wf_exec:is_done(ExecState1)]).
run_n(ExecState, 0) -> ExecState;
run_n(ExecState, N) ->
put(step_count, get(step_count) + 1),
case wf_exec:run(ExecState, 1, deterministic) of
{done, ES} ->
io:format("Done!~n"),
ES;
{yield, ES} ->
io:format("Step ~p: yield~n", [get(step_count)]),
run_n(ES, N-1)
end.
get_step() -> get(step_count).