====== Using ''after'' with a local variable ====== This page is part of the Tcl/Tk page of the Airplug documentation.\\ [[en:doc:pub:tcltk:start|Back to the Tcl/Tk page]] / [[en:doc:summary|Back to Airplug documentation page]]. --- The following code after $closingdelay { catch { close $socket } } allows to program the closure of a socket thay may remain opened after a given delay. If the ''socket'' variable is not in the correct namespace when the delay expired, an error will occur regarding the value of ''$socket''. A solution consists in executing the delayed command in the correct namespace or to define the ''socket'' variable in the global namespace. However, if the above line of code is reused with a new value of ''$socket'' (eg. a second socket has been opened and should be closed after a delay), then a single socket will be closed (the one with the last value assigned to ''$socket''). In the case the variable ''$socket'' is used several times and you want that the delayed instruction is executed, for each of its value, a solution consists in replacing ''$socket'' by its value before the after call: set cmd "close $socket_web" eval { after $closingdelay $cmd }
---- This page is part of the Tcl/Tk page of the Airplug documentation.\\ [[en:doc:pub:tcltk:start|Back to the Tcl/Tk page]] / [[en:doc:summary|Back to Airplug documentation page]].