Uh oh!
There was an error while loading. Please reload this page.
Implement AsyncProgressWorker - #529
Conversation
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
mhdawson
commented
Aug 27, 2019
CI run to check across platforms: https://ci.nodejs.org/view/x%20-%20Abi%20stable%20module%20API/job/node-test-node-addon-api-new/503/nodes=rhel72-s390x/console |
mhdawson
commented
Aug 27, 2019
Seems to be a failure due to unused paramter in OnProgress. Will push a change to address that so can test further. |
mhdawson
commented
Aug 27, 2019
@legendecas can you take a look, seems to be failing in CI runs across platforms with: |
mhdawson
commented
Aug 27, 2019
@legendecas sorry, see you are still working on the tests from your checklist in the original post. Let us know when it's ready to review. One other thing that you'll need to add is docs in the "Async Operations" section of https://github.com/nodejs/node-addon-api |
legendecas
commented
Aug 27, 2019
Yes, it's crashed for case https://github.com/nodejs/node-addon-api/blob/master/test/asyncworker.js. It could be reproduced locally. |
legendecas
commented
Aug 27, 2019
Added to checklist |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
f7d9fd4 to
a9093d9CompareUh oh!
There was an error while loading. Please reload this page.
NickNaso
left a comment
There was a problem hiding this comment.
@legendecas I downloaded your work and it seems to work on macOS, but to execute the tests you need to add asyncprogressworker to here https://github.com/legendecas/node-addon-api/blob/async-progress-work/test/index.js#L13 and remove it in case the N-API version is less then 4 like we did here https://github.com/legendecas/node-addon-api/blob/async-progress-work/test/index.js#L67
legendecas
commented
Sep 3, 2019
#532 would blocking this PR from their routine work like CI/tests. (Just a note) |
a9093d9 to
16f7249Compare16f7249 to
3c3d321Compare3c3d321 to
f150a98CompareWas a bit worried that some of the locking features might have requuired later compilers. This CI run seems to confirm it can build/run on Node.js 8.X so that is not an issue: https://ci.nodejs.org/view/x%20-%20Abi%20stable%20module%20API/job/node-test-node-addon-api-new/675/ |
mhdawson
commented
Sep 27, 2019
@legendecas sorry it's taking so long to get the review done. I'm out of time for today but I'll try to continue reviewing next week. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
521711b to
2540375CompareUh oh!
There was an error while loading. Please reload this page.
mhdawson
left a comment
There was a problem hiding this comment.
LGTM, @legendecas thanks for all of the work on this. Hope to do a pass of landing PRs in the next few days.
gabrielschulhof
left a comment
There was a problem hiding this comment.
Partial review. Will continue.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
| void OnProgress(const uint32_t* data, size_t /* count */) { | ||
| HandleScope scope(Env()); | ||
| Callback().Call({Env().Null(), Env().Null(), Number::New(Env(), data)}); |
There was a problem hiding this comment.
data here is a pointer to an integer, not an integer. Also, there is no synchronization between the Execute writing to i and OnProgress reading from i. Perhaps above the code should be changed to
progress.Send(newuint32_t(i), 1);and here it should be
Callback().Call({Env().Null(), Env().Null(), Number::New(Env(), *data)});
delete data;There was a problem hiding this comment.
Yes, it's a pointer to an integer. I'll update the doc.
For the later question, as documented above, progress.Send will copy the data pointed to right on the call to the progress.Send. So it is safe to do so without any synchronizations.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
7e0e636 to
b9748f2Compare21fd0ba to
5c11a56Compare5c11a56 to
390507cCompare| @@ -0,0 +1,344 @@ | |||
| # AsyncProgressWorker | |||
| `Napi::AsyncProgressWorker` is an abstract class, which implements `Napi::AsyncWorker` | |||
There was a problem hiding this comment.
| `Napi::AsyncProgressWorker` is an abstract class, which implements `Napi::AsyncWorker` | |
| `Napi::AsyncProgressWorker` is an abstract class which implements `Napi::AsyncWorker` |
| ## Methods | ||
| [`Napi::AsyncWorker`]() provides detailed descriptions for most methods. |
There was a problem hiding this comment.
| [`Napi::AsyncWorker`]() provides detailed descriptions for most methods. | |
| [`Napi::AsyncWorker`][] provides detailed descriptions for most methods. |
| explicit Napi::AsyncProgressWorker(const Napi::Object& receiver, const Napi::Function& callback, const char* resource_name, const Napi::Object& resource); | ||
| ``` | ||
| - `[in] receiver`: The `this` object passed to the called function. |
There was a problem hiding this comment.
| -`[in] receiver`: The `this` object passed to the called function. | |
| -`[in] receiver`: The `this` object to pass to the called function. |
Uh oh!
There was an error while loading. Please reload this page.
| passed in through its constructor. | ||
| During the worker thread execution, the first argument of `Napi::AsyncProgressWorker::Execute` | ||
| can be used to report the process of the execution. |
There was a problem hiding this comment.
| can be used to report the process of the execution. | |
| can be used to report the progress of the execution. |
| callback that the `Napi::AsyncProgressWorker` base class will store persistently. When | ||
| the work on the `Napi::AsyncProgressWorker::Execute` method is done the | ||
| `Napi::AsyncProgressWorker::OnOk` method is called and the results return back to | ||
| JavaScript invoking the stored callback with its associated environment. |
There was a problem hiding this comment.
| JavaScript invoking the stored callback with its associated environment. | |
| JavaScript when the stored callback is invoked with its associated environment. |
| The following code shows an example of how to create and use an `Napi::AsyncProgressWorker` | ||
| ```cpp | ||
| #include<napi.h> |
There was a problem hiding this comment.
| #include<napi.h> | |
| #include<napi.h> |
| Using the implementation of a `Napi::AsyncProgressWorker` is straight forward. You only | ||
| need to create a new instance and pass to its constructor the callback you want to | ||
| execute when your asynchronous task ends and other data you need for your | ||
| computation. Once created the only other action you have to do is to call the | ||
| `Napi::AsyncProgressWorker::Queue` method that will queue the created worker for execution. |
There was a problem hiding this comment.
We generally avoid using "you" in our documentation. Let's rephrase this as
The implementation of a `Napi::AsyncProgressWorker` can be used by creating a
new instance and passing to its constructore the callback to execute when the
asynchronous task ends and other data needed for the computation. Once created,
the only other action needed is to call the `Napi::AsyncProgressWorker::Queue`
method that will queue the created worker for execution.
| The first step to use the `Napi::AsyncProgressWorker` class is to create a new class that | ||
| inherits from it and implement the `Napi::AsyncProgressWorker::Execute` abstract method. | ||
| Typically input to your worker will be saved within the class' fields generally |
There was a problem hiding this comment.
| Typically input to your worker will be saved within the class' fields generally | |
| Typically input to the worker will be saved within the class' fields generally |
| use namespace Napi; | ||
| Value Echo(const CallbackInfo& info) { | ||
| // You need to validate the arguments here |
There was a problem hiding this comment.
| // You need to validate the arguments here | |
| // We need to validate the arguments here |
mhdawson
commented
Nov 1, 2019
Landed as 650562c |
PR-URL: nodejs/node-addon-api#529Fixes: nodejs/node-addon-api#473 Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Gabriel Schulhof <gabriel.schulhof@intel.com>
PR-URL: nodejs/node-addon-api#529Fixes: nodejs/node-addon-api#473 Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Gabriel Schulhof <gabriel.schulhof@intel.com>
PR-URL: nodejs/node-addon-api#529Fixes: nodejs/node-addon-api#473 Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Gabriel Schulhof <gabriel.schulhof@intel.com>
PR-URL: nodejs/node-addon-api#529Fixes: nodejs/node-addon-api#473 Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Gabriel Schulhof <gabriel.schulhof@intel.com>
Related: #473