1mNAME0m
       vwait - Process events until a variable is written

1mSYNOPSIS0m
       1mvwait 4m22mvarName0m


1mDESCRIPTION0m
       This  command enters the Tcl event loop to process events, blocking the
       application if no events are ready.   It  continues  processing  events
       until some event handler sets the value of variable 4mvarName24m.  Once 4mvar-0m
       4mName24m has been set, the 1mvwait 22mcommand will return as soon as  the  event
       handler  that modified 4mvarName24m completes.  4mvarName24m must globally scoped
       (either with a call to 1mglobal 22mfor the 4mvarName24m, or with the full  names-
       pace path specification).

       In  some  cases the 1mvwait 22mcommand may not return immediately after 4mvar-0m
       4mName24m is set.  This can happen if the event handler  that  sets  4mvarName0m
       does  not  complete immediately.  For example, if an event handler sets
       4mvarName24m and then itself calls 1mvwait 22mto wait for a  different  variable,
       then it may not return for a long time.  During this time the top-level
       1mvwait 22mis blocked waiting for the event handler to complete, so it  can-
       not return either.

1mEXAMPLES0m
       Run  the  event-loop continually until some event calls 1mexit22m.  (You can
       use any variable not mentioned elsewhere, but the name 4mforever24m  reminds
       you at a glance of the intent.)
              1mvwait 22mforever

       Wait  five seconds for a connection to a server socket, otherwise close
       the socket and continue running the script:
              # Initialise the state
              after 5000 set state timeout
              set server [socket -server accept 12345]
              proc accept {args} {
                 global state connectionInfo
                 set state accepted
                 set connectionInfo $args
              }

              # Wait for something to happen
              1mvwait 22mstate

              # Clean up events that could have happened
              close $server
              after cancel set state timeout

              # Do something based on how the vwait finished...
              switch $state {
                 timeout {
                    puts "no connection on port 12345"
                 }
                 accepted {
                    puts "connection: $connectionInfo"
                    puts [lindex $connectionInfo 0] "Hello there!"
                 }
              }


1mSEE ALSO0m
       global(n), update(n)


1mKEYWORDS0m
