just to do job and and send result back to parent.
call_controller_action(Adapter, AdapterInfo, RequestContext) ->
lager:notice("Calling Controller Adapter ~s", [Adapter]),
process_flag(trap_exit, true),
Ref = make_ref(),
CHandlerPid = self(),
_N = spawn_link(fun() ->
R = Adapter:action(AdapterInfo, RequestContext),
CHandlerPid !{msg,Ref, R}
end),
receive_controller_response(Ref).
-spec(receive_controller_response(reference()) ->any()).
receive_controller_response(Ref) ->
receive
{msg, Ref, R} ->
lager:notice("Response ~p", [R]),
R;
{'EXIT',_From, normal} ->
%%lager:error("2 Controller Process Exited normal ~p but response not yet receive", [From]),
receive_controller_response(Ref);
{'EXIT',From, Reason} ->
lager:error("Controller Process Exited ~p ~p", [From, Reason]),
{output, "Process Error see console.log for details\n"}
end.
Is there some reason for that?
It is synchronous, so it could be replaced with:
call_controller_action(Adapter, AdapterInfo, RequestContext) ->
Adapter:action(AdapterInfo, RequestContext).
Or maybe surround the call in try ... catch.
If there is no reason for spawning new process, than I'll make a pull request,
if there is - I would really like to know :)