summaryrefslogtreecommitdiffstats
path: root/common/asyncutils.h
diff options
context:
space:
mode:
Diffstat (limited to 'common/asyncutils.h')
-rw-r--r--common/asyncutils.h27
1 files changed, 13 insertions, 14 deletions
diff --git a/common/asyncutils.h b/common/asyncutils.h
index ddcc37c..2cf010e 100644
--- a/common/asyncutils.h
+++ b/common/asyncutils.h
@@ -24,19 +24,18 @@
24#include <QFutureWatcher> 24#include <QFutureWatcher>
25 25
26namespace async { 26namespace async {
27 template<typename T> 27template <typename T>
28 KAsync::Job<T> run(const std::function<T()> &f) 28KAsync::Job<T> run(const std::function<T()> &f)
29 { 29{
30 return KAsync::start<T>([f](KAsync::Future<T> &future) { 30 return KAsync::start<T>([f](KAsync::Future<T> &future) {
31 auto result = QtConcurrent::run(f); 31 auto result = QtConcurrent::run(f);
32 auto watcher = new QFutureWatcher<T>; 32 auto watcher = new QFutureWatcher<T>;
33 watcher->setFuture(result); 33 watcher->setFuture(result);
34 QObject::connect(watcher, &QFutureWatcher<T>::finished, watcher, [&future, watcher]() { 34 QObject::connect(watcher, &QFutureWatcher<T>::finished, watcher, [&future, watcher]() {
35 future.setValue(watcher->future().result()); 35 future.setValue(watcher->future().result());
36 delete watcher; 36 delete watcher;
37 future.setFinished(); 37 future.setFinished();
38 });
39 }); 38 });
40 } 39 });
41 40}
42} 41}