diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-04-28 09:45:26 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-04-28 09:45:26 +0200 |
commit | 3012dc36bbc40e6f8c07a6af7b2fba9d6c826399 (patch) | |
tree | c895b04f3b974a28a2b156b36cc9f8c4cd854bbe | |
parent | c5595c71f6db276513d5158ccef23c2c7d8d0834 (diff) | |
download | sink-3012dc36bbc40e6f8c07a6af7b2fba9d6c826399.tar.gz sink-3012dc36bbc40e6f8c07a6af7b2fba9d6c826399.zip |
Async: Nested job error propagation.
-rw-r--r-- | async/autotests/asynctest.cpp | 23 | ||||
-rw-r--r-- | async/src/async.h | 6 |
2 files changed, 28 insertions, 1 deletions
diff --git a/async/autotests/asynctest.cpp b/async/autotests/asynctest.cpp index 9789950..9bc9f6b 100644 --- a/async/autotests/asynctest.cpp +++ b/async/autotests/asynctest.cpp | |||
@@ -68,6 +68,7 @@ private Q_SLOTS: | |||
68 | void testErrorPropagation(); | 68 | void testErrorPropagation(); |
69 | void testErrorHandlerAsync(); | 69 | void testErrorHandlerAsync(); |
70 | void testErrorPropagationAsync(); | 70 | void testErrorPropagationAsync(); |
71 | void testNestedErrorPropagation(); | ||
71 | 72 | ||
72 | void testChainingRunningJob(); | 73 | void testChainingRunningJob(); |
73 | void testChainingFinishedJob(); | 74 | void testChainingFinishedJob(); |
@@ -688,6 +689,28 @@ void AsyncTest::testErrorPropagationAsync() | |||
688 | QCOMPARE(error, 1); | 689 | QCOMPARE(error, 1); |
689 | } | 690 | } |
690 | 691 | ||
692 | void AsyncTest::testNestedErrorPropagation() | ||
693 | { | ||
694 | int error = 0; | ||
695 | auto job = Async::start<void>([](){}) | ||
696 | .then<void>(Async::error<void>(1, "error")) //Nested job that throws error | ||
697 | .then<void>([](Async::Future<void> &future) { | ||
698 | //We should never get here | ||
699 | Q_ASSERT(false); | ||
700 | }, | ||
701 | [&error](int errorCode, const QString &errorMessage) { | ||
702 | error += errorCode; | ||
703 | } | ||
704 | ); | ||
705 | auto future = job.exec(); | ||
706 | |||
707 | future.waitForFinished(); | ||
708 | |||
709 | QVERIFY(future.isFinished()); | ||
710 | QCOMPARE(future.errorCode(), 1); | ||
711 | QCOMPARE(future.errorMessage(), QString::fromLatin1("error")); | ||
712 | QCOMPARE(error, 1); | ||
713 | } | ||
691 | 714 | ||
692 | 715 | ||
693 | 716 | ||
diff --git a/async/src/async.h b/async/src/async.h index d6a74c0..18b5979 100644 --- a/async/src/async.h +++ b/async/src/async.h | |||
@@ -514,7 +514,11 @@ private: | |||
514 | // copy by value is const | 514 | // copy by value is const |
515 | auto outFuture = future; | 515 | auto outFuture = future; |
516 | Async::detail::copyFutureValue(watcher->future(), outFuture); | 516 | Async::detail::copyFutureValue(watcher->future(), outFuture); |
517 | outFuture.setFinished(); | 517 | if (watcher->future().errorCode()) { |
518 | outFuture.setError(watcher->future().errorCode(), watcher->future().errorMessage()); | ||
519 | } else { | ||
520 | outFuture.setFinished(); | ||
521 | } | ||
518 | delete watcher; | 522 | delete watcher; |
519 | }); | 523 | }); |
520 | watcher->setFuture(job.exec(in ...)); | 524 | watcher->setFuture(job.exec(in ...)); |