change runnable to lambda
This commit is contained in:
parent
1592dcb739
commit
21b3353e18
@ -2,13 +2,14 @@
|
|||||||
#define ASYNC_CALL_H
|
#define ASYNC_CALL_H
|
||||||
|
|
||||||
#include <QThreadPool>
|
#include <QThreadPool>
|
||||||
|
#include <QtConcurrent/QtConcurrent>
|
||||||
|
|
||||||
class AsyncCall {
|
class AsyncCall {
|
||||||
|
|
||||||
public:
|
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;
|
InterfaceJSE *mJSE;
|
||||||
|
|
||||||
void loadBuiltinJS(QString assetName);
|
void loadBuiltinJS(QString assetName);
|
||||||
void prepareContext(QString contextId, QString script, QString source);
|
|
||||||
QString packageContextScript(QString contextId, QString content);
|
QString packageContextScript(QString contextId, QString content);
|
||||||
QString packageModuleScript(QString moduleName, QString content);
|
QString packageModuleScript(QString moduleName, QString content);
|
||||||
public:
|
public:
|
||||||
@ -21,9 +20,10 @@ public:
|
|||||||
|
|
||||||
explicit JSEngine(QObject *parent = nullptr);
|
explicit JSEngine(QObject *parent = nullptr);
|
||||||
|
|
||||||
QJSValue invokeDoricMethod(QString method, QJSValueList arguments);
|
|
||||||
|
|
||||||
~JSEngine();
|
~JSEngine();
|
||||||
|
|
||||||
|
QJSValue invokeDoricMethod(QString method, QJSValueList arguments);
|
||||||
|
void prepareContext(QString contextId, QString script, QString source);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // JSENGINE_H
|
#endif // JSENGINE_H
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
#include "native_driver.h"
|
#include "native_driver.h"
|
||||||
#include "async/async_call.h"
|
#include "async/async_call.h"
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
void NativeDriver::invokeContextEntityMethod(QString contextId, QString method, QList<QObject> args)
|
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)
|
void NativeDriver::createContext(QString contextId, QString script, QString source)
|
||||||
{
|
{
|
||||||
class Runnable: public QRunnable
|
AsyncCall::ensureRunInThreadPool(&jsEngine.mJSThreadPool, [this, contextId, script, source]{
|
||||||
{
|
this->jsEngine.prepareContext(contextId, script, source);
|
||||||
void run() override
|
});
|
||||||
{
|
|
||||||
qDebug() << "123";
|
|
||||||
}
|
|
||||||
};
|
|
||||||
Runnable *runnable = new Runnable();
|
|
||||||
runnable->setAutoDelete(true);
|
|
||||||
|
|
||||||
AsyncCall::ensureRunInThreadPool(jsEngine.mJSThreadPool, runnable);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void NativeDriver::destroyContext(QString contextId)
|
void NativeDriver::destroyContext(QString contextId)
|
||||||
|
Reference in New Issue
Block a user