QXmpp Version: 1.5.1
Public Member Functions | Friends | List of all members
QXmppTask< T > Class Template Reference

#include <QXmppTask.h>

Public Member Functions

void then (QObject *context, Continuation continuation)
bool isFinished () const
bool hasResult () const
const T & result () const
takeResult ()
QFuture< T > toFuture (QObject *context)


class QXmppPromise< T >

Detailed Description

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.

QXmpp 1.5

Member Function Documentation

◆ hasResult()

template<typename T >
bool QXmppTask< T >::hasResult ( ) const

Returns whether the task is finished and the value has not been taken yet.

◆ isFinished()

template<typename T >
bool QXmppTask< T >::isFinished ( ) const

Whether the asynchronous operation is already finished.

This does not mean that the result is still stored, it might have been taken using takeResult() or handled using then().

◆ result()

template<typename T >
const T & QXmppTask< T >::result ( ) const

The result of the operation.

This can only be used once the operation is finished.

◆ takeResult()

template<typename T >
T QXmppTask< T >::takeResult ( )

Moves the result of the operation out of the task.

This can only be used once and only after the operation has finished.

◆ then()

template<typename T >
void QXmppTask< T >::then ( QObject *  context,
Continuation  continuation 

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.

If another function was previously registered using .then(), the old function will be replaced, and only the new one will be called.

Example usage:

QXmppTask<QString> generateSomething();
void Manager::generate()
generateSomething().then(this, [](QString &&result) {
// runs as soon as the result is finished
qDebug() << "Generating finished:" << result;
// The generation could still be in progress here and the lambda might not
// have been executed yet.
// Manager is derived from QObject.
Definition: QXmppTask.h:62
const T & result() const
Definition: QXmppTask.h:162
contextQObject 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.
continuationA function accepting a result in the form of T &&.

◆ toFuture()

template<typename T >
QFuture< T > QXmppTask< T >::toFuture ( QObject *  context)

Converts the Task into a QFuture. Afterwards the QXmppTask object is invalid.

The documentation for this class was generated from the following files: