#ifndef ASYNC_CALL_H
#define ASYNC_CALL_H
#include <QFuture>
#include <QThreadPool>
#include <QtConcurrent/QtConcurrent>
#include "DoricAsyncResult.h"
class DoricAsyncCall {
public:
template <typename Function>
static std::shared_ptr<DoricAsyncResult>
ensureRunInThreadPool(QThreadPool *threadPool, Function &&function) {
std::shared_ptr<DoricAsyncResult> asyncResult =
std::make_shared<DoricAsyncResult>();
Function lambda = std::forward<Function>(function);
QtConcurrent::run(threadPool, [lambda, asyncResult]() {
lambda();
// asyncResult->setResult(result);
});
return asyncResult;
}
ensureRunInMain(Function &&function, QThread *thread = qApp->thread()) {
auto *obj = QAbstractEventDispatcher::instance(thread);
Q_ASSERT(obj);
QMetaObject::invokeMethod(obj, [lambda, asyncResult]() {
};
#endif // ASYNC_CALL_H