summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--async/autotests/asynctest.cpp29
-rw-r--r--async/src/async.h3
2 files changed, 31 insertions, 1 deletions
diff --git a/async/autotests/asynctest.cpp b/async/autotests/asynctest.cpp
index ffbce9e..714e2e4 100644
--- a/async/autotests/asynctest.cpp
+++ b/async/autotests/asynctest.cpp
@@ -40,6 +40,7 @@ public:
40private Q_SLOTS: 40private Q_SLOTS:
41 void testSyncPromises(); 41 void testSyncPromises();
42 void testAsyncPromises(); 42 void testAsyncPromises();
43 void testAsyncPromises2();
43 void testSyncEach(); 44 void testSyncEach();
44 void testSyncReduce(); 45 void testSyncReduce();
45}; 46};
@@ -91,6 +92,34 @@ void AsyncTest::testAsyncPromises()
91 QCOMPARE(future.value(), 42); 92 QCOMPARE(future.value(), 42);
92} 93}
93 94
95void AsyncTest::testAsyncPromises2()
96{
97 bool done = false;
98
99 auto job = Async::start<int>(
100 [](Async::Future<int> &future) {
101 QTimer *timer = new QTimer();
102 QObject::connect(timer, &QTimer::timeout,
103 [&]() {
104 future.setValue(42);
105 future.setFinished();
106 });
107 QObject::connect(timer, &QTimer::timeout,
108 timer, &QObject::deleteLater);
109 timer->setSingleShot(true);
110 timer->start(200);
111 }
112 ).then<int, int>([&done](int result, Async::Future<int> &future) {
113 done = true;
114 future.setValue(result);
115 future.setFinished();
116 });
117 auto future = job.exec();
118
119 QTRY_VERIFY(done);
120 QCOMPARE(future.value(), 42);
121}
122
94void AsyncTest::testSyncEach() 123void AsyncTest::testSyncEach()
95{ 124{
96 auto job = Async::start<QList<int>>( 125 auto job = Async::start<QList<int>>(
diff --git a/async/src/async.h b/async/src/async.h
index 6548079..4fb4f2b 100644
--- a/async/src/async.h
+++ b/async/src/async.h
@@ -287,7 +287,8 @@ void Executor<PrevOut, Out, In ...>::exec()
287 auto futureWatcher = new Async::FutureWatcher<PrevOut>(); 287 auto futureWatcher = new Async::FutureWatcher<PrevOut>();
288 QObject::connect(futureWatcher, &Async::FutureWatcher<PrevOut>::futureReady, 288 QObject::connect(futureWatcher, &Async::FutureWatcher<PrevOut>::futureReady,
289 [futureWatcher, this]() { 289 [futureWatcher, this]() {
290 assert(futureWatcher->future().isFinished()); 290 //FIXME mFinished is not part of the d-pointer but we copy the future below
291 // assert(futureWatcher->future().isFinished());
291 futureWatcher->deleteLater(); 292 futureWatcher->deleteLater();
292 previousFutureReady(); 293 previousFutureReady();
293 }); 294 });