Tcl 在http::geturl中运行异步回调

Tcl 在http::geturl中运行异步回调,tcl,asynchronous,Tcl,Asynchronous,我尝试异步运行http::geturl,并在回调中获得结果 package require http proc cb {token} { exec notify-send "message"; puts "console message" exec echo "file message" > ~/test_file } http::geturl http://mail.ru -command cb 当我像tclsh main.tcl那

我尝试异步运行http::geturl,并在回调中获得结果

package require  http

proc cb {token} {
    exec notify-send "message";
    puts "console message"
    exec  echo  "file message" >  ~/test_file    
}

http::geturl  http://mail.ru   -command  cb 
当我像tclsh main.tcl那样运行这段代码时,什么也没发生-脚本可以工作,但不调用回调

当我像运行wish main.tcl这样运行代码时,我看到“message”通知,看到“console message”,test_文件得到“file message”


为什么会发生这种情况以及我应该如何异步运行tcl脚本???

您必须使用
vwait显式地在适当的位置(注册回调等后)输入tcl的事件循环:

package require  http

proc cb {token} {
    puts "console message"
    set ::done 1; # break out of event loop
}

http::geturl http://example.org/ -command cb

vwait ::done; # enter the event loop

在回调中,您可能希望再次通过设置信号变量
::done

离开事件循环,您必须使用
vwait显式地在适当的位置(注册回调等后)输入Tcl的事件循环:

package require  http

proc cb {token} {
    puts "console message"
    set ::done 1; # break out of event loop
}

http::geturl http://example.org/ -command cb

vwait ::done; # enter the event loop

在回调中,您可能希望通过设置信号变量
::done

wish
隐式地进入事件循环,从而产生差异。
wish
隐式地进入事件循环,从而产生差异。文档中对此进行了描述,并提供了一个方便的命令,::http::wait的存在有助于实现这一点。文档中对此进行了描述,并且有一个方便的命令::http::wait的存在有助于实现这一点。