Nonblocking Wait Activities
Perl/Tk provides three commands that wait for particular events to occur. Although the wait is nonblocking (Tk events continue to be processed), program flow is logically suspended at the wait point only until the appropriate event occurs. The commands are:
-
$widget->waitVariable(varRef) Waits until the variable referenced by
varRefchanges (i.e., it is written orundef).-
$widget->waitVisibility Waits until
$widget’s visibility state changes. The most common use for this command is to wait for a window to appear on the display. (Event type =Visibility.)-
$widget->waitWindow Waits until
$widgetis destroyed. (Event type =Destroy.)
waitVariable can be employed in a number of
ingenious situations. In Chapter 23, we use it as a
means of effecting interprocess communications. But perhaps the most
common is waiting for a user response to, say, a Dialog widget. A
Dialog posts a message and one or more Buttons, then waits for the
user to make a selection by clicking a Button. The specified Button
label text is then stored in the variable that
waitVariable is watching, and logical program flow
continues.
Tk::waitVariableX
Although waitVariable is nonblocking in the sense
that Tk events continue to be processed, the program flow at the wait
point is blocked until the variable changes. If the variable never
changes, then that thread of execution can never continue. So, we can
imagine a waitVariable with a timeout such that, after a certain amount of time, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access