无法更改请求的默认超时值。但是,在管理异步请求处理程序中的超时时,您可以手动执行此操作。大多数应用程序应该使用异步请求,所以无论如何你都会进行类似的检查。另外请务必拨打roUrlTransfer
上的asyncCancel()
来清理请求。
' given a url that will timeout
url = "http://www.mocky.io/v2/5a75d6902e000068006ab21a?mocky-delay=1000ms"
' and a timeout in ms
timeout = 100
' create a roUrlTransfer for the request
urlTransfer = CreateObject("roUrlTransfer")
urlTransfer.setUrl(url)
port = CreateObject("roMessagePort")
urlTransfer.setMessagePort(port)
' request the URL
if urlTransfer.asyncGetToString()
event = wait(timeout, port)
if type(event) = "roUrlEvent"
print "urlTransfer success"
else if event <> invalid
print "event emitted: " + type(event)
else
print "urlTransfer timed out"
urlTransfer.asyncCancel()
' alternatively: measure the request time against timeout using roTimeSpan
end if
end if
正如代码所指出的,你会想使用roTimeSpan
如果你正在处理您的等待循环其他请求测量超时(在情况下,等待超时是不一样的请求超时)。