From 546d86aae7cd0b9766f3a0ea73f3777334d55814 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Tue, 31 Jan 2017 17:32:45 +0100 Subject: A model stress test to try to crash the result emitter when used with threads. --- common/asyncutils.h | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'common') diff --git a/common/asyncutils.h b/common/asyncutils.h index 2cf010e..6cbcee8 100644 --- a/common/asyncutils.h +++ b/common/asyncutils.h @@ -25,17 +25,23 @@ namespace async { template -KAsync::Job run(const std::function &f) +KAsync::Job run(const std::function &f, bool runAsync = true) { - return KAsync::start([f](KAsync::Future &future) { - auto result = QtConcurrent::run(f); - auto watcher = new QFutureWatcher; - watcher->setFuture(result); - QObject::connect(watcher, &QFutureWatcher::finished, watcher, [&future, watcher]() { - future.setValue(watcher->future().result()); - delete watcher; - future.setFinished(); + if (runAsync) { + return KAsync::start([f](KAsync::Future &future) { + auto result = QtConcurrent::run(f); + auto watcher = new QFutureWatcher; + watcher->setFuture(result); + QObject::connect(watcher, &QFutureWatcher::finished, watcher, [&future, watcher]() { + future.setValue(watcher->future().result()); + delete watcher; + future.setFinished(); + }); }); - }); + } else { + return KAsync::syncStart([f]() { + return f(); + }); + } } } -- cgit v1.2.3