Skip to content

Commit

Permalink
[squash] add AsyncResource::get_trigger_async_id
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreasMadsen committed Jul 5, 2017
1 parent 98b5e9b commit 48ef6a2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<v8::Object> resource_;
Expand Down
7 changes: 7 additions & 0 deletions test/addons/async-resource/binding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ void GetAsyncId(const FunctionCallbackInfo<Value>& args) {
args.GetReturnValue().Set(r->get_async_id());
}

void GetTriggerAsyncId(const FunctionCallbackInfo<Value>& args) {
assert(args[0]->IsExternal());
auto r = static_cast<AsyncResource*>(args[0].As<External>()->Value());
args.GetReturnValue().Set(r->get_trigger_async_id());
}

void GetResource(const FunctionCallbackInfo<Value>& args) {
assert(args[0]->IsExternal());
auto r = static_cast<AsyncResource*>(args[0].As<External>()->Value());
Expand All @@ -99,6 +105,7 @@ void Initialize(Local<Object> 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);
}

Expand Down
1 change: 1 addition & 0 deletions test/addons/async-resource/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 48ef6a2

Please sign in to comment.