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

Fundamental issues with ThreadSafeFunction #665

Closed
gabrielschulhof opened this issue Feb 3, 2020 · 7 comments
Closed

Fundamental issues with ThreadSafeFunction #665

gabrielschulhof opened this issue Feb 3, 2020 · 7 comments
Labels

Comments

@gabrielschulhof
Copy link
Contributor

The two issues below point to some fairly core problems with the current implementation of Napi::ThreadSafeFunction.

#653
#594

We may well have to create a new implementation, while at the same time retaining maximum backward compatibility and as smooth a transition path as possible for those who need the functionality mentioned in the issues above.

@KevinEady
Copy link
Contributor

I have started working on #653. I will put any comments on that thread.

@gabrielschulhof gabrielschulhof changed the title Fundanental issues with ThreadSafeFunction Fundamental issues with ThreadSafeFunction Feb 15, 2020
@KevinEady
Copy link
Contributor

@gabrielschulhof / @legendecas / @mhdawson :

In response to this, I think a solution that can solve both problems above, is actually to create a new templated class ThreadSafeFunctionEx<Context> that:

  • Getting rid of the "given-per-call" callback method signatures of [Non]BlockingCall.
  • Getting rid of above makes it much simpler to fix Context parameter on thread safe function callback #653 which I've been struggling on for awhile
  • And what about this, not sure though: Has only one New method, thereby putting the "what parameters are optional" into the logic of underlying napi_create_threadsafe_function Eg: if you do not want an async_resource, you would need to pass an empty Value(). This is for sake of keeping the code easily maintainable. (NB: need to figure out how nullptr context works, eg. maybe its ThreadSafeFunctionEx<nullptr_t>)
    • Could possibly default some arguments on the New method signature

I was originally against the creation of a new class but I just now saw the comment I linked above talking about removing those [Non]BlockingCall signatures and so maybe this is the best way forward... I should be on next weeks napi call to discuss.

Thanks, Kevin

@legendecas
Copy link
Member

if you do not want an async_resource, you would need to pass an empty Value()

This reminds me that maybe we can introduce Maybe box into node-addon-api to provide a stronger nullable contract.

@mhdawson
Copy link
Member

@KevinEady can we share most of the code between the existing ThreadSafeFunction and ThreadSafeFunctionEx<Context> ? If so it sounds like a good path to explore.

@KevinEady
Copy link
Contributor

@KevinEady can we share most of the code between the existing ThreadSafeFunction and ThreadSafeFunctionEx<Context> ? If so it sounds like a good path to explore.

Hi @mhdawson , posted this to #687

@github-actions
Copy link
Contributor

This issue is stale because it has been open many days with no activity. It will be closed soon unless the stale label is removed or a comment is made.

@github-actions github-actions bot added the stale label Dec 16, 2020
@mhdawson
Copy link
Member

@KevinEady , @gabrielschulhof should we close this as fixed by #742?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants