diff options
Diffstat (limited to 'async/src/future.h')
-rw-r--r-- | async/src/future.h | 26 |
1 files changed, 21 insertions, 5 deletions
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 | ||
33 | namespace Async { | 34 | namespace 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 | ||
51 | template<typename T> | 51 | template<typename T> |
52 | class FutureWatcher; | 52 | class FutureWatcher; |
53 | 53 | ||
54 | template<typename T> | 54 | template<typename T> |
55 | class Future; | ||
56 | |||
57 | template<typename T> | ||
55 | class FutureGeneric : public FutureBase | 58 | class 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 | |||
70 | protected: | 86 | protected: |
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 |