[erlang-questions] Newbie question: wait until an absolute time

Per Hedeland <>
Fri Feb 1 16:07:04 CET 2008


Alpár Jüttner <> wrote:
>
>Is there any simple way in erlang to wait until a certain absolute time
>or to do something at a specific time in the future ? Namely, I'm
>looking for the absolute counterpart of the functions sleep(),
>send_after(), apply_after() and the 'after TimeOut ->'.
>
>Is it there anything like the opposite of  now_to_universal_time(Now)?
>
>Anyway, is there any easy way to use a larger timeout than it is
>representable by a single integer?

Others have already explained why you probably don't want to do it this
way unless the future is "pretty near", but to answer the question
without regard for that:

1> Now = calendar:local_time().
{{2008,2,1},{15,53,6}}
2> Future = {{2134,5,6},{17,42,0}}.
{{2134,5,6},{17,42,0}}
3> Seconds = calendar:datetime_to_gregorian_seconds(Future) - calendar:datetime_to_gregorian_seconds(Now).
3984342534
4> timer:send_after(1000*Seconds, "Wake up!").
{ok,{5186220328800266,#Ref<0.0.0.40>}}

(The timer module doesn't have the limit of 'receive after'.)

--Per Hedeland



More information about the erlang-questions mailing list