Since I didn't see any good examples of async requests, here's a reworking of the two functions so they are generally useful, in case anyone is interested. I made them so you can have multiple async requests happening at the same time and they won't conflict.
' url: the url
' port: port that is being monitored with wait()
' return value: the unique id of the request (or 0 for failure).
Function sendAsyncRequest(url as String, port as Object) as Integer
if m.asynchRequests = invalid
m.asynchRequests = {}
end if
urlXfer = CreateObject("roURLTransfer")
urlXfer.setUrl(url)
urlXfer.setPort(port)
urlXfer.EnableEncodings(true)
if urlXfer.asyncGetToString() = false
return 0
end if
id = urlXfer.GetIdentity()
m.asynchRequests[str(id)] = urlXfer
return id
end Function
and...
' msg: the message returned from wait()
' id: (optional) it will ignore responses with different ids
' return value: invalid, if not an async request or not the right id, or
' an object with the string (as "data") and the id,
' and the response code (hopefully 200)
Function getAsyncResponse (msg as Object, id = 0 as Integer) as Object
if type(msg) = "roUrlEvent"
currId = msg.GetSourceIdentity()
if id = 0 or id = currId
out = {
data : msg.GetString()
id : currId
responseCode : msg.GetResponseCode()
}
m.asynchRequests.delete(str(currId))
return out
end if
end if
return invalid
end Function