after idle [list command1 arg1 arg2]
after idle [list command2 arg3 arg4]
Can I be sure that command1 will be run before command2?
Also, I am guessing there is no (automatic) way to cache idle commands
i.e. I would like to be able to schedule the same command multiple times
(before the event loop is re-entered), and then have the command run
only once. I thought I'd knock up a small package that would cache
scheduled idle events - would this be useful to anyone?
Thanks.
--
Mark G. Saye
markgsaye @ yahoo.com
it seems to me that Tcl_DoWhenIdle() appends the event
handlers in a linked list of "IdleHandler" structures (in
"tclTimer.c"), so the order should be preserved.
About the package: I think it would be useful to have it
on the Wiki. Maybe with transparent support to execute the
scripts in another interpreter or thread... Support for
priority between scripts could be useful, too... or not?
Ciao,
Marco
--
"Yo, check the diagonal"
Rage Against the Machine - "Freedom"
You mean like
proc after_once {script} {
catch {after cancel $script}
after idle $script
}
Like that?
Yes. Like that. Simple. Can't believe I overlooked the 'after cancel
script' bit. I almost always use the id returned from after command for
that sort of thing. In fact, you don't even need the catch in your code:
proc idle {command} {
after cancel $command
after idle $command
}
which implicitly returns the after id.
To allow for multiple args (like the idle command does), and with an
explicit return (for readability):
proc idle {args} {
set command [eval concat $args]
after cancel $command
return [after idle $command]
}
or even:
proc idle {args} {
eval after cancel $args
return [eval after idle $args]
}
Thanks, Darren.
Mark /
For this purpose I do this:
set after ""
proc display {w} \
{
variable after
if {$after != ""} { after cancel $after }
set after [after idle [namespace code [list _display $w]]]
}
proc _display {w} \
{
variable after
set after ""
...
}
This lets a chance to complete the update of the whole widget before
displaying the changes.
ulis