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

Remove const from AsyncProgressWorker::Signal and AsyncProgressQueueWorker::Signal #1086

Closed
wants to merge 9 commits into from

Conversation

JosephusPaye
Copy link

@JosephusPaye JosephusPaye commented Oct 6, 2021

This PR fixes #1081 by removing const from the AsyncProgressWorker::Signal and AsyncProgressQueueWorker::Signal methods, and also from the ExecutionProgress parameter of the Execute method (this one might be a breaking change).

Also added a test for the AsyncProgressWorker::Signal. AsyncProgressQueueWorker::Signal needs to be tested as well. EDIT: Test added, but AsyncProgressQueueWorker::Signal() doesn't work, needs fixing.

@KevinEady
Copy link
Contributor

Hi @JosephusPaye ,

Thanks for your PR! We discussed this inside today's Node.js API meeting. Looking back at your original issue, you say the const issue comes from crossing the boundary between points 2 and 3:

// 2. https://github.com/nodejs/node-addon-api/blob/4351bffd537eab927226bf6f9b66cd385a049a43/napi-inl.h#L5876
template<class T>
inline void AsyncProgressWorker<T>::Signal() const {
  this->NonBlockingCall(static_cast<T*>(nullptr));
}

// 3. https://github.com/nodejs/node-addon-api/blob/4351bffd537eab927226bf6f9b66cd385a049a43/napi-inl.h#L5725
template <typename DataType>
inline napi_status AsyncProgressWorkerBase<DataType>::NonBlockingCall(DataType* data) {
  auto tsd = new AsyncProgressWorkerBase::ThreadSafeData(this, data);
  return _tsfn.NonBlockingCall(tsd, OnAsyncWorkProgress);
}

Have you thought about making the method in point three const instead? Does this fix the issue as well?

Thanks, Kevin

@JosephusPaye
Copy link
Author

Hi Kevin,

I went ahead and tried adding const to NonBlockingCall() but that raises further errors that require adding const in other places:

  • AsyncProgressWorkerBase::ThreadSafeData needs const on the constructor param that takes the AsyncProgressWorkerBase instance, the member variable that stores it, and the method that returns it
  • As a result OnWorkProgress() needs const on AsyncProgressWorkerBase, AsyncProgressWorker and AsyncProgressQueueWorker
  • As a result OnProgress() needs const (this one is a user-visible change, potentially breaking)
  • This breaks the AsyncProgressQueueWorker test, where the OnProgress() method calls the Receiver() method to run a JS callback, and also calls notify_one() on the std::condition_variable member variable, where notify_one() is non-const.

@JosephusPaye
Copy link
Author

It also appears AsyncProgressQueueWorker::Signal() is not working as expected, as this test shows.

@KevinEady
Copy link
Contributor

Hi @JosephusPaye ,

We reviewed both of your issues here (the const and the non-call of Signal()). We would like to separate them into two different issues, so I created the non-calling of Signal() here #1095

@legendecas will take a further look into the implementation of why const is failing here, because our implementation is based off of Nan's which is const.

@JosephusPaye
Copy link
Author

Sounds good!

napi.h Outdated Show resolved Hide resolved
test/async_progress_worker.js Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

const error with AsyncProgressWorker<T>::ExecutionProgress::Signal()
5 participants