template<typename T>
class QXmppTask< T >
Handle for an ongoing operation that finishes in the future.
Tasks are generated by QXmppPromise and can be handled using QXmppTask::then().
Unlike QFuture, this is not thread-safe!! This avoids the need to do mutex locking at every access though.
- Since
- QXmpp 1.5
template<typename T >
| void QXmppTask< T >::then |
( |
const QObject * |
context, |
|
|
Continuation |
continuation |
|
) |
| |
|
inline |
Registers a function that will be called with the result as parameter when the asynchronous operation finishes.
If the task is already finished when calling this (and still has a result), the function will be called immediately.
.then() can be called multiple times if and only if T is copy-constructible. For copyable types all continuations will be called in the order they were set. For move-only types only the latest continuation will be called.
Example usage:
void Manager::generate()
{
generateSomething().then(
this, [](QString &&
result) {
qDebug() <<
"Generating finished:" <<
result;
});
}
Definition QXmppTask.h:46
const T & result() const
Definition QXmppTask.h:156
- Note
- Support for multiple continuations with copy-constructible types was added in QXmpp 1.11.
- Parameters
-
| context | QObject used for unregistering the handler function when the object is deleted. This way your lambda will never be executed after your object has been deleted. |
| continuation | A function accepting a result in the form of T &&. |