Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2020-03-28 04:46:41 +0300
committerAnna Henningsen <anna@addaleax.net>2020-04-02 18:23:15 +0300
commitd812f16234c80690ee9bdc34f496ae261a7b8530 (patch)
tree9b0fc91344f3643c201fcdd4982dc0996949c235 /src/node_worker.cc
parent7e664a554ac58f84adee7990d3509f128551cc35 (diff)
embedding: provide hook for custom process.exit() behaviour
Embedders may not want to terminate the process when `process.exit()` is called. This provides a hook for more flexible handling of that situation. Refs: https://github.com/nodejs/node/pull/30467#issuecomment-603689644 PR-URL: https://github.com/nodejs/node/pull/32531 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src/node_worker.cc')
-rw-r--r--src/node_worker.cc10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/node_worker.cc b/src/node_worker.cc
index 26c6ce11cef..f81daf284dd 100644
--- a/src/node_worker.cc
+++ b/src/node_worker.cc
@@ -311,6 +311,9 @@ void Worker::Run() {
if (is_stopped()) return;
CHECK_NOT_NULL(env_);
env_->set_env_vars(std::move(env_vars_));
+ SetProcessExitHandler(env_.get(), [this](Environment*, int exit_code) {
+ Exit(exit_code);
+ });
}
{
Mutex::ScopedLock lock(mutex_);
@@ -420,9 +423,10 @@ void Worker::JoinThread() {
MakeCallback(env()->onexit_string(), arraysize(args), args);
}
- // We cleared all libuv handles bound to this Worker above,
- // the C++ object is no longer needed for anything now.
- MakeWeak();
+ // If we get here, the !thread_joined_ condition at the top of the function
+ // implies that the thread was running. In that case, its final action will
+ // be to schedule a callback on the parent thread which will delete this
+ // object, so there's nothing more to do here.
}
Worker::~Worker() {