refactor: update node main instance management (#21562)
This commit is contained in:
parent
58b816431d
commit
087cb1d592
1 changed files with 25 additions and 13 deletions
|
@ -116,28 +116,40 @@ int NodeMain(int argc, char* argv[]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
node::LoadEnvironment(env);
|
node::LoadEnvironment(env);
|
||||||
|
v8::Isolate* isolate = env->isolate();
|
||||||
|
|
||||||
bool more;
|
{
|
||||||
do {
|
v8::SealHandleScope seal(isolate);
|
||||||
more = uv_run(env->event_loop(), UV_RUN_ONCE);
|
bool more;
|
||||||
gin_env.platform()->DrainTasks(env->isolate());
|
do {
|
||||||
if (more == false) {
|
uv_run(env->event_loop(), UV_RUN_DEFAULT);
|
||||||
node::EmitBeforeExit(env);
|
|
||||||
|
gin_env.platform()->DrainTasks(env->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
|
// Emit `beforeExit` if the loop became alive either after emitting
|
||||||
// event, or after running some callbacks.
|
// event, or after running some callbacks.
|
||||||
more = uv_loop_alive(env->event_loop());
|
more = uv_loop_alive(env->event_loop());
|
||||||
if (uv_run(env->event_loop(), UV_RUN_NOWAIT) != 0)
|
} while (more && !env->is_stopping());
|
||||||
more = true;
|
}
|
||||||
}
|
|
||||||
} while (more == true);
|
|
||||||
|
|
||||||
node_debugger.Stop();
|
node_debugger.Stop();
|
||||||
exit_code = node::EmitExit(env);
|
exit_code = node::EmitExit(env);
|
||||||
env->set_can_call_into_js(false);
|
|
||||||
node::RunAtExit(env);
|
|
||||||
|
|
||||||
v8::Isolate* isolate = env->isolate();
|
node::ResetStdio();
|
||||||
|
|
||||||
|
env->set_can_call_into_js(false);
|
||||||
|
env->stop_sub_worker_contexts();
|
||||||
|
env->RunCleanup();
|
||||||
|
|
||||||
|
node::RunAtExit(env);
|
||||||
node::FreeEnvironment(env);
|
node::FreeEnvironment(env);
|
||||||
node::FreeIsolateData(isolate_data);
|
node::FreeIsolateData(isolate_data);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue