From c73371e12fd127cbc39496b9ffadbcf9b702b600 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Tue, 6 Jan 2015 20:13:30 +0100 Subject: Make async use of jobs work. --- async/autotests/asynctest.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'async/autotests') 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: private Q_SLOTS: void testSyncPromises(); void testAsyncPromises(); + void testAsyncPromises2(); void testSyncEach(); void testSyncReduce(); }; @@ -91,6 +92,34 @@ void AsyncTest::testAsyncPromises() QCOMPARE(future.value(), 42); } +void AsyncTest::testAsyncPromises2() +{ + bool done = false; + + auto job = Async::start( + [](Async::Future &future) { + QTimer *timer = new QTimer(); + QObject::connect(timer, &QTimer::timeout, + [&]() { + future.setValue(42); + future.setFinished(); + }); + QObject::connect(timer, &QTimer::timeout, + timer, &QObject::deleteLater); + timer->setSingleShot(true); + timer->start(200); + } + ).then([&done](int result, Async::Future &future) { + done = true; + future.setValue(result); + future.setFinished(); + }); + auto future = job.exec(); + + QTRY_VERIFY(done); + QCOMPARE(future.value(), 42); +} + void AsyncTest::testSyncEach() { auto job = Async::start>( -- cgit v1.2.3