forked from BabylonJS/JsRuntimeHost
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppRuntime.cpp
More file actions
65 lines (58 loc) · 1.58 KB
/
AppRuntime.cpp
File metadata and controls
65 lines (58 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "AppRuntime.h"
#include "WorkQueue.h"
#include <cassert>
namespace Babylon
{
AppRuntime::AppRuntime() :
AppRuntime{{}}
{
}
AppRuntime::AppRuntime(Options options)
: m_workQueue{std::make_unique<WorkQueue>([this] { RunPlatformTier(); })}
, m_options{std::move(options)}
{
Dispatch([this](Napi::Env env) {
JsRuntime::CreateForJavaScript(env, [this](auto func) { Dispatch(std::move(func)); });
});
}
AppRuntime::~AppRuntime()
{
}
void AppRuntime::Run(Napi::Env env)
{
m_workQueue->Run(env);
}
void AppRuntime::Suspend()
{
m_workQueue->Suspend();
}
void AppRuntime::Resume()
{
m_workQueue->Resume();
}
void AppRuntime::Dispatch(Dispatchable<void(Napi::Env)> func)
{
m_workQueue->Append([this, func{std::move(func)}](Napi::Env env) mutable {
Execute([this, env, func{std::move(func)}]() mutable {
try
{
func(env);
if (env.IsExceptionPending())
{
auto error = env.GetAndClearPendingException();
m_options.UnhandledExceptionHandler(error);
}
}
catch (const Napi::Error& error)
{
m_options.UnhandledExceptionHandler(error);
}
catch (...)
{
assert(false);
std::abort();
}
});
});
}
}