Fix dispatching when app (or thread) terminated

Make sure to **not** notify handlers if the captured thread doesn't exist anymore, which would potentially result in dispatching to the wrong thread (ie. nullptr == current thread). This also applies when the app is shutting down and the even loop is not anymore available. In both cases, we should not trigger any error and skip notifications.
This commit is contained in:
Simon Brunel
2018-02-24 12:31:03 +01:00
parent f794916be6
commit 313d3882d7
2 changed files with 30 additions and 7 deletions

View File

@ -261,9 +261,9 @@ void tst_future::fail()
QString result;
auto input = QPromise<QString>::reject(MyException("bar"));
auto output = input.fail([](const MyException& e) {
return QtConcurrent::run([=]() {
return QString("foo%1").arg(e.error());
});
return QtConcurrent::run([](const QString& error) {
return QString("foo%1").arg(error);
}, e.error());
});
QCOMPARE(input.isRejected(), true);
@ -282,9 +282,9 @@ void tst_future::fail_void()
QString result;
auto input = QPromise<void>::reject(MyException("bar"));
auto output = input.fail([&](const MyException& e) {
return QtConcurrent::run([&]() {
result = e.error();
});
return QtConcurrent::run([&](const QString& error) {
result = error;
}, e.error());
});
QCOMPARE(input.isRejected(), true);