| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 4353b7a commit 2fe8a79
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -676,6 +676,12 @@ void Worker::Ref(const FunctionCallbackInfo<Value>& args) { | |||
| 676 | 676 | } | |
| 677 | 677 | } | |
| 678 | 678 | ||
| 679 | + void Worker::HasRef(const FunctionCallbackInfo<Value>& args) { | ||
| 680 | + Worker* w; | ||
| 681 | + ASSIGN_OR_RETURN_UNWRAP(&w, args.This()); | ||
| 682 | + args.GetReturnValue().Set(w->has_ref_); | ||
| 683 | + } | ||
| 684 | + | ||
| 679 | 685 | void Worker::Unref(const FunctionCallbackInfo<Value>& args) { | |
| 680 | 686 | Worker* w; | |
| 681 | 687 | ASSIGN_OR_RETURN_UNWRAP(&w, args.This()); | |
@@ -838,6 +844,7 @@ void InitWorker(Local<Object> target, | |||
| 838 | 844 | ||
| 839 | 845 | env->SetProtoMethod(w, "startThread", Worker::StartThread); | |
| 840 | 846 | env->SetProtoMethod(w, "stopThread", Worker::StopThread); | |
| 847 | + env->SetProtoMethod(w, "hasRef", Worker::HasRef); | ||
| 841 | 848 | env->SetProtoMethod(w, "ref", Worker::Ref); | |
| 842 | 849 | env->SetProtoMethod(w, "unref", Worker::Unref); | |
| 843 | 850 | env->SetProtoMethod(w, "getResourceLimits", Worker::GetResourceLimits); | |
@@ -901,6 +908,7 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) { | |||
| 901 | 908 | registry->Register(Worker::New); | |
| 902 | 909 | registry->Register(Worker::StartThread); | |
| 903 | 910 | registry->Register(Worker::StopThread); | |
| 911 | + registry->Register(Worker::HasRef); | ||
| 904 | 912 | registry->Register(Worker::Ref); | |
| 905 | 913 | registry->Register(Worker::Unref); | |
| 906 | 914 | registry->Register(Worker::GetResourceLimits); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -60,6 +60,7 @@ class Worker : public AsyncWrap { | |||
| 60 | 60 | static void SetEnvVars(const v8::FunctionCallbackInfo<v8::Value>& args); | |
| 61 | 61 | static void StartThread(const v8::FunctionCallbackInfo<v8::Value>& args); | |
| 62 | 62 | static void StopThread(const v8::FunctionCallbackInfo<v8::Value>& args); | |
| 63 | + static void HasRef(const v8::FunctionCallbackInfo<v8::Value>& args); | ||
| 63 | 64 | static void Ref(const v8::FunctionCallbackInfo<v8::Value>& args); | |
| 64 | 65 | static void Unref(const v8::FunctionCallbackInfo<v8::Value>& args); | |
| 65 | 66 | static void GetResourceLimits( | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,33 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + const common = require('../common'); | ||
| 3 | + | ||
| 4 | + const { Worker } = require('worker_threads'); | ||
| 5 | + const { createHook } = require('async_hooks'); | ||
| 6 | + const { strictEqual } = require('assert'); | ||
| 7 | + | ||
| 8 | + let handle; | ||
| 9 | + | ||
| 10 | + createHook({ | ||
| 11 | + init(asyncId, type, triggerAsyncId, resource) { | ||
| 12 | + if (type === 'WORKER') { | ||
| 13 | + handle = resource; | ||
| 14 | + this.disable(); | ||
| 15 | + } | ||
| 16 | + } | ||
| 17 | + }).enable(); | ||
| 18 | + | ||
| 19 | + const w = new Worker('', { eval: true }); | ||
| 20 | + | ||
| 21 | + strictEqual(handle.hasRef(), true); | ||
| 22 | + w.unref(); | ||
| 23 | + strictEqual(handle.hasRef(), false); | ||
| 24 | + w.ref(); | ||
| 25 | + strictEqual(handle.hasRef(), true); | ||
| 26 | + | ||
| 27 | + w.on('exit', common.mustCall((exitCode) => { | ||
| 28 | + strictEqual(exitCode, 0); | ||
| 29 | + strictEqual(handle.hasRef(), true); | ||
| 30 | + setTimeout(common.mustCall(() => { | ||
| 31 | + strictEqual(handle.hasRef(), undefined); | ||
| 32 | + }), 0); | ||
| 33 | + })); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments