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.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/async/autotests/asynctest.cpp b/async/autotests/asynctest.cpp
index 714e2e4..1ee3843 100644
--- a/async/autotests/asynctest.cpp
+++ b/async/autotests/asynctest.cpp
@@ -41,6 +41,7 @@ private Q_SLOTS:
41 void testSyncPromises(); 41 void testSyncPromises();
42 void testAsyncPromises(); 42 void testAsyncPromises();
43 void testAsyncPromises2(); 43 void testAsyncPromises2();
44 void testNestedAsync();
44 void testSyncEach(); 45 void testSyncEach();
45 void testSyncReduce(); 46 void testSyncReduce();
46}; 47};
@@ -120,6 +121,39 @@ void AsyncTest::testAsyncPromises2()
120 QCOMPARE(future.value(), 42); 121 QCOMPARE(future.value(), 42);
121} 122}
122 123
124void AsyncTest::testNestedAsync()
125{
126 bool done = false;
127
128 auto job = Async::start<int>(
129 [](Async::Future<int> &future) {
130 auto innerJob = Async::start<int>([](Async::Future<int> &innerFuture) {
131 QTimer *timer = new QTimer();
132 QObject::connect(timer, &QTimer::timeout,
133 [&]() {
134 innerFuture.setValue(42);
135 innerFuture.setFinished();
136 });
137 QObject::connect(timer, &QTimer::timeout,
138 timer, &QObject::deleteLater);
139 timer->setSingleShot(true);
140 timer->start(0);
141 }).then<void>([&future](Async::Future<void> &innerThenFuture) {
142 future.setFinished();
143 innerThenFuture.setFinished();
144 });
145 innerJob.exec();
146 }
147 ).then<int, int>([&done](int result, Async::Future<int> &future) {
148 done = true;
149 future.setValue(result);
150 future.setFinished();
151 });
152 job.exec();
153
154 QTRY_VERIFY(done);
155}
156
123void AsyncTest::testSyncEach() 157void AsyncTest::testSyncEach()
124{ 158{
125 auto job = Async::start<QList<int>>( 159 auto job = Async::start<QList<int>>(