diff --git a/doric-Qt/doric/async/async_call.h b/doric-Qt/doric/async/async_call.h index c945c06a..117ee5cc 100644 --- a/doric-Qt/doric/async/async_call.h +++ b/doric-Qt/doric/async/async_call.h @@ -2,13 +2,14 @@ #define ASYNC_CALL_H #include +#include class AsyncCall { public: - static void ensureRunInThreadPool(QThreadPool &threadPool, QRunnable *runnable) + static void ensureRunInThreadPool(QThreadPool *threadPool, std::function lambda) { - threadPool.start(runnable); + QtConcurrent::run(threadPool, lambda); } }; diff --git a/doric-Qt/doric/engine/js_engine.h b/doric-Qt/doric/engine/js_engine.h index 4a6dabd6..7eefa1d7 100644 --- a/doric-Qt/doric/engine/js_engine.h +++ b/doric-Qt/doric/engine/js_engine.h @@ -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 diff --git a/doric-Qt/doric/native_driver.cpp b/doric-Qt/doric/native_driver.cpp index 5404b425..497d12ce 100644 --- a/doric-Qt/doric/native_driver.cpp +++ b/doric-Qt/doric/native_driver.cpp @@ -1,6 +1,8 @@ #include "native_driver.h" #include "async/async_call.h" +#include + void NativeDriver::invokeContextEntityMethod(QString contextId, QString method, QList args) { @@ -13,17 +15,9 @@ void NativeDriver::invokeDoricMethod(QString method, QList 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)