-
Notifications
You must be signed in to change notification settings - Fork 459
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
src: make OnWorkComplete and OnExecute override-able #589
Conversation
0eb4bba
to
e1e5e6f
Compare
Just mark the PR as working in progress. |
e1e5e6f
to
016d91d
Compare
There might be issues on sharing the AsyncProgressWorker base class between AsyncProgressWorker and AsyncProgressQueueWorker if the ThreadSafeFunction queue size is different: a possible redundant wrapper around ThreadSafeFunction Call might be introduced to AsyncProgressWorker. So I'd like to remove the AsyncProgressWorker base class from the PR and leave the PR for the AsyncWorker's methods. |
This one is ready to be reviewed @nodejs/n-api please review/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 % nits
@@ -136,6 +136,30 @@ class was created, passing in the error as the first parameter. | |||
virtual void Napi::AsyncWorker::OnError(const Napi::Error& e); | |||
``` | |||
|
|||
### OnWorkComplete | |||
|
|||
This method is invoked after the work has completed on JavaScript thread. |
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:
This method is invoked after the work has completed on JavaScript thread. | |
This method is invoked after the work has completed on the JavaScript thread. |
ba820aa
to
3da380b
Compare
napi-inl.h
Outdated
// The OnAsyncWorkExecute method receives an napi_env argument. However, do NOT | ||
// use it within this method, as it does not run on the main thread and must | ||
// not run any method that would cause JavaScript to run. In practice, this | ||
// means that almost any use of napi_env will be incorrect. |
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.
This blurb should be copied into the documentation above.
napi-inl.h
Outdated
#ifdef NAPI_CPP_EXCEPTIONS | ||
try { | ||
self->Execute(); | ||
this->Execute(); |
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.
Do we need this->
here and in the lines below?
napi-inl.h
Outdated
if (status != napi_cancelled) { | ||
HandleScope scope(self->_env); | ||
HandleScope scope(this->_env); |
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.
Same here. I don't think we need this->
.
Noticed some greater-than-nit things like the removal of this->
No breaking changes on existing code were expected. All existing tests shall pass without any touch. Changes on declaration: - Added `Napi::AsyncWorker::OnWorkComplete`. - Added `Napi::AsyncWorker::OnExecute`.
3da380b
to
0de964c
Compare
@gabrielschulhof updated! PTAL :D |
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 with a few nits.
doc/async_worker.md
Outdated
The default implementation of this method just calls the `Napi::AsyncWorker::Execute` | ||
and handles exceptions if cpp exceptions were enabled. | ||
|
||
The `OnExecute` method receives an `napi_env` argument. However, do NOT |
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.
The `OnExecute` method receives an `napi_env` argument. However, do NOT | |
The `OnExecute` method receives an `napi_env` argument. However, it must NOT be used |
doc/async_worker.md
Outdated
and handles exceptions if cpp exceptions were enabled. | ||
|
||
The `OnExecute` method receives an `napi_env` argument. However, do NOT | ||
use it within this method, as it does not run on the JavaScript thread and |
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.
use it within this method, as it does not run on the JavaScript thread and | |
within this method, as it does not run on the JavaScript thread and |
CI:
|
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
No breaking changes on existing code were expected. All existing tests shall pass without any touch. Changes on declaration: - Added `Napi::AsyncWorker::OnWorkComplete`. - Added `Napi::AsyncWorker::OnExecute`. PR-URL: #589 Reviewed-By: Gabriel Schulhof <gabriel.schulhof@intel.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Landed in 23ff7f0. |
No breaking changes on existing code were expected. All existing tests shall pass without any touch. Changes on declaration: - Added `Napi::AsyncWorker::OnWorkComplete`. - Added `Napi::AsyncWorker::OnExecute`. PR-URL: nodejs/node-addon-api#589 Reviewed-By: Gabriel Schulhof <gabriel.schulhof@intel.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
No breaking changes on existing code were expected. All existing tests shall pass without any touch. Changes on declaration: - Added `Napi::AsyncWorker::OnWorkComplete`. - Added `Napi::AsyncWorker::OnExecute`. PR-URL: nodejs/node-addon-api#589 Reviewed-By: Gabriel Schulhof <gabriel.schulhof@intel.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
No breaking changes on existing code were expected. All existing tests shall pass without any touch. Changes on declaration: - Added `Napi::AsyncWorker::OnWorkComplete`. - Added `Napi::AsyncWorker::OnExecute`. PR-URL: nodejs/node-addon-api#589 Reviewed-By: Gabriel Schulhof <gabriel.schulhof@intel.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
No breaking changes on existing code were expected. All existing tests shall pass without any touch. Changes on declaration: - Added `Napi::AsyncWorker::OnWorkComplete`. - Added `Napi::AsyncWorker::OnExecute`. PR-URL: nodejs/node-addon-api#589 Reviewed-By: Gabriel Schulhof <gabriel.schulhof@intel.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
No breaking changes on existing code were expected. All existing tests shall pass without any touch.
Changes on declaration:
Napi::AsyncWorker::OnWorkComplete
.Napi::AsyncWorker::OnExecute
.Fixes: #582