Initial version of donated sources by Avertec, 3.4p5.
[tas-yagle.git] / distrib / share / tcl / help / tcl / events / vwait
1 NAME
2 vwait - Process events until a variable is written
3
4 SYNOPSIS
5 vwait varName
6
7
8 DESCRIPTION
9 This command enters the Tcl event loop to process events, blocking the
10 application if no events are ready. It continues processing events
11 until some event handler sets the value of variable varName. Once var-
12 Name has been set, the vwait command will return as soon as the event
13 handler that modified varName completes. varName must globally scoped
14 (either with a call to global for the varName, or with the full names-
15 pace path specification).
16
17 In some cases the vwait command may not return immediately after var-
18 Name is set. This can happen if the event handler that sets varName
19 does not complete immediately. For example, if an event handler sets
20 varName and then itself calls vwait to wait for a different variable,
21 then it may not return for a long time. During this time the top-level
22 vwait is blocked waiting for the event handler to complete, so it can-
23 not return either.
24
25 EXAMPLES
26 Run the event-loop continually until some event calls exit. (You can
27 use any variable not mentioned elsewhere, but the name forever reminds
28 you at a glance of the intent.)
29 vwait forever
30
31 Wait five seconds for a connection to a server socket, otherwise close
32 the socket and continue running the script:
33 # Initialise the state
34 after 5000 set state timeout
35 set server [socket -server accept 12345]
36 proc accept {args} {
37 global state connectionInfo
38 set state accepted
39 set connectionInfo $args
40 }
41
42 # Wait for something to happen
43 vwait state
44
45 # Clean up events that could have happened
46 close $server
47 after cancel set state timeout
48
49 # Do something based on how the vwait finished...
50 switch $state {
51 timeout {
52 puts "no connection on port 12345"
53 }
54 accepted {
55 puts "connection: $connectionInfo"
56 puts [lindex $connectionInfo 0] "Hello there!"
57 }
58 }
59
60
61 SEE ALSO
62 global(n), update(n)
63
64
65 KEYWORDS