Skip to content

Commit

Permalink
refactor: simplify Node.js event loop with SpinEventLoop (#37259)
Browse files Browse the repository at this point in the history
refactor: simplify Node.js event loop with SpinEventLoop

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
  • Loading branch information
trop[bot] and codebytere committed Feb 14, 2023
1 parent 5e0014f commit c7e9011
Showing 1 changed file with 3 additions and 31 deletions.
34 changes: 3 additions & 31 deletions shell/app/node_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -256,37 +256,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();

Expand Down

0 comments on commit c7e9011

Please sign in to comment.