Re: sleep in tcl



yusuke wrote:
You can't rewrite this like the following.
# sample4
first_proc
after 2000 second_proc
after 2000 third_proc

As Allan writes, you should separate each section of continuous
execution into a separate proc, and have each proc schedule the
following proc to execute. If you have a lot of local variables for
your in-linwed proc, then you should probably make a namespace for
your sequence of small procs.

set ::stone 0
after 2000 {second_proc; set ::stone 1}
if {$::stone == 0} {vwait ::stone}
set ::stone 0
after 2000 {third_proc; set ::stone 1}
if {$::stone == 0} {vwait ::stone}

Again, don't use one continuous flow-through proc with vwait.

If you want to set a global variable, it would be useful to use a sort
of "semaphore" to prevent multiple proc streams from executing in
parallel.

Let's say you want to cancel any current processing sequence when a
new request comes in:

set ::procID {}
proc proc1 {args} {
global procID ;# or use a namespace var
after cancel $procID
blah blah
set procID [after 2000 {proc2 arg yew mints}]
}
proc proc2 {a y m} {
global procID
after cancel $procID
foo bar
set procID [after 4000 [list proc3 $a $y $e]]
}
proc proc3 {args} {
global procID
after cancel $procID
set procID {}
finalize
}

Alternatively, let's say tou want to reject new requests when a
processing stream is in progress. We will assume that a request that
hasn't completed in 10 seconds has failed, so a failure will not lock
things permanently.

set procTime 0
proc proc1 {args} {
global procTime ;# or a namespace variable
set now [clock seconds]
if { $procTime > $now - 10 } { return }
set procTime $now
...
after 2000 {proc 2 xx yy zz}
}
proc proc1 {args} {
....
after 4000 {proc 3 xx yy zz}
}
proc proc3 {args} {
...
set ::procTime 0
}

(Hope there aren't too many typos.)

Donald Arseneau asnd@xxxxxxxxx
.



Relevant Pages

  • trick question
    ... proc has any input parameters then it will display Proc ... @ProcId refers to the ID of a stored procedure in my user ... You need to loop through it. ... >will be at least one optional parameter. ...
    (microsoft.public.sqlserver.programming)
  • Re: NRE committed: PLEASE TEST
    ... be a proc, and hence you could pass in arguments and have them update ... so you give an argument to the coroutine and it pops out as the ... that a design decision, or a practical limitation? ... foreach arg [info args $proc] { ...
    (comp.lang.tcl)
  • Re: de-listing a list to use as proc arguments
    ... TCL proc. ... Or I can write it using "args" and call it in this way: ... applying it as arguments to a proc. ... define suma = curry sum ...
    (comp.lang.tcl)
  • Re: Help Passing Variables
    ... proc atst { ... set a [lindex $alst 0] ... Is the use of the term args tied to the "called" procedure, i.e. 'proc sum args {' then using $args within it to extract the variables. ...
    (comp.lang.tcl)
  • Re: tk_openFile errors on files within vfs
    ... proc::tk_getOpenFile {args} { ... The problem is that the native dialogs don't grok the Tcl VFS. ...
    (comp.lang.tcl)