diff --git a/src/node.h b/src/node.h index 1e1f2641e02616..88465a763476b7 100644 --- a/src/node.h +++ b/src/node.h @@ -652,6 +652,10 @@ class AsyncResource { async_id get_async_id() const { return async_context_.async_id; } + + async_id get_trigger_async_id() const { + return async_context_.trigger_async_id; + } private: v8::Isolate* isolate_; v8::Persistent resource_; diff --git a/test/addons/async-resource/binding.cc b/test/addons/async-resource/binding.cc index 9a3030c94b22f3..9d3ab37e12a838 100644 --- a/test/addons/async-resource/binding.cc +++ b/test/addons/async-resource/binding.cc @@ -86,6 +86,12 @@ void GetAsyncId(const FunctionCallbackInfo& args) { args.GetReturnValue().Set(r->get_async_id()); } +void GetTriggerAsyncId(const FunctionCallbackInfo& args) { + assert(args[0]->IsExternal()); + auto r = static_cast(args[0].As()->Value()); + args.GetReturnValue().Set(r->get_trigger_async_id()); +} + void GetResource(const FunctionCallbackInfo& args) { assert(args[0]->IsExternal()); auto r = static_cast(args[0].As()->Value()); @@ -99,6 +105,7 @@ void Initialize(Local exports) { NODE_SET_METHOD(exports, "callViaString", CallViaString); NODE_SET_METHOD(exports, "callViaUtf8Name", CallViaUtf8Name); NODE_SET_METHOD(exports, "getAsyncId", GetAsyncId); + NODE_SET_METHOD(exports, "getTriggerAsyncId", GetTriggerAsyncId); NODE_SET_METHOD(exports, "getResource", GetResource); } diff --git a/test/addons/async-resource/test.js b/test/addons/async-resource/test.js index 98cc8f2d3558f3..f19ad58637f187 100644 --- a/test/addons/async-resource/test.js +++ b/test/addons/async-resource/test.js @@ -66,6 +66,7 @@ for (const call of [binding.callViaFunction, assert.strictEqual(ret, 'baz'); assert.strictEqual(binding.getResource(resource), object); assert.strictEqual(binding.getAsyncId(resource), uid); + assert.strictEqual(binding.getTriggerAsyncId(resource), expectedTriggerId); binding.destroyAsyncResource(resource); }