ensure_started
Vladimir Sekissov
svg@REDACTED
Mon Mar 24 16:12:18 CET 2003
Good day,
cpressey> I guess the lesson to take from this is that it's good coding style to
cpressey> always use a finite timeout when waiting for a reply from something you're
cpressey> not linked to, because that reply simply may never show up no matter how
cpressey> carefully you code the server... ?
I usually use erlang:monitor/2 in such cases. You don't need to use
timeout with it if you shure that process can only answer or die (no
hungs). Small example from code I use with mdisp:
%% We are implementing synchronous call to mdisp process,
%% it answers with its Pid and after with actual Result
disp_call(Name, Key, Args) ->
mdisp_tt:send(Name, Key, {self(), continue, Args}),
rec_answer(Key).
rec_answer(Key) ->
receive
{Key, iam, Pid} ->
Ref = erlang:monitor(process, Pid),
receive
{'DOWN', Ref, _, _, Reson} ->
exit(Reson);
{Key, Answer} ->
erlang:demonitor(Ref),
Answer
end
after 500 ->
{error, {nothread, Key}}
end.
Best Regards,
Vladimir Sekissov
More information about the erlang-questions
mailing list