Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34.2k
n-api: implement async helper methods#12250
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
Uh oh!
There was an error while loading. Please reload this page.
Conversation
boingoing commented Apr 6, 2017 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
boingoing commented Apr 6, 2017
@jasongin@digitalinfinity@mhdawson@sampsongao |
kkoopa commented Apr 6, 2017 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
Would it be reasonable to use |
bnoordhuis commented Apr 6, 2017
Why would you do this in napi instead of nan? Seems like feature creep. |
addaleax commented Apr 6, 2017 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
@bnoordhuis See also #11975 (comment). I am still not 100 % sure about this either… |
mhdawson left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
mhdawson commented Apr 6, 2017 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
@bnoordhuis there was also a comment from @kkoopa on this issue: nodejs/abi-stable-node#204 In response to discussion about removing from the original PR (which we did temporarily, and are now adding back in): |
boingoing commented Apr 6, 2017
@kkoopa There isn't an ABI issue blocking us from using |
boingoing commented Apr 6, 2017
The issue and comments @mhdawson is referencing above are at nodejs/abi-stable-node#204 (comment) |
kkoopa commented Apr 6, 2017 via email
Yes that is what I was wondering about. If the class is not exposed, it is fine as is. …On April 6, 2017 11:09:32 PM GMT+03:00, Taylor Woll ***@***.***> wrote: >Would it be reasonable to use unique_ptr instead of handing out raw pointers in the Work class? Is there an ABI issue? @kkoopa There isn't an ABI issue blocking us from using `unique_ptr` wrapping `Work` instances and handing those out as `napi_async_work` pointers, if that's what you meant. Since the `Work` class is not exposed outside of napi internals, we aren't worried about users messing-up the state via these opaque `napi_async_work` pointers. We use the same pattern for returning `Reference` instances via `napi_ref` opaque pointers via `napi_create_reference`. That's the main reason I have used the same pattern here. -- You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub: #12250 (comment) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: redundant space before function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not redundant, it is part of the string on the line above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you have this test case queue the work multiple times and verify that that works? You'll probably have to change the complete handler to not delete the work after every item but only when all work has been completed
src/node_api_types.h Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was this moved?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I put the napi_callback typedef near napi_async_execute_callback and other callback typedefs. But napi_async_complete_callback takes a napi_status so all the callbacks should be located down below the enum (at least). However, napi_property_descriptor has napi_callback members so it also had to move down in the file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either
errorMessage = errorMessage == nullptr ? "empty error message" : errorMessage;or
errorMessage = errorMessage || "empty error message";There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. This will be refactored via #12248 so I didn't pull all of that in for this change. Will make this change, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We use snake_case for C++ code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for noticing. I fixed this via 1b210fe
mhdawson commented Apr 10, 2017
mhdawson commented Apr 10, 2017
Link failures: ln -s /usr/local/bin/node Please fix up and make sure to run make lint |
boingoing commented Apr 10, 2017
@mhdawson Pushed 85ca55a to fix these lint errors. Are the same rules used when we run Anyway, could you kick off a new CI, please? :) |
mhdawson commented Apr 10, 2017
I assume it should be the same across platforms so not sure what might have happend: New CI: https://ci.nodejs.org/job/node-test-pull-request/7309/ |
mhdawson commented Apr 10, 2017
Sorry your other PR made it in first can you do a rebase and the I'll give it one more shot. |
Based on the async methods we had in abi-stable-node before the napi feature landed in node/master. Changed this set of APIs to handle error cases and removed a lot of the extra methods we had for setting all the pieces of napi_work opting instead to pass all of those as arguments to napi_create_async_work as none of those parameters are optional except for the complete callback, anyway. Renamed the napi_work struct to napi_async_work and replace the struct itself with a class which can better encapsulate the object lifetime and uv_work_t that we're trying to wrap anyway. Added a napi_async_callback type for the async helper callbacks instead of taking raw function pointers and make this callback take a napi_env parameter as well as the void* data it was already taking. Call the complete handler for the async work item with a napi_status code translated from the uvlib error code. The execute callback is required for napi_create_async_work, though complete callback is still optional. Also added some async unit tests for addons-napi based on the addons/async_hello_world test.
boingoing commented Apr 10, 2017
@mhdawson No worry, I knew one of them would get in first which would conflict with the other. I did the rebase and running test locally to see if I can catch any kind of lint errors on my end before updating the PR. |
mhdawson commented Apr 10, 2017
ok, If you can do it today I'll check in later tonight to see if we can get it landed as I'm pretty booked tomorrow. |
boingoing commented Apr 10, 2017
@mhdawson Thanks for baby-sitting this PR. I pushed the rebase via 35a0287. |
addaleax commented Apr 10, 2017
addaleax commented Apr 10, 2017
Landed in 9decfb1 |
Based on the async methods we had in abi-stable-node before the napi feature landed in node/master. Changed this set of APIs to handle error cases and removed a lot of the extra methods we had for setting all the pieces of napi_work opting instead to pass all of those as arguments to napi_create_async_work as none of those parameters are optional except for the complete callback, anyway. Renamed the napi_work struct to napi_async_work and replace the struct itself with a class which can better encapsulate the object lifetime and uv_work_t that we're trying to wrap anyway. Added a napi_async_callback type for the async helper callbacks instead of taking raw function pointers and make this callback take a napi_env parameter as well as the void* data it was already taking. Call the complete handler for the async work item with a napi_status code translated from the uvlib error code. The execute callback is required for napi_create_async_work, though complete callback is still optional. Also added some async unit tests for addons-napi based on the addons/async_hello_world test. PR-URL: #12250 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: Timothy Gu <[email protected]> Reviewed-By: Hitesh Kanwathirtha <[email protected]>
mhdawson commented Apr 11, 2017
:) |
boingoing commented Apr 11, 2017
Thanks all! 😃 |
aruneshchandra commented Apr 11, 2017
do we need to tag this with the right labels to be picked up for next RC ? |
Based on the async methods we had in abi-stable-node before the napi feature landed in node/master. Changed this set of APIs to handle error cases and removed a lot of the extra methods we had for setting all the pieces of napi_work opting instead to pass all of those as arguments to napi_create_async_work as none of those parameters are optional except for the complete callback, anyway. Renamed the napi_work struct to napi_async_work and replace the struct itself with a class which can better encapsulate the object lifetime and uv_work_t that we're trying to wrap anyway. Added a napi_async_callback type for the async helper callbacks instead of taking raw function pointers and make this callback take a napi_env parameter as well as the void* data it was already taking. Call the complete handler for the async work item with a napi_status code translated from the uvlib error code. The execute callback is required for napi_create_async_work, though complete callback is still optional. Also added some async unit tests for addons-napi based on the addons/async_hello_world test. PR-URL: nodejs#12250 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: Timothy Gu <[email protected]> Reviewed-By: Hitesh Kanwathirtha <[email protected]>
Based on the async methods we had in abi-stable-node before the napi feature landed in node/master. Changed this set of APIs to handle error cases and removed a lot of the extra methods we had for setting all the pieces of napi_work opting instead to pass all of those as arguments to napi_create_async_work as none of those parameters are optional except for the complete callback, anyway. Renamed the napi_work struct to napi_async_work and replace the struct itself with a class which can better encapsulate the object lifetime and uv_work_t that we're trying to wrap anyway. Added a napi_async_callback type for the async helper callbacks instead of taking raw function pointers and make this callback take a napi_env parameter as well as the void* data it was already taking. Call the complete handler for the async work item with a napi_status code translated from the uvlib error code. The execute callback is required for napi_create_async_work, though complete callback is still optional. Also added some async unit tests for addons-napi based on the addons/async_hello_world test. Backport-PR-URL: #19447 PR-URL: #12250 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: Timothy Gu <[email protected]> Reviewed-By: Hitesh Kanwathirtha <[email protected]>
Based on the async methods we had in
abi-stable-nodebefore the napifeature landed in node/master. Changed this set of APIs to handle
error cases and removed a lot of the extra methods we had for setting
all the pieces of
napi_workopting instead to pass all of those asarguments to
napi_create_async_workas none of those parameters areoptional except for the complete callback, anyway.
Renamed the
napi_workstruct tonapi_async_workand replace thestruct itself with a class which can better encapsulate the object
lifetime and
uv_work_tthat we're trying to wrap anyway.Added a
napi_async_callbacktype for the async helper callbacksinstead of taking raw function pointers and make this callback take a
napi_envparameter as well as thevoid* datait was already taking.Call the complete handler for the async work item with a
napi_statuscode translated from the uvlib error code.
The execute callback is required for
napi_create_async_work, thoughcomplete callback is still optional.
Also added some async unit tests for addons-napi based on the
addons/async_hello_worldtest.Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passesAffected core subsystem(s)
n-api