More "real world" example of using the new Wait For feature to get information from a remote database using jRDC2:
The standard way to send a request with jRDC2:
1. Call req.ExecuteQuery.
2. Handle JobDone event and call Manager.HandleJobAsync.
3. Handle the Result event.
All the results are handled by the same two subs so you use the Tag parameter to distinguish between different requests. It becomes more and more complicated when you add more types of requests.
With the new Wait For feature everything can be handled locally inside the sub. Note that it can be called multiple times safely.
Sub GetRecord (id As Int)
Dim req As DBRequestManager = CreateRequest
Dim cmd As DBCommand = CreateCommand ("select", Array(id))
Dim j As HttpJob = req.ExecuteQuery(cmd, 0)
Wait For (j) JobDone(j As HttpJob) '<---- catch the relevant JobDone event here
If j.Success Then
req.HandleJobAsync(j)
Wait For (req) Result(res As DBResult) '<---- catch the relevant Result event here
Log ("Result for id: " & id)
req.PrintTable(res)
Else
Log("ERROR: " & j.ErrorMessage)
End If
j.Release
End Sub
No need to use tags or to use any global variable to understand which request has returned.