tcl/tk参照——制御構造vwait
..。
..。
名前
vwait-変数が変更されるまで待ちます。
構文
vwait varName
説明
このコマンドはTclイベントサイクルに入り、Tclは変数varNameが修正されるまでイベントを処理します。一旦varNameが修正されると、vwaitコマンドはすぐに戻ります。varNameはグローバルレンジ変数でなければなりません。(グローバル変数か、名前空間パスが完全に付いているか)
いくつかの場合、varNameが修正された後、vwaitコマンドはすぐには戻らないかもしれません。varNameを設定したイベントのハンドルが完成していない場合、vwaitコマンドはすぐには戻りません。例えば、イベントのハンドルをvarNameに設定し、自分でvwaitを呼び出して別の変数を待つと、長い時間がかかります。この場合、最高スタック層のvwaitコマンドがブロックされ、イベントの終了を待つため、戻ることができません。
例
イベントがいくつかのイベントまで実行されます。
..。
名前
vwait-変数が変更されるまで待ちます。
構文
vwait varName
説明
このコマンドはTclイベントサイクルに入り、Tclは変数varNameが修正されるまでイベントを処理します。一旦varNameが修正されると、vwaitコマンドはすぐに戻ります。varNameはグローバルレンジ変数でなければなりません。(グローバル変数か、名前空間パスが完全に付いているか)
いくつかの場合、varNameが修正された後、vwaitコマンドはすぐには戻らないかもしれません。varNameを設定したイベントのハンドルが完成していない場合、vwaitコマンドはすぐには戻りません。例えば、イベントのハンドルをvarNameに設定し、自分でvwaitを呼び出して別の変数を待つと、長い時間がかかります。この場合、最高スタック層のvwaitコマンドがブロックされ、イベントの終了を待つため、戻ることができません。
例
イベントがいくつかのイベントまで実行されます。
vwait forever
サーバーソケットを接続するとき5秒待ちます。さもなければソケットを閉じてスクリプトを実行し続けます。# 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
vwait state
# 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!"
}
}