summaryrefslogtreecommitdiffstats
path: root/async/src
diff options
context:
space:
mode:
Diffstat (limited to 'async/src')
-rw-r--r--async/src/async.cpp1
-rw-r--r--async/src/async.h3
-rw-r--r--async/src/future.cpp2
-rw-r--r--async/src/future.h26
4 files changed, 23 insertions, 9 deletions
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)
48JobBase::~JobBase() 48JobBase::~JobBase()
49{ 49{
50} 50}
51
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:
251private: 251private:
252 Job(Private::ExecutorBase *executor) 252 Job(Private::ExecutorBase *executor)
253 : JobBase(executor) 253 : JobBase(executor)
254 { 254 {}
255 }
256}; 255};
257 256
258} // namespace Async 257} // 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;
25 25
26FutureBase::FutureBase() 26FutureBase::FutureBase()
27 : mFinished(false) 27 : mFinished(false)
28 , mWaitLoop(nullptr)
29{ 28{
30} 29}
31 30
32FutureBase::FutureBase(const Async::FutureBase &other) 31FutureBase::FutureBase(const Async::FutureBase &other)
33 : mFinished(other.mFinished) 32 : mFinished(other.mFinished)
34 , mWaitLoop(other.mWaitLoop)
35{ 33{
36} 34}
37 35
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;
29#include <QSharedDataPointer> 29#include <QSharedDataPointer>
30#include <QPointer> 30#include <QPointer>
31#include <QVector> 31#include <QVector>
32#include <QEventLoop>
32 33
33namespace Async { 34namespace Async {
34 35
@@ -45,13 +46,15 @@ protected:
45 FutureBase(const FutureBase &other); 46 FutureBase(const FutureBase &other);
46 47
47 bool mFinished; 48 bool mFinished;
48 QEventLoop *mWaitLoop;
49}; 49};
50 50
51template<typename T> 51template<typename T>
52class FutureWatcher; 52class FutureWatcher;
53 53
54template<typename T> 54template<typename T>
55class Future;
56
57template<typename T>
55class FutureGeneric : public FutureBase 58class FutureGeneric : public FutureBase
56{ 59{
57 friend class FutureWatcher<T>; 60 friend class FutureWatcher<T>;
@@ -67,15 +70,28 @@ public:
67 } 70 }
68 } 71 }
69 72
73 void waitForFinished()
74 {
75 if (isFinished()) {
76 return;
77 }
78 FutureWatcher<T> watcher;
79 QEventLoop eventLoop;
80 QObject::connect(&watcher, &Async::FutureWatcher<T>::futureReady,
81 &eventLoop, &QEventLoop::quit);
82 watcher.setFuture(*static_cast<Async::Future<T>*>(this));
83 eventLoop.exec();
84 }
85
70protected: 86protected:
71 FutureGeneric() 87 FutureGeneric()
72 : FutureBase() 88 : FutureBase()
73 , d(new Private) 89 , d(new Private)
74 {} 90 {}
75 91
76 FutureGeneric(const FutureGeneric<T> &other) 92 FutureGeneric(const FutureGeneric<T> &other)
77 : FutureBase(other) 93 : FutureBase(other)
78 , d(other.d) 94 , d(other.d)
79 {} 95 {}
80 96
81 class Private : public QSharedData 97 class Private : public QSharedData