Skip to content
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

Add resource_name and resource parameters to AsyncWorker constructor #253

Closed
wants to merge 1 commit into from

Conversation

romandev
Copy link
Contributor

This PR is initiated from #140 (comment).

napi.h Outdated
AsyncWorker(const Object& receiver,
const Function& callback,
const char* resource_name,
const Object& resource);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good but do we need to add explicit (like there was for the existing methods) to avoid unwanted conversions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I followed your comment here but I didn't find any guidance for this in node.js project. In my humble opinion, it might be better to allow the explicit keyword only for the single argument constructors. If we do that, we can have the advantage of using list initialization.

void hello(AsyncWorker worker) {
    ...
}

hello({ callback, "test" });

FYI, many other projects(e.g. Chromium) are also following the rule.
https://google.github.io/styleguide/cppguide.html#Implicit_Conversions

WDYT?

(async() => {
await test(require(`./build/${buildType}/binding.node`));
await test(require(`./build/${buildType}/binding_noexcept.node`));
})();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this was needed to make sure the tests ran sequentially. Could you do it without depending on await as we run the tests with older versions of Node.js that may not have support (ex 6.x I think)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

const events = [];
const hook = async_hooks.createHook({
init(asyncId, type, triggerAsyncId, resource) {
if (type === 'TestResource'){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing space between ) and {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@romandev
Copy link
Contributor Author

Thank you for review. I'm on a trip until this week. So, I'll update this patch until early next week. Thank you.

@mhdawson
Copy link
Member

@romandev thanks for the update :)

Copy link
Contributor Author

@romandev romandev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I addressed your comments.
Could you please review this patch?

const events = [];
const hook = async_hooks.createHook({
init(asyncId, type, triggerAsyncId, resource) {
if (type === 'TestResource'){
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

(async() => {
await test(require(`./build/${buildType}/binding.node`));
await test(require(`./build/${buildType}/binding_noexcept.node`));
})();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

napi.h Outdated
AsyncWorker(const Object& receiver,
const Function& callback,
const char* resource_name,
const Object& resource);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I followed your comment here but I didn't find any guidance for this in node.js project. In my humble opinion, it might be better to allow the explicit keyword only for the single argument constructors. If we do that, we can have the advantage of using list initialization.

void hello(AsyncWorker worker) {
    ...
}

hello({ callback, "test" });

FYI, many other projects(e.g. Chromium) are also following the rule.
https://google.github.io/styleguide/cppguide.html#Implicit_Conversions

WDYT?

Copy link
Member

@mhdawson mhdawson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mhdawson
Copy link
Member

@romandev thanks. @NickNaso any additional comments before we land?

Copy link
Member

@NickNaso NickNaso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked at code and seems good to me. Thanks @romandev

mhdawson pushed a commit that referenced this pull request May 25, 2018
This change is initiated from
#140 (comment).

PR-URL: #253
Reviewed-By: Michael Dawson <[email protected]>
Reviewed-By: Nicola Del Gobbo <[email protected]>
@mhdawson
Copy link
Member

Landed as 4b8918b

@mhdawson mhdawson closed this May 25, 2018
kevindavies8 added a commit to kevindavies8/node-addon-api-Develop that referenced this pull request Aug 24, 2022
This change is initiated from
nodejs/node-addon-api#140 (comment).

PR-URL: nodejs/node-addon-api#253
Reviewed-By: Michael Dawson <[email protected]>
Reviewed-By: Nicola Del Gobbo <[email protected]>
Marlyfleitas added a commit to Marlyfleitas/node-api-addon-Development that referenced this pull request Aug 26, 2022
This change is initiated from
nodejs/node-addon-api#140 (comment).

PR-URL: nodejs/node-addon-api#253
Reviewed-By: Michael Dawson <[email protected]>
Reviewed-By: Nicola Del Gobbo <[email protected]>
wroy7860 added a commit to wroy7860/addon-api-benchmark-node that referenced this pull request Sep 19, 2022
This change is initiated from
nodejs/node-addon-api#140 (comment).

PR-URL: nodejs/node-addon-api#253
Reviewed-By: Michael Dawson <[email protected]>
Reviewed-By: Nicola Del Gobbo <[email protected]>
johnfrench3 pushed a commit to johnfrench3/node-addon-api-git that referenced this pull request Aug 11, 2023
This change is initiated from
nodejs/node-addon-api#140 (comment).

PR-URL: nodejs/node-addon-api#253
Reviewed-By: Michael Dawson <[email protected]>
Reviewed-By: Nicola Del Gobbo <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants