[erlang-questions] extended timer module to handle absolute time-of-day timers

Serge Aleynikov <>
Tue Jan 13 05:45:00 CET 2009


I extended the timer module to handle absolute time specifications.

With this implementation it's possible to have messages sent on given 
days of week at a certain time of day.  Five new functions are added:
     apply_at_local_time/4, send_at_local_time/3, exit_at_local_time/3,
     apply_daily_at_local_time/5, send_daily_at_local_time/4.


Example1: Send a shutdown message to Pid at 23:00:00 every Friday and 
Sunday.
     timer:send_daily_at_local_time([fri,sun], {23,0,0}, Pid, shutdown).

Example2: Send a restart message to Pid at "6:00:00":
     timer:send_at_local_time({6,0,0}, Pid, restart).

Legacy timer_server's functionality is not affected.

The rationale behind this extension is that I frequently needed 
functionality to schedule some "cron-like" recurrent activities, and was 
always relying either on cron+erl_call or coding that activity with help 
of timer:send_after/3 or timer:send_interval/2.  As I finally got sick 
of dealing with shortcomings of the timer module, I put together this 
extension.

Let me know if you also find it useful, and in such case perhaps we can 
get it included in the OTP.

Serge
-------------- next part --------------
A non-text attachment was scrubbed...
Name: timer.erl
Type: text/x-erlang
Size: 15216 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20090112/b6e8fd89/attachment.bin>


More information about the erlang-questions mailing list