There is no way to change the default timeout of a request. But you can do this manually when managing the timeout in your async request handler. Most applications should be using async requests, so you'll be doing similar checks anyway. Also be sure to call asyncCancel()
on the roUrlTransfer
to clean up the request.
' 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
As noted in the code, you will want to measure the timeout using an roTimeSpan
if you are handling other requests in your wait loop (in cases where the wait timeout is not the same as the request timeout).