diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/base/QXmppFutureUtils_p.h | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/base/QXmppFutureUtils_p.h b/src/base/QXmppFutureUtils_p.h index 720e6df4..0cad95f5 100644 --- a/src/base/QXmppFutureUtils_p.h +++ b/src/base/QXmppFutureUtils_p.h @@ -83,6 +83,19 @@ inline QFuture<void> makeReadyFuture() } template<typename T, typename Handler> +void awaitLast(const QFuture<T> &future, QObject *context, Handler handler) +{ + auto *watcher = new QFutureWatcher<T>(context); + QObject::connect(watcher, &QFutureWatcherBase::finished, + context, [watcher, handler { std::move(handler) }]() { + auto future = watcher->future(); + handler(future.resultAt(future.resultCount() - 1)); + watcher->deleteLater(); + }); + watcher->setFuture(future); +} + +template<typename T, typename Handler> void await(const QFuture<T> &future, QObject *context, Handler handler) { auto *watcher = new QFutureWatcher<T>(context); |
