diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-01-06 20:13:30 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-01-06 20:13:30 +0100 |
commit | c73371e12fd127cbc39496b9ffadbcf9b702b600 (patch) | |
tree | 912dab0f3105a2c4c4f994ae6adbf54d0158d595 /async/autotests/asynctest.cpp | |
parent | 3e786efb2811f1e88485ffff50d1327d07f40892 (diff) | |
download | sink-c73371e12fd127cbc39496b9ffadbcf9b702b600.tar.gz sink-c73371e12fd127cbc39496b9ffadbcf9b702b600.zip |
Make async use of jobs work.
Diffstat (limited to 'async/autotests/asynctest.cpp')
-rw-r--r-- | async/autotests/asynctest.cpp | 29 |
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: | |||
40 | private Q_SLOTS: | 40 | private 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 | ||
95 | void 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 | |||
94 | void AsyncTest::testSyncEach() | 123 | void AsyncTest::testSyncEach() |
95 | { | 124 | { |
96 | auto job = Async::start<QList<int>>( | 125 | auto job = Async::start<QList<int>>( |