| View previous topic :: View next topic |
| Author |
Message |
sKy Op

Joined: 14 Apr 2005 Posts: 194 Location: Germany
|
Posted: Wed Jul 18, 2007 1:26 pm Post subject: How to let an utimer know it`s own utimer id? |
|
|
| Code: |
proc lremove { list string } {
return [lsearch -all -inline -not -exact $listname $string]
} |
This sets the timers.
| Code: |
set timer 0
foreach element $list_of_ tasks {
set timer [expr $timer + 5]
set id [utimer $timer [list $element]]
lappend ::list_with_timerids $id
} |
This code is used in case of I want to kill the remaining utimers.
| Code: |
foreach id $::list_with_timerids {
killutimer $id
}
|
The problem is that if the utimer has already been executed then it would throw an error invalid timerid. Sure I could use catch, but I don`t want to use catch.
I don`t want to use catch because some other utimer (set by another script) could have that id now and I could eventually kill the wrong timer because he has the same name.
The problem is set id [utimer $timer [list $element]]. I would like to expand the [list ...] section with a command to remove the utimer from $::list_with_timerids. With set :list_with_timerids [lremove $:list_with_timerids $id].
But this isn`t possible because I get the $id just after I did set the utimer. Is there some tricky work around?
As far I know I can not modify a timer/utimer/after after it has been set. Otherwise it would be easy. _________________ socketapi | Code less, create more. |
|
| Back to top |
|
 |
sKy Op

Joined: 14 Apr 2005 Posts: 194 Location: Germany
|
Posted: Fri Aug 24, 2007 6:32 pm Post subject: |
|
|
No one knows? No way? Or is my English to bad to understand what I want to do? _________________ socketapi | Code less, create more. |
|
| Back to top |
|
 |
Alchera Revered One

Joined: 11 Aug 2003 Posts: 3344 Location: Ballarat Victoria, Australia
|
|
| Back to top |
|
 |
user

Joined: 18 Mar 2003 Posts: 1452 Location: Norway
|
Posted: Sat Aug 25, 2007 4:47 pm Post subject: |
|
|
There is no way to know the id at the time you create the code argument (because it doesn't exist yet).
If all the timers run for the same amount of time, your timer will always be the first on the list, which would let you use lrange to remove its id, but if the delay differs, that won't work...
I have the same problem with my socket api - code executed by the server socket needs to know its id, so I made my own "id" that is used to look up the real id. For timers it would be something like this:
| Code: | array set myTimer {}
if {![info exists myTimerID]} {set myTimerID -1}
proc myTimer {delay code} {
global myTimerID myTimer
# The custom id is appended to your code and must be used to unset myTimer(theID) if you kill the timer
set myTimer([incr myTimerID]) [utimer $delay [lappend code $myTimerID]]
set myTimerID
}
proc killMyTimer id {
upvar 0 ::myTimer($id) timer
if {[info exists timer]} {
killutimer $timer
unset timer
}
} |
Use the concept in your script instead of using these procs to avoid adding overhead... or use "utimers" in your "kill remaining" code. _________________ Have you ever read "The Manual"? |
|
| Back to top |
|
 |
|