Skip to content

Add resource_name and resource parameters to AsyncWorker constructor#253

Closed
romandev wants to merge 1 commit intonodejs:masterfrom
romandev:asyncworker
Closed

Add resource_name and resource parameters to AsyncWorker constructor#253
romandev wants to merge 1 commit intonodejs:masterfrom
romandev:asyncworker

Conversation

@romandev
Copy link
Copy Markdown
Contributor

This PR is initiated from #140 (comment).

Comment thread napi.h Outdated
AsyncWorker(const Object& receiver,
const Function& callback,
const char* resource_name,
const Object& resource);
Copy link
Copy Markdown
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
Copy Markdown
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?

Comment thread test/asyncworker.js Outdated
(async() => {
await test(require(`./build/${buildType}/binding.node`));
await test(require(`./build/${buildType}/binding_noexcept.node`));
})();
Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment thread test/asyncworker.js Outdated
const events = [];
const hook = async_hooks.createHook({
init(asyncId, type, triggerAsyncId, resource) {
if (type === 'TestResource'){
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member

@romandev thanks for the update :)

Copy link
Copy Markdown
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?

Comment thread test/asyncworker.js Outdated
const events = [];
const hook = async_hooks.createHook({
init(asyncId, type, triggerAsyncId, resource) {
if (type === 'TestResource'){
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

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

Choose a reason for hiding this comment

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

Done

Comment thread napi.h Outdated
AsyncWorker(const Object& receiver,
const Function& callback,
const char* resource_name,
const Object& resource);
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member

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

Copy link
Copy Markdown
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 <michael_dawson@ca.ibm.com>
Reviewed-By: Nicola Del Gobbo <nicoladelgobbo@NickNaso.local>
@mhdawson
Copy link
Copy Markdown
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 <michael_dawson@ca.ibm.com>
Reviewed-By: Nicola Del Gobbo <nicoladelgobbo@NickNaso.local>
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 <michael_dawson@ca.ibm.com>
Reviewed-By: Nicola Del Gobbo <nicoladelgobbo@NickNaso.local>
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 <michael_dawson@ca.ibm.com>
Reviewed-By: Nicola Del Gobbo <nicoladelgobbo@NickNaso.local>
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 <michael_dawson@ca.ibm.com>
Reviewed-By: Nicola Del Gobbo <nicoladelgobbo@NickNaso.local>
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