Implement new send and sendAsync api
This commit adds a new send api which is now located on the QTdRequest for convenience So it now should be enough to just do something like
QScopedPointer<QTdRequest> req(new QTdRequest);
req->send();
Which will internally pass it on to QTdClient::send()
There is also a new sendAsync api on the QTdRequest
that will
return a QFuture<QTdResponse>
so that you can wait on a response
for a request and then unmarshal the data into the desired structure
QFuture<QTdResponse> resp = req->sendAsync()
await(resp) // or you can use QFutureWatcher
if (resp.result().isError() {
qWarning() << resp.result().errorMessage();
}
myStructure->unmarshalJson(resp.result().json());
As you can see above there is also an await()
helper located
in utils/await.h which will allow you to wait inline without
blocking the mainthread. The await helper takes a second argument
for a timer to abort the wait after a certain amount of time.
The current api of passing the request to QTdClient::send is still supported so this isn't a breaking change.
Edited by Dan Chapman