From 8618af7252260e1c283de20bc4cfd64d63b68770 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dan=20Vr=C3=A1til?= Date: Sun, 14 Dec 2014 13:11:47 +0100 Subject: Async: bring back synchronous Future::waitForFinished() --- async/src/async.cpp | 1 + async/src/async.h | 3 +-- async/src/future.cpp | 2 -- async/src/future.h | 26 +++++++++++++++++++++----- 4 files changed, 23 insertions(+), 9 deletions(-) (limited to 'async/src') diff --git a/async/src/async.cpp b/async/src/async.cpp index e1d4806..e24b769 100644 --- a/async/src/async.cpp +++ b/async/src/async.cpp @@ -48,3 +48,4 @@ JobBase::JobBase(Private::ExecutorBase *executor) JobBase::~JobBase() { } + diff --git a/async/src/async.h b/async/src/async.h index 233ad56..5866b34 100644 --- a/async/src/async.h +++ b/async/src/async.h @@ -251,8 +251,7 @@ public: private: Job(Private::ExecutorBase *executor) : JobBase(executor) - { - } + {} }; } // namespace Async diff --git a/async/src/future.cpp b/async/src/future.cpp index 48c7417..dcbec32 100644 --- a/async/src/future.cpp +++ b/async/src/future.cpp @@ -25,13 +25,11 @@ using namespace Async; FutureBase::FutureBase() : mFinished(false) - , mWaitLoop(nullptr) { } FutureBase::FutureBase(const Async::FutureBase &other) : mFinished(other.mFinished) - , mWaitLoop(other.mWaitLoop) { } diff --git a/async/src/future.h b/async/src/future.h index 39e3936..ecd6931 100644 --- a/async/src/future.h +++ b/async/src/future.h @@ -29,6 +29,7 @@ class QEventLoop; #include #include #include +#include namespace Async { @@ -45,12 +46,14 @@ protected: FutureBase(const FutureBase &other); bool mFinished; - QEventLoop *mWaitLoop; }; template class FutureWatcher; +template +class Future; + template class FutureGeneric : public FutureBase { @@ -67,15 +70,28 @@ public: } } + void waitForFinished() + { + if (isFinished()) { + return; + } + FutureWatcher watcher; + QEventLoop eventLoop; + QObject::connect(&watcher, &Async::FutureWatcher::futureReady, + &eventLoop, &QEventLoop::quit); + watcher.setFuture(*static_cast*>(this)); + eventLoop.exec(); + } + protected: FutureGeneric() - : FutureBase() - , d(new Private) + : FutureBase() + , d(new Private) {} FutureGeneric(const FutureGeneric &other) - : FutureBase(other) - , d(other.d) + : FutureBase(other) + , d(other.d) {} class Private : public QSharedData -- cgit v1.2.3