diff options
author | Gireesh Punathil <gpunathi@in.ibm.com> | 2018-06-12 09:01:46 -0400 |
---|---|---|
committer | Gireesh Punathil <gpunathi@in.ibm.com> | 2019-03-16 12:50:26 +0530 |
commit | d35af56e5f3b1334c4360dbf8a013d0c522fe5f8 (patch) | |
tree | a6f9bb5467ec693c04d6741c3704a7c80a4eb482 /src/node.cc | |
parent | 22de2cfb71f3f1ab63e9663f4aa62bd9016b762a (diff) | |
download | android-node-v8-d35af56e5f3b1334c4360dbf8a013d0c522fe5f8.tar.gz android-node-v8-d35af56e5f3b1334c4360dbf8a013d0c522fe5f8.tar.bz2 android-node-v8-d35af56e5f3b1334c4360dbf8a013d0c522fe5f8.zip |
src: shutdown node in-flight
This commit introduces a `node::Stop()` API.
An identified use case for embedders is their ability to tear down
Node while it is still running (event loop contain pending events)
Here the assumptions are that (i) embedders do not wish to resort to
JS routines to initiate shutdown (ii) embedders have the Environment
handle handy. (iii) embedders stop Node through a second thread.
Fixes: https://github.com/nodejs/node/issues/19365
Refs: https://github.com/nodejs/user-feedback/issues/51
PR-URL: https://github.com/nodejs/node/pull/21283
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Michael Dawson <Michael_Dawson@ca.ibm.com>
Diffstat (limited to 'src/node.cc')
-rw-r--r-- | src/node.cc | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/node.cc b/src/node.cc index adcd6f6cad..783962d192 100644 --- a/src/node.cc +++ b/src/node.cc @@ -832,15 +832,14 @@ inline int StartNodeWithIsolate(Isolate* isolate, per_process::v8_platform.DrainVMTasks(isolate); more = uv_loop_alive(env.event_loop()); - if (more) - continue; + if (more && !env.GetAsyncRequest()->IsStopped()) continue; RunBeforeExit(&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 == true); + } while (more == true && !env.GetAsyncRequest()->IsStopped()); env.performance_state()->Mark( node::performance::NODE_PERFORMANCE_MILESTONE_LOOP_EXIT); } @@ -977,6 +976,11 @@ int Start(int argc, char** argv) { return exit_code; } +int Stop(Environment* env) { + env->ExitEnv(); + return 0; +} + } // namespace node #if !HAVE_INSPECTOR |