diff options
author | Anna Henningsen <anna@addaleax.net> | 2020-10-11 16:13:19 +0300 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2020-10-14 21:08:19 +0300 |
commit | 9fd6122659c4067b0d8bd2c590f4ba01b48c93a3 (patch) | |
tree | 89cdbb73d84f5ae87e1399f95aa0fba392b43f7f /src/node_worker.cc | |
parent | ef1645e2b3f609492af7f25e4468db9b7801f4aa (diff) |
src: add embedding helpers to reduce boilerplate code
Provide helpers for a) spinning the event loop and
b) setting up and tearing down the objects involved in a single
Node.js instance, as they would typically be used.
The former helper is also usable inside Node.js itself,
for both Worker and main threads.
PR-URL: https://github.com/nodejs/node/pull/35597
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
Diffstat (limited to 'src/node_worker.cc')
-rw-r--r-- | src/node_worker.cc | 40 |
1 files changed, 5 insertions, 35 deletions
diff --git a/src/node_worker.cc b/src/node_worker.cc index cdaeefb7897..2006380cd41 100644 --- a/src/node_worker.cc +++ b/src/node_worker.cc @@ -27,6 +27,7 @@ using v8::Integer; using v8::Isolate; using v8::Local; using v8::Locker; +using v8::Maybe; using v8::MaybeLocal; using v8::Null; using v8::Number; @@ -332,45 +333,14 @@ void Worker::Run() { Debug(this, "Loaded environment for worker %llu", thread_id_.id); } - - if (is_stopped()) return; - { - SealHandleScope seal(isolate_); - bool more; - env_->performance_state()->Mark( - node::performance::NODE_PERFORMANCE_MILESTONE_LOOP_START); - do { - if (is_stopped()) break; - uv_run(&data.loop_, UV_RUN_DEFAULT); - if (is_stopped()) break; - - platform_->DrainTasks(isolate_); - - more = uv_loop_alive(&data.loop_); - if (more && !is_stopped()) continue; - - if (EmitProcessBeforeExit(env_.get()).IsNothing()) - break; - - // Emit `beforeExit` if the loop became alive either after emitting - // event, or after running some callbacks. - more = uv_loop_alive(&data.loop_); - } while (more == true && !is_stopped()); - env_->performance_state()->Mark( - node::performance::NODE_PERFORMANCE_MILESTONE_LOOP_EXIT); - } } { - int exit_code; - bool stopped = is_stopped(); - if (!stopped) { - env_->VerifyNoStrongBaseObjects(); - exit_code = EmitProcessExit(env_.get()).FromMaybe(1); - } + Maybe<int> exit_code = SpinEventLoop(env_.get()); Mutex::ScopedLock lock(mutex_); - if (exit_code_ == 0 && !stopped) - exit_code_ = exit_code; + if (exit_code_ == 0 && exit_code.IsJust()) { + exit_code_ = exit_code.FromJust(); + } Debug(this, "Exiting thread for worker %llu with exit code %d", thread_id_.id, exit_code_); |