change runnable to lambda

This commit is contained in:
王劲鹏 2021-01-28 19:44:06 +08:00 committed by osborn
parent 1592dcb739
commit 21b3353e18
3 changed files with 11 additions and 16 deletions

View File

@ -2,13 +2,14 @@
#define ASYNC_CALL_H
#include <QThreadPool>
#include <QtConcurrent/QtConcurrent>
class AsyncCall {
public:
static void ensureRunInThreadPool(QThreadPool &threadPool, QRunnable *runnable)
static void ensureRunInThreadPool(QThreadPool *threadPool, std::function<void()> lambda)
{
threadPool.start(runnable);
QtConcurrent::run(threadPool, lambda);
}
};

View File

@ -13,7 +13,6 @@ private:
InterfaceJSE *mJSE;
void loadBuiltinJS(QString assetName);
void prepareContext(QString contextId, QString script, QString source);
QString packageContextScript(QString contextId, QString content);
QString packageModuleScript(QString moduleName, QString content);
public:
@ -21,9 +20,10 @@ public:
explicit JSEngine(QObject *parent = nullptr);
QJSValue invokeDoricMethod(QString method, QJSValueList arguments);
~JSEngine();
QJSValue invokeDoricMethod(QString method, QJSValueList arguments);
void prepareContext(QString contextId, QString script, QString source);
};
#endif // JSENGINE_H

View File

@ -1,6 +1,8 @@
#include "native_driver.h"
#include "async/async_call.h"
#include <functional>
void NativeDriver::invokeContextEntityMethod(QString contextId, QString method, QList<QObject> args)
{
@ -13,17 +15,9 @@ void NativeDriver::invokeDoricMethod(QString method, QList<QObject> args)
void NativeDriver::createContext(QString contextId, QString script, QString source)
{
class Runnable: public QRunnable
{
void run() override
{
qDebug() << "123";
}
};
Runnable *runnable = new Runnable();
runnable->setAutoDelete(true);
AsyncCall::ensureRunInThreadPool(jsEngine.mJSThreadPool, runnable);
AsyncCall::ensureRunInThreadPool(&jsEngine.mJSThreadPool, [this, contextId, script, source]{
this->jsEngine.prepareContext(contextId, script, source);
});
}
void NativeDriver::destroyContext(QString contextId)