proc cron {{opt {}}} { set every 1800 if {$opt eq {}} { # Do the work you need every $every seconds puts [clock format [clock seconds]] } after [expr {($every-([clock seconds] % $every))*1000}] cron } cron -init vwait forever
ABU 26-may-2005Here is yet another implementation SyncTimer.Added features:
- Timers can be stopped and restarted
- timers can be kept in sync with system-clock
- timers can be started after a given amount
# example set t1 [SyncTimer::every "1 hour" "00:30:00" {puts "every hour at the half-hour"}] $t1 start
See also the page for every, which shows the evolution of the trivial one-line implementation into a full sibling of after, with valuable discussion along the way.