SyncTimer - timers synchronized with clock.
package require SyncTimer
::SyncTimer::every interval basetime script ?script ...?
::SyncTimer::cancel id
This package provides commands able to start/stop synchronized timers. Each time a timer is triggered, it executes a user-defined command. Timers are triggered at regular intervals, and are aligned (synchronized) with the system-clock.
[clock]
command).
"1 hour" "20 minutes" "2 minutes 30 seconds"
[clock]
command).
::SyncTimer::every "5 minutes" "00:00:10" ....means that timer will be triggered every 5 minutes, 10 second after clock strikes the "5 minutes" ( i.e at hh:00:10, hh:05:10, hh:10:10, hh:15:10 ... hh:55:10) Note that if you want timer be triggered 10 second *before* clock strikes the ""5 minutes", you should write
::SyncTimer::every "5 minutes" "00:04:50" ....( i.e at hh:04:50, hh:09:50, hh:14:50 ... hh:59:50)
[after]
command).
The SyncTimer::every command returns an identifier that can be used later to cancel the timer.
set SyncTimer::clockTuning $newValue ; # 0 <= newValue <= 999are supported for compatibility, but they have no effect.
Just a simple echo of current time, followed by a msg
proc myCmd {msg} { puts -nonewline "[clock format [clock seconds] -format "%Y-%m-%d %T"]" puts " $msg" } set t1 [SyncTimer::every "10 secs" "00:00:00" {myCmd "Timer-One - every 10 secs"}] set t2 [SyncTimer::every "15 secs" "00:00:00" {myCmd "Timer-Two - every 15 secs"}] set t1a [SyncTimer::every "15 secs" "00:00:02" {myCmd "every 15 secs (+2)"}] # ... let them run for some minutes ... SyncTimer::cancel $t2 SyncTimer::cancel $t1a SyncTimer::cancel $t1
[after]
command )
[clock milliseconds]
command (new in Tcl 8.5) for a
simpler and better synchronization.