diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-01-16 13:38:29 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-01-16 13:38:29 +0100 |
commit | 10977b90bffeb675650b049df6585c296c6980cb (patch) | |
tree | 52e41281b820fa7112742240d995de652219cdc2 /async/autotests/asynctest.cpp | |
parent | e56166cf75aff15eda05be5c33825bd926b9ccb2 (diff) | |
download | sink-10977b90bffeb675650b049df6585c296c6980cb.tar.gz sink-10977b90bffeb675650b049df6585c296c6980cb.zip |
Async test for nested jobs.
Diffstat (limited to 'async/autotests/asynctest.cpp')
-rw-r--r-- | async/autotests/asynctest.cpp | 34 |
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 | ||
124 | void 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 | |||
123 | void AsyncTest::testSyncEach() | 157 | void AsyncTest::testSyncEach() |
124 | { | 158 | { |
125 | auto job = Async::start<QList<int>>( | 159 | auto job = Async::start<QList<int>>( |