add async call to prepare context

This commit is contained in:
王劲鹏 2021-01-28 18:08:13 +08:00 committed by osborn
parent 93b7cc2457
commit 1592dcb739
7 changed files with 22 additions and 5 deletions

View File

@ -8,7 +8,7 @@ class AsyncCall {
public:
static void ensureRunInThreadPool(QThreadPool &threadPool, QRunnable *runnable)
{
threadPool.start(runnable);
}
};

View File

@ -12,7 +12,7 @@ private:
QString source;
QString script;
QString extra;
InterfaceDriver *driver;
InterfaceDriver *driver = NULL;
public:
Context(QString contextId, QString source, QString extra);

View File

@ -33,7 +33,7 @@ public:
int contextId = counter->fetchAndAddOrdered(1);
Context *context = new Context(QString::number(contextId), source, extra);
contextMap->insert(QString::number(contextId), context);
context->driver->createContext(contextId, script);
context->getDriver()->createContext(QString::number(contextId), script, source);
return context;
}
};

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.11.1, 2021-01-28T10:15:57. -->
<!-- Written by QtCreator 4.11.1, 2021-01-28T17:40:51. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>

View File

@ -10,7 +10,6 @@ class JSEngine : public QObject
{
Q_OBJECT
private:
QThreadPool mJSThreadPool;
InterfaceJSE *mJSE;
void loadBuiltinJS(QString assetName);
@ -18,6 +17,8 @@ private:
QString packageContextScript(QString contextId, QString content);
QString packageModuleScript(QString moduleName, QString content);
public:
QThreadPool mJSThreadPool;
explicit JSEngine(QObject *parent = nullptr);
QJSValue invokeDoricMethod(QString method, QJSValueList arguments);

View File

@ -4,6 +4,8 @@
#include "engine/js_engine.h"
#include "async/async_result.h"
#include "context_manager.h"
#include "utils/utils.h"
int main(int argc, char *argv[])
{
@ -22,5 +24,8 @@ int main(int argc, char *argv[])
JSEngine jsEngine;
QString script = Utils::readAssetFile("doric", "Snake.js");
ContextManager::getInstance()->createContext(script, "", "");
return app.exec();
}

View File

@ -1,4 +1,5 @@
#include "native_driver.h"
#include "async/async_call.h"
void NativeDriver::invokeContextEntityMethod(QString contextId, QString method, QList<QObject> args)
{
@ -12,7 +13,17 @@ 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);
}
void NativeDriver::destroyContext(QString contextId)