[erlang-patches] [erlang-questions] max timeout

Per Hedeland per@REDACTED
Sun Aug 24 21:25:44 CEST 2008


"Hynek Vychodil" <vychodil.hynek@REDACTED> wrote:
>
>          {ok, _} = send_after(Time, Ref),

>> It should be much more simpler to do it without modify timer_server:
>>
>> sleep(Time) ->
>>     case whereis(timer_server) of
>>        undefined -> receive after Time -> ok end;
>>        _ ->
>>           Ref = make_ref(),
>>           send_after(Time, Ref),
>>           receive Ref -> ok end
>>     end.

Matter of taste perhaps, whether you prefer the absolute minimum of
change vs regularity of implementation. One thing that often falls out
of the latter is consistency in API, such that you don't end up with one
API function doing a badmatch crash on erroneous input, while all the
others return {error, badarg}. And of course one could ask why create an
unneeded ref, or why require two messages from the server when you only
need one, but that's more in the nitpicking area.

--Per Hedeland



More information about the erlang-patches mailing list