Sujet : Re: Event loop and http::geturl
De : et99 (at) *nospam* rocketship1.me (et99)
Groupes : comp.lang.tclDate : 25. Jun 2025, 08:03:52
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <103g70o$2k78v$1@dont-email.me>
References : 1 2 3 4
User-Agent : Mozilla Thunderbird
On 6/24/2025 5:19 PM, et99 wrote:
On 6/24/2025 1:01 AM, Jonathan Kelly wrote:
OK. Is there a way to ACTUALLY get geturl to block, or equivalent? I need the geturl to finish before anything else happens.
I would think you can use this option on the geturl call:
-command callback
I see you already know about -command, so perhaps what you really want is an example of how to use it.
proc httpCallback {token} { ;# the -command callback - called when transaction completes
upvar 0 $token state ;# use this to get the results
set ::urldone 1 ;# block on the setting of this variable
return
}
unset -nocomplain ::urldone :# rules out a race condition
http::geturl <your url> -command httpCallback
if {![info exists ::urldone]} {vwait ::urldone} ;# no need to block if the variable exists
The above code is being cautious. There may not be any possibility of a race condition, but this way we rule it out, even if they change the code in the future. It never hurts to unset a variable first that you're going to set later anyway.