diff options
Diffstat (limited to 'async/src')
-rw-r--r-- | async/src/async.h | 5 | ||||
-rw-r--r-- | async/src/future.cpp | 7 | ||||
-rw-r--r-- | async/src/future.h | 13 |
3 files changed, 11 insertions, 14 deletions
diff --git a/async/src/async.h b/async/src/async.h index 171a245..8fee0bc 100644 --- a/async/src/async.h +++ b/async/src/async.h | |||
@@ -300,8 +300,7 @@ void Executor<PrevOut, Out, In ...>::exec() | |||
300 | auto futureWatcher = new Async::FutureWatcher<PrevOut>(); | 300 | auto futureWatcher = new Async::FutureWatcher<PrevOut>(); |
301 | QObject::connect(futureWatcher, &Async::FutureWatcher<PrevOut>::futureReady, | 301 | QObject::connect(futureWatcher, &Async::FutureWatcher<PrevOut>::futureReady, |
302 | [futureWatcher, this]() { | 302 | [futureWatcher, this]() { |
303 | //FIXME mFinished is not part of the d-pointer but we copy the future below | 303 | assert(futureWatcher->future().isFinished()); |
304 | // assert(futureWatcher->future().isFinished()); | ||
305 | futureWatcher->deleteLater(); | 304 | futureWatcher->deleteLater(); |
306 | previousFutureReady(); | 305 | previousFutureReady(); |
307 | }); | 306 | }); |
@@ -320,7 +319,7 @@ template<typename Out, typename ... In> | |||
320 | void ThenExecutor<Out, In ...>::previousFutureReady() | 319 | void ThenExecutor<Out, In ...>::previousFutureReady() |
321 | { | 320 | { |
322 | if (this->mPrevFuture) { | 321 | if (this->mPrevFuture) { |
323 | assert(this->mPrevFuture->isFinished()); | 322 | assert(this->mPrevFuture->isFinished()); |
324 | } | 323 | } |
325 | this->mFunc(this->mPrevFuture ? this->mPrevFuture->value() : In() ..., | 324 | this->mFunc(this->mPrevFuture ? this->mPrevFuture->value() : In() ..., |
326 | *static_cast<Async::Future<Out>*>(this->mResult)); | 325 | *static_cast<Async::Future<Out>*>(this->mResult)); |
diff --git a/async/src/future.cpp b/async/src/future.cpp index 4b34514..ab02baf 100644 --- a/async/src/future.cpp +++ b/async/src/future.cpp | |||
@@ -20,12 +20,10 @@ | |||
20 | using namespace Async; | 20 | using namespace Async; |
21 | 21 | ||
22 | FutureBase::FutureBase() | 22 | FutureBase::FutureBase() |
23 | : mFinished(false) | ||
24 | { | 23 | { |
25 | } | 24 | } |
26 | 25 | ||
27 | FutureBase::FutureBase(const Async::FutureBase &other) | 26 | FutureBase::FutureBase(const Async::FutureBase &other) |
28 | : mFinished(other.mFinished) | ||
29 | { | 27 | { |
30 | } | 28 | } |
31 | 29 | ||
@@ -33,11 +31,6 @@ FutureBase::~FutureBase() | |||
33 | { | 31 | { |
34 | } | 32 | } |
35 | 33 | ||
36 | bool FutureBase::isFinished() const | ||
37 | { | ||
38 | return mFinished; | ||
39 | } | ||
40 | |||
41 | FutureWatcherBase::FutureWatcherBase(QObject *parent) | 34 | FutureWatcherBase::FutureWatcherBase(QObject *parent) |
42 | : QObject(parent) | 35 | : QObject(parent) |
43 | { | 36 | { |
diff --git a/async/src/future.h b/async/src/future.h index aa8e9be..54580ad 100644 --- a/async/src/future.h +++ b/async/src/future.h | |||
@@ -35,13 +35,11 @@ public: | |||
35 | virtual ~FutureBase(); | 35 | virtual ~FutureBase(); |
36 | 36 | ||
37 | virtual void setFinished() = 0; | 37 | virtual void setFinished() = 0; |
38 | bool isFinished() const; | 38 | virtual bool isFinished() const = 0; |
39 | 39 | ||
40 | protected: | 40 | protected: |
41 | FutureBase(); | 41 | FutureBase(); |
42 | FutureBase(const FutureBase &other); | 42 | FutureBase(const FutureBase &other); |
43 | |||
44 | bool mFinished; | ||
45 | }; | 43 | }; |
46 | 44 | ||
47 | template<typename T> | 45 | template<typename T> |
@@ -58,7 +56,7 @@ class FutureGeneric : public FutureBase | |||
58 | public: | 56 | public: |
59 | void setFinished() | 57 | void setFinished() |
60 | { | 58 | { |
61 | mFinished = true; | 59 | d->finished = true; |
62 | for (auto watcher : d->watchers) { | 60 | for (auto watcher : d->watchers) { |
63 | if (watcher) { | 61 | if (watcher) { |
64 | watcher->futureReadyCallback(); | 62 | watcher->futureReadyCallback(); |
@@ -66,6 +64,11 @@ public: | |||
66 | } | 64 | } |
67 | } | 65 | } |
68 | 66 | ||
67 | bool isFinished() const | ||
68 | { | ||
69 | return d->finished; | ||
70 | } | ||
71 | |||
69 | void waitForFinished() | 72 | void waitForFinished() |
70 | { | 73 | { |
71 | if (isFinished()) { | 74 | if (isFinished()) { |
@@ -93,10 +96,12 @@ protected: | |||
93 | class Private : public QSharedData | 96 | class Private : public QSharedData |
94 | { | 97 | { |
95 | public: | 98 | public: |
99 | Private() : QSharedData(), finished(false) {} | ||
96 | typename std::conditional<std::is_void<T>::value, int /* dummy */, T>::type | 100 | typename std::conditional<std::is_void<T>::value, int /* dummy */, T>::type |
97 | value; | 101 | value; |
98 | 102 | ||
99 | QVector<QPointer<FutureWatcher<T>>> watchers; | 103 | QVector<QPointer<FutureWatcher<T>>> watchers; |
104 | bool finished; | ||
100 | }; | 105 | }; |
101 | 106 | ||
102 | QExplicitlySharedDataPointer<Private> d; | 107 | QExplicitlySharedDataPointer<Private> d; |