<div dir="ltr">It should be much more simpler to do it without modify timer_server:<br><br>sleep(Time) -><br>
    case whereis(timer_server) of<br>
       undefined -> receive after Time -> ok end;<br>
       _ -><br>          Ref = make_ref(),<br>          send_after(Time, Ref),<br>          receive Ref -> ok end<br>    end.<br><br><div class="gmail_quote">On Fri, Aug 22, 2008 at 12:11 AM, Per Hedeland <span dir="ltr"><<a href="mailto:per@hedeland.org">per@hedeland.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div class="Ih2E3d">Alpár Jüttner <<a href="mailto:alpar@cs.elte.hu">alpar@cs.elte.hu</a>> wrote:<br>

><br>
>As I recall, someone noted on that thread that timer:sleep() works well<br>
>for arbitrarily large numbers.<br>
<br>
</div>I thought that might have been me:-( - but I see now that I just said<br>
"the timer module" and gave an example using timer:send_after/2, so I<br>
was almost right...<br>
<div class="Ih2E3d"><br>
>Now I looked at the source and found that this is _not_ true. Strangely<br>
>enough, all the functions of the timer modules seem to work correctly<br>
>with large numbers _except_ timer:sleep() which has a definition as<br>
>simple as this:<br>
><br>
>sleep(T) -><br>
>    receive<br>
>    after T -> ok<br>
>    end.<br>
<br>
</div>Ouch. But no-one will ever need to sleep for 50 days or more, right?:-)<br>
<div class="Ih2E3d"><br>
>It might be worth fixing.<br>
<br>
</div>And I guess I half-owe the fix - the problem is (as I discovered...)<br>
that there may be (is) code, um, "out there", that relies on being able<br>
to use timer:sleep/1 without having the timer_server running *or*<br>
getting "auto-started". Below is what I believe to be a backwards-<br>
compatible fix (against R12B-3), but it's pretty ugly - would probably<br>
be better to e.g.  define a new function long_sleep/1 or somesuch for<br>
the "unlimited" case.<br>
<br>
--Per Hedeland<br>
<br>
--- lib/stdlib/src/timer.erl.orig       2007-11-26 19:55:44.000000000 +0100<br>
+++ lib/stdlib/src/timer.erl    2008-08-21 23:00:45.000000000 +0200<br>
@@ -75,9 +75,14 @@<br>
 cancel(BRef) -><br>
     req(cancel, BRef).<br>
<br>
-sleep(T) -><br>
-    receive<br>
-    after T -> ok<br>
+sleep(Time) -><br>
+    case whereis(timer_server) of<br>
+       undefined -><br>
+           receive<br>
+           after Time -> ok<br>
+           end;<br>
+       _ -><br>
+           req(sleep, Time)<br>
     end.<br>
<br>
 %%<br>
@@ -176,6 +181,13 @@<br>
            {reply, {error, badarg}, [], next_timeout()}<br>
     end;<br>
<br>
+handle_call({sleep, Time, Started}, From, Ts) -><br>
+    Req = {apply_after, {Time, {gen_server, reply, [From, ok]}}, Started},<br>
+    case handle_call(Req, From, Ts) of<br>
+        {reply, {ok, _}, _, Timeout} -> {noreply, [], Timeout};<br>
+        Reply                        -> Reply<br>
+    end;<br>
+<br>
 handle_call({cancel, BRef = {_Time, Ref}, _}, _From, Ts)<br>
                                            when is_reference(Ref) -><br>
     delete_ref(BRef),<br>
<div><div></div><div class="Wj3C7c">_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://www.erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://www.erlang.org/mailman/listinfo/erlang-questions</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>--Hynek (Pichi) Vychodil<br>
</div>