Skip to content

Use Nan::AsyncResource #41

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions src/GNContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,9 @@ void GNContext::Callback(getdns_context *context,
}
Nan::TryCatch try_catch;
argv[2] = GNUtil::convertToBuffer(&transId, 8);
data->callback->Call(Nan::GetCurrentContext()->Global(), 3, argv);

Nan::AsyncResource callbackAsyncResource("(getdns-node) GNContext::Callback");
data->callback->Call(Nan::GetCurrentContext()->Global(), 3, argv, &callbackAsyncResource);

if (try_catch.HasCaught())
Nan::FatalException(try_catch);
Expand Down Expand Up @@ -874,7 +876,8 @@ NAN_METHOD(GNContext::Lookup) {
if (!ctx || !ctx->context_) {
Local<Value> err = makeErrorObj("Context is invalid", GETDNS_RETURN_GENERIC_ERROR);
Local<Value> cbArgs[] = { err };
Nan::MakeCallback(Nan::GetCurrentContext()->Global(), localCb, 1, cbArgs);
Nan::AsyncResource lookupAsyncResource("(getdns-node) GNContext::Lookup (Context is invalid)");
lookupAsyncResource.runInAsyncScope(Nan::GetCurrentContext()->Global(), localCb, 1, cbArgs);
return;
}
// take first arg and make it a string
Expand All @@ -883,7 +886,8 @@ NAN_METHOD(GNContext::Lookup) {
if (!info[1]->IsNumber()) {
Local<Value> err = makeErrorObj("Second argument must be a number", GETDNS_RETURN_INVALID_PARAMETER);
Local<Value> cbArgs[] = { err };
Nan::MakeCallback(Nan::GetCurrentContext()->Global(), localCb, 1, cbArgs);
Nan::AsyncResource lookupAsyncResource("(getdns-node) GNContext::Lookup (Second argument must be a number)");
lookupAsyncResource.runInAsyncScope(Nan::GetCurrentContext()->Global(), localCb, 1, cbArgs);
return;
}
uint16_t type = (uint16_t) Nan::To<uint32_t>(info[1]).FromJust();
Expand Down Expand Up @@ -913,7 +917,8 @@ NAN_METHOD(GNContext::Lookup) {

Local<Value> err = makeErrorObj("Error issuing query", r);
Local<Value> cbArgs[] = { err };
Nan::MakeCallback(Nan::GetCurrentContext()->Global(), localCb, 1, cbArgs);
Nan::AsyncResource lookupAsyncResource("(getdns-node) GNContext::Lookup (Error issuing query)");
lookupAsyncResource.runInAsyncScope(Nan::GetCurrentContext()->Global(), localCb, 1, cbArgs);
return;
}
// done.
Expand All @@ -939,7 +944,8 @@ NAN_METHOD(GNContext::HelperLookup) {
if (!ctx || !ctx->context_) {
Local<Value> err = makeErrorObj("Context is invalid", GETDNS_RETURN_GENERIC_ERROR);
Local<Value> cbArgs[] = { err };
Nan::Call(localCb, Nan::GetCurrentContext()->Global(), 1, cbArgs);
Nan::AsyncResource helperLookupAsyncResource("(getdns-node) GNContext::HelperLookup (Context is invalid)");
helperLookupAsyncResource.runInAsyncScope(Nan::GetCurrentContext()->Global(), localCb, 1, cbArgs);
return;
}
// take first arg and make it a string
Expand Down Expand Up @@ -989,7 +995,8 @@ NAN_METHOD(GNContext::HelperLookup) {

Local<Value> err = makeErrorObj("Error issuing query", r);
Local<Value> cbArgs[] = { err };
Nan::MakeCallback(Nan::GetCurrentContext()->Global(), localCb, 1, cbArgs);
Nan::AsyncResource helperLookupAsyncResource("(getdns-node) GNContext::HelperLookup (Error issuing query)");
helperLookupAsyncResource.runInAsyncScope(Nan::GetCurrentContext()->Global(), localCb, 1, cbArgs);
return;
}
// done. return as buffer
Expand Down