Merge pull request 'Spawned processes inherit the parent's flow identity' (#3) from uw-inherit-flow into master
Reviewed-on: #3
This commit was merged in pull request #3.
This commit is contained in:
+18
-5
@@ -7,6 +7,7 @@
|
|||||||
]).
|
]).
|
||||||
|
|
||||||
-export([ note_flow/1
|
-export([ note_flow/1
|
||||||
|
, get_flow/0
|
||||||
, ct_log/2 %% ct_log(Fmt, Args)
|
, ct_log/2 %% ct_log(Fmt, Args)
|
||||||
, ct_log/3 %% ct_log(Flow, Fmt, Args)
|
, ct_log/3 %% ct_log(Flow, Fmt, Args)
|
||||||
, timestamp/0 ]).
|
, timestamp/0 ]).
|
||||||
@@ -44,9 +45,14 @@ get(Key, Default) ->
|
|||||||
erase(Key) ->
|
erase(Key) ->
|
||||||
gm_ctflow_state:erase(Key).
|
gm_ctflow_state:erase(Key).
|
||||||
|
|
||||||
|
-spec note_flow(flow()) -> 'ok'.
|
||||||
note_flow(Flow) ->
|
note_flow(Flow) ->
|
||||||
erlang:put({?MODULE, flow}, Flow).
|
erlang:put({?MODULE, flow}, Flow),
|
||||||
|
ok.
|
||||||
|
|
||||||
|
-spec get_flow() -> flow() | 'undefined'.
|
||||||
|
get_flow() ->
|
||||||
|
erlang:get({?MODULE, flow}).
|
||||||
|
|
||||||
ct_log(Fmt, Args) ->
|
ct_log(Fmt, Args) ->
|
||||||
ct_log(erlang:get({?MODULE, flow}), Fmt, Args).
|
ct_log(erlang:get({?MODULE, flow}), Fmt, Args).
|
||||||
@@ -136,13 +142,20 @@ timestamp() ->
|
|||||||
[Year,Month,Day,Hour,Min,Sec,MilliSec])).
|
[Year,Month,Day,Hour,Min,Sec,MilliSec])).
|
||||||
|
|
||||||
spawn(F) ->
|
spawn(F) ->
|
||||||
|
Flow = get_flow(),
|
||||||
proc_lib:spawn(fun() ->
|
proc_lib:spawn(fun() ->
|
||||||
|
maybe_inherit_flow(Flow),
|
||||||
ct_util:mark_process(),
|
ct_util:mark_process(),
|
||||||
F()
|
F()
|
||||||
end).
|
end).
|
||||||
|
|
||||||
spawn_opt(F, Opts) ->
|
spawn_opt(F, Opts) ->
|
||||||
|
Flow = get_flow(),
|
||||||
proc_lib:spawn_opt(fun() ->
|
proc_lib:spawn_opt(fun() ->
|
||||||
ct_util:mark_process(),
|
maybe_inherit_flow(Flow),
|
||||||
F()
|
ct_util:mark_process(),
|
||||||
end, Opts).
|
F()
|
||||||
|
end, Opts).
|
||||||
|
|
||||||
|
maybe_inherit_flow(undefined) -> ok;
|
||||||
|
maybe_inherit_flow(Flow) -> note_flow(Flow).
|
||||||
|
|||||||
Reference in New Issue
Block a user