change runnable to lambda
This commit is contained in:
		| @@ -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); | ||||
|     } | ||||
| }; | ||||
|  | ||||
|   | ||||
| @@ -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 | ||||
|   | ||||
| @@ -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) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user