diff options
author | Darshan Sen <raisinten@gmail.com> | 2022-04-20 02:27:14 +0300 |
---|---|---|
committer | Michaƫl Zasso <targos@protonmail.com> | 2022-04-28 07:56:13 +0300 |
commit | c3922afa1c9acad431812a1bd45725ae3410522b (patch) | |
tree | 851fcc72042e15e56f03af6432f8d75b50bf3ece /src/node_worker.cc | |
parent | 7c973474bf24cf58db4f9242e3683514e33a7c71 (diff) |
worker: add hasRef() to the handle object
This should help projects like
https://github.com/mafintosh/why-is-node-running and
https://github.com/facebook/jest to detect if Worker instances are
keeping the event loop active correctly.
Fixes: https://github.com/nodejs/node/issues/42091
Refs: https://github.com/mafintosh/why-is-node-running/issues/59
Signed-off-by: Darshan Sen <raisinten@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/42756
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Diffstat (limited to 'src/node_worker.cc')
-rw-r--r-- | src/node_worker.cc | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/node_worker.cc b/src/node_worker.cc index 04cd60b2453..2a509165c25 100644 --- a/src/node_worker.cc +++ b/src/node_worker.cc @@ -680,6 +680,12 @@ void Worker::Ref(const FunctionCallbackInfo<Value>& args) { } } +void Worker::HasRef(const FunctionCallbackInfo<Value>& args) { + Worker* w; + ASSIGN_OR_RETURN_UNWRAP(&w, args.This()); + args.GetReturnValue().Set(w->has_ref_); +} + void Worker::Unref(const FunctionCallbackInfo<Value>& args) { Worker* w; ASSIGN_OR_RETURN_UNWRAP(&w, args.This()); @@ -842,6 +848,7 @@ void InitWorker(Local<Object> target, env->SetProtoMethod(w, "startThread", Worker::StartThread); env->SetProtoMethod(w, "stopThread", Worker::StopThread); + env->SetProtoMethod(w, "hasRef", Worker::HasRef); env->SetProtoMethod(w, "ref", Worker::Ref); env->SetProtoMethod(w, "unref", Worker::Unref); env->SetProtoMethod(w, "getResourceLimits", Worker::GetResourceLimits); @@ -905,6 +912,7 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) { registry->Register(Worker::New); registry->Register(Worker::StartThread); registry->Register(Worker::StopThread); + registry->Register(Worker::HasRef); registry->Register(Worker::Ref); registry->Register(Worker::Unref); registry->Register(Worker::GetResourceLimits); |