5#ifndef TASKING_CONCURRENTCALL_H
6#define TASKING_CONCURRENTCALL_H
21#include <QtConcurrent/QtConcurrent>
32template <
typename ResultType>
39 template <
typename Function,
typename ...Args>
42 return wrapConcurrent(std::forward<Function>(function), std::forward<Args>(
args)...);
53 QFuture<ResultType>
future()
const {
return m_future; }
56 template <
typename Function,
typename ...Args>
59 m_startHandler = [
this, function = std::forward<Function>(function),
args...] {
65 template <
typename Function,
typename ...Args>
66 void wrapConcurrent(std::reference_wrapper<const Function> &&
wrapper, Args &&...
args)
68 m_startHandler = [
this,
wrapper = std::forward<std::reference_wrapper<const Function>>(
wrapper),
args...] {
78 std::function<QFuture<ResultType>()> m_startHandler;
80 QFuture<ResultType> m_future;
83template <
typename ResultType>
90 m_watcher->waitForFinished();
95 if (!this->
task()->m_startHandler) {
99 m_watcher.reset(
new QFutureWatcher<ResultType>);
101 emit this->done(toDoneResult(!m_watcher->isCanceled()));
102 m_watcher.release()->deleteLater();
104 this->
task()->m_future = this->
task()->m_startHandler();
105 m_watcher->setFuture(this->
task()->m_future);
109 std::unique_ptr<QFutureWatcher<ResultType>> m_watcher;
QList< T > results() const
static QThreadPool * globalInstance()
Returns the global QThreadPool instance.
void start() final
This method is called by the running TaskTree for starting the Task instance.
~ConcurrentCallTaskAdapter()
void setThreadPool(QThreadPool *pool)
QFuture< ResultType > future() const
QList< ResultType > results() const
ResultType result() const
void setConcurrentCallData(Function &&function, Args &&...args)
\inheaderfile solutions/tasking/tasktree.h \inmodule TaskingSolution
Combined button and popup list for selecting options.
QTCONCURRENT_RUN_NODISCARD auto run(QThreadPool *pool, Function &&f, Args &&...args)
\inmodule TaskingSolution
CustomTask< ConcurrentCallTaskAdapter< T > > ConcurrentCallTask
connect(quitButton, &QPushButton::clicked, &app, &QCoreApplication::quit, Qt::QueuedConnection)