diff options
author | Dan Vrátil <dvratil@redhat.com> | 2015-02-20 13:13:56 +0100 |
---|---|---|
committer | Dan Vrátil <dvratil@redhat.com> | 2015-02-20 13:52:10 +0100 |
commit | 1da08ebfe267313015c201fd1106f891af554e14 (patch) | |
tree | 0c535e0b9a356f3ca6d0a6309dd9153c1882b088 /async/autotests/asynctest.cpp | |
parent | 5c8714d3b29fbed600b367bdad1e695674a0e551 (diff) | |
download | sink-1da08ebfe267313015c201fd1106f891af554e14.tar.gz sink-1da08ebfe267313015c201fd1106f891af554e14.zip |
Async: allow Async::start() to have input value
The initial value can be passed in as argument to Job::exec(), or by another
job in case of job chaining.
Diffstat (limited to 'async/autotests/asynctest.cpp')
-rw-r--r-- | async/autotests/asynctest.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/async/autotests/asynctest.cpp b/async/autotests/asynctest.cpp index 4ebe65e..ed550ca 100644 --- a/async/autotests/asynctest.cpp +++ b/async/autotests/asynctest.cpp | |||
@@ -25,6 +25,7 @@ | |||
25 | #include <QString> | 25 | #include <QString> |
26 | #include <QTimer> | 26 | #include <QTimer> |
27 | #include <QtTest/QTest> | 27 | #include <QtTest/QTest> |
28 | #include <QDebug> | ||
28 | 29 | ||
29 | class AsyncTest : public QObject | 30 | class AsyncTest : public QObject |
30 | { | 31 | { |
@@ -42,6 +43,8 @@ private Q_SLOTS: | |||
42 | void testAsyncPromises(); | 43 | void testAsyncPromises(); |
43 | void testAsyncPromises2(); | 44 | void testAsyncPromises2(); |
44 | void testNestedAsync(); | 45 | void testNestedAsync(); |
46 | void testStartValue(); | ||
47 | |||
45 | void testAsyncThen(); | 48 | void testAsyncThen(); |
46 | void testSyncThen(); | 49 | void testSyncThen(); |
47 | void testAsyncEach(); | 50 | void testAsyncEach(); |
@@ -52,6 +55,8 @@ private Q_SLOTS: | |||
52 | 55 | ||
53 | }; | 56 | }; |
54 | 57 | ||
58 | |||
59 | |||
55 | void AsyncTest::testSyncPromises() | 60 | void AsyncTest::testSyncPromises() |
56 | { | 61 | { |
57 | auto baseJob = Async::start<int>( | 62 | auto baseJob = Async::start<int>( |
@@ -160,6 +165,23 @@ void AsyncTest::testNestedAsync() | |||
160 | QTRY_VERIFY(done); | 165 | QTRY_VERIFY(done); |
161 | } | 166 | } |
162 | 167 | ||
168 | void AsyncTest::testStartValue() | ||
169 | { | ||
170 | auto job = Async::start<int, int>( | ||
171 | [](int in, Async::Future<int> &future) { | ||
172 | future.setValue(in); | ||
173 | future.setFinished(); | ||
174 | }); | ||
175 | |||
176 | auto future = job.exec(42); | ||
177 | QVERIFY(future.isFinished()); | ||
178 | QCOMPARE(future.value(), 42); | ||
179 | } | ||
180 | |||
181 | |||
182 | |||
183 | |||
184 | |||
163 | void AsyncTest::testAsyncThen() | 185 | void AsyncTest::testAsyncThen() |
164 | { | 186 | { |
165 | auto job = Async::start<int>( | 187 | auto job = Async::start<int>( |