refactor: simplify Node.js event loop with SpinEventLoop (#34884)

refactor: simplify Node.js event loop with SpinEventLoop
This commit is contained in:
Shelley Vohr 2023-02-14 08:54:09 +00:00 committed by GitHub
parent a38b711fb1
commit 2e8114aea3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -260,37 +260,9 @@ int NodeMain(int argc, char* argv[]) {
v8::HandleScope scope(isolate);
node::LoadEnvironment(env, node::StartExecutionCallback{});
env->set_trace_sync_io(env->options()->trace_sync_io);
{
v8::SealHandleScope seal(isolate);
bool more;
env->performance_state()->Mark(
node::performance::NODE_PERFORMANCE_MILESTONE_LOOP_START);
do {
uv_run(env->event_loop(), UV_RUN_DEFAULT);
gin_env.platform()->DrainTasks(isolate);
more = uv_loop_alive(env->event_loop());
if (more && !env->is_stopping())
continue;
if (!uv_loop_alive(env->event_loop())) {
EmitBeforeExit(env);
}
// Emit `beforeExit` if the loop became alive either after emitting
// event, or after running some callbacks.
more = uv_loop_alive(env->event_loop());
} while (more && !env->is_stopping());
env->performance_state()->Mark(
node::performance::NODE_PERFORMANCE_MILESTONE_LOOP_EXIT);
}
env->set_trace_sync_io(false);
exit_code = node::EmitExit(env);
// Potential reasons we get Nothing here may include: the env
// is stopping, or the user hooks process.emit('exit').
exit_code = node::SpinEventLoop(env).FromMaybe(1);
node::ResetStdio();