Skip to content

Commit d970ed9

Browse files
committed
fix: ensure microtasks are executed automatically #10
1 parent d38ca1f commit d970ed9

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/legacy/main/NodeJsHelper.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,13 +313,21 @@ bool loadPluginCode(script::ScriptEngine* engine, std::string entryScriptPath, s
313313
// Start libuv event loop
314314
uvLoopTask.push_back(env);
315315
ll::coro::keepThis(
316-
[engine, env, isRunningMap{&isRunning}, eventLoop{it->second->event_loop()}]() -> ll::coro::CoroTask<> {
316+
[engine,
317+
env,
318+
isolate{it->second->isolate()},
319+
isRunningMap{&isRunning},
320+
eventLoop{it->second->event_loop()}]() -> ll::coro::CoroTask<> {
317321
using namespace ll::chrono_literals;
318322
while (std::find(uvLoopTask.begin(), uvLoopTask.end(), env) != uvLoopTask.end()) {
319323
co_await 2_tick;
320324
if (!(ll::getGamingStatus() != ll::GamingStatus::Running) && (*isRunningMap)[env]) {
321325
EngineScope enter(engine);
326+
// v8::MicrotasksScope microtaskScope(isolate, v8::MicrotasksScope::kRunMicrotasks);
322327
uv_run(eventLoop, UV_RUN_NOWAIT);
328+
// Manually perform microtasks because default MicrotasksPolicy is kExplicit
329+
isolate->PerformMicrotaskCheckpoint();
330+
// Or change MicrotasksPolicy to kScope and enter MicrotasksScope before uv_run
323331
}
324332
if ((ll::getGamingStatus() != ll::GamingStatus::Running)) {
325333
uv_stop(eventLoop);

0 commit comments

Comments
 (0)