summaryrefslogtreecommitdiffstats
path: root/common/asyncutils.h
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2017-01-31 17:32:45 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2017-01-31 19:38:57 +0100
commit546d86aae7cd0b9766f3a0ea73f3777334d55814 (patch)
tree58667b891038926e732e1b6fd9b50a8433bf465b /common/asyncutils.h
parent871a048580d5a464fb697713a5e0e2c52dee5208 (diff)
downloadsink-546d86aae7cd0b9766f3a0ea73f3777334d55814.tar.gz
sink-546d86aae7cd0b9766f3a0ea73f3777334d55814.zip
A model stress test to try to crash the result emitter when used with
threads.
Diffstat (limited to 'common/asyncutils.h')
-rw-r--r--common/asyncutils.h26
1 files changed, 16 insertions, 10 deletions
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 @@
25 25
26namespace async { 26namespace async {
27template <typename T> 27template <typename T>
28KAsync::Job<T> run(const std::function<T()> &f) 28KAsync::Job<T> run(const std::function<T()> &f, bool runAsync = true)
29{ 29{
30 return KAsync::start<T>([f](KAsync::Future<T> &future) { 30 if (runAsync) {
31 auto result = QtConcurrent::run(f); 31 return KAsync::start<T>([f](KAsync::Future<T> &future) {
32 auto watcher = new QFutureWatcher<T>; 32 auto result = QtConcurrent::run(f);
33 watcher->setFuture(result); 33 auto watcher = new QFutureWatcher<T>;
34 QObject::connect(watcher, &QFutureWatcher<T>::finished, watcher, [&future, watcher]() { 34 watcher->setFuture(result);
35 future.setValue(watcher->future().result()); 35 QObject::connect(watcher, &QFutureWatcher<T>::finished, watcher, [&future, watcher]() {
36 delete watcher; 36 future.setValue(watcher->future().result());
37 future.setFinished(); 37 delete watcher;
38 future.setFinished();
39 });
38 }); 40 });
39 }); 41 } else {
42 return KAsync::syncStart<T>([f]() {
43 return f();
44 });
45 }
40} 46}
41} 47}