From 1da08ebfe267313015c201fd1106f891af554e14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dan=20Vr=C3=A1til?= Date: Fri, 20 Feb 2015 13:13:56 +0100 Subject: 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. --- async/autotests/asynctest.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'async/autotests') 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 @@ #include #include #include +#include class AsyncTest : public QObject { @@ -42,6 +43,8 @@ private Q_SLOTS: void testAsyncPromises(); void testAsyncPromises2(); void testNestedAsync(); + void testStartValue(); + void testAsyncThen(); void testSyncThen(); void testAsyncEach(); @@ -52,6 +55,8 @@ private Q_SLOTS: }; + + void AsyncTest::testSyncPromises() { auto baseJob = Async::start( @@ -160,6 +165,23 @@ void AsyncTest::testNestedAsync() QTRY_VERIFY(done); } +void AsyncTest::testStartValue() +{ + auto job = Async::start( + [](int in, Async::Future &future) { + future.setValue(in); + future.setFinished(); + }); + + auto future = job.exec(42); + QVERIFY(future.isFinished()); + QCOMPARE(future.value(), 42); +} + + + + + void AsyncTest::testAsyncThen() { auto job = Async::start( -- cgit v1.2.3