refactor: simplify Node.js event loop with SpinEventLoop
(#34884)
refactor: simplify Node.js event loop with SpinEventLoop
This commit is contained in:
parent
a38b711fb1
commit
2e8114aea3
1 changed files with 3 additions and 31 deletions
|
@ -260,37 +260,9 @@ int NodeMain(int argc, char* argv[]) {
|
||||||
v8::HandleScope scope(isolate);
|
v8::HandleScope scope(isolate);
|
||||||
node::LoadEnvironment(env, node::StartExecutionCallback{});
|
node::LoadEnvironment(env, node::StartExecutionCallback{});
|
||||||
|
|
||||||
env->set_trace_sync_io(env->options()->trace_sync_io);
|
// 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);
|
||||||
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);
|
|
||||||
|
|
||||||
node::ResetStdio();
|
node::ResetStdio();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue