summaryrefslogtreecommitdiffstats
path: root/async/autotests/asynctest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'async/autotests/asynctest.cpp')
-rw-r--r--async/autotests/asynctest.cpp29
1 files changed, 29 insertions, 0 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>>(