From 71aace61b7b1c27ac9296a882b209fe966be5848 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Thu, 23 Jul 2015 19:43:45 +0200 Subject: An easy way to switch between threaded and non-threaded query execution --- common/clientapi.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'common') diff --git a/common/clientapi.cpp b/common/clientapi.cpp index 06bf5ab..c19ea4f 100644 --- a/common/clientapi.cpp +++ b/common/clientapi.cpp @@ -5,12 +5,26 @@ #include "resourcefacade.h" #include "log.h" #include +#define ASYNCINTHREAD +#ifndef ASYNCINTHREAD +#include +#endif namespace async { void run(const std::function &runner) { +#ifndef ASYNCINTHREAD + auto timer = new QTimer(); + timer->setSingleShot(true); + QObject::connect(timer, &QTimer::timeout, [runner, timer]() { + delete timer; + runner(); + }); + timer->start(0); +#else //TODO use a job that runs in a thread? QtConcurrent::run(runner); +#endif }; } // namespace async -- cgit v1.2.3