1vwait(n)                     Tcl Built-In Commands                    vwait(n)
2
3
4
5______________________________________________________________________________
6

NAME

8       vwait - Process events until a variable is written
9

SYNOPSIS

11       vwait varName
12_________________________________________________________________
13
14

DESCRIPTION

16       This  command enters the Tcl event loop to process events, blocking the
17       application if no events are ready.   It  continues  processing  events
18       until some event handler sets the value of variable varName.  Once var‐
19       Name has been set, the vwait command will return as soon as  the  event
20       handler  that  modified  varName  completes.   varName must be globally
21       scoped (either with a call to global for the varName, or with the  full
22       namespace path specification).
23
24       In  some  cases the vwait command may not return immediately after var‐
25       Name is set.  This can happen if the event handler  that  sets  varName
26       does  not  complete immediately.  For example, if an event handler sets
27       varName and then itself calls vwait to wait for a  different  variable,
28       then it may not return for a long time.  During this time the top-level
29       vwait is blocked waiting for the event handler to complete, so it  can‐
30       not return either.
31

EXAMPLES

33       Run  the  event-loop continually until some event calls exit.  (You can
34       use any variable not mentioned elsewhere, but the name forever  reminds
35       you at a glance of the intent.)
36              vwait forever
37
38       Wait  five seconds for a connection to a server socket, otherwise close
39       the socket and continue running the script:
40              # Initialise the state
41              after 5000 set state timeout
42              set server [socket -server accept 12345]
43              proc accept {args} {
44                 global state connectionInfo
45                 set state accepted
46                 set connectionInfo $args
47              }
48
49              # Wait for something to happen
50              vwait state
51
52              # Clean up events that could have happened
53              close $server
54              after cancel set state timeout
55
56              # Do something based on how the vwait finished...
57              switch $state {
58                 timeout {
59                    puts "no connection on port 12345"
60                 }
61                 accepted {
62                    puts "connection: $connectionInfo"
63                    puts [lindex $connectionInfo 0] "Hello there!"
64                 }
65              }
66
67

SEE ALSO

69       global(n), update(n)
70
71

KEYWORDS

73       event, variable, wait
74
75
76
77Tcl                                   8.0                             vwait(n)
Impressum