-
Notifications
You must be signed in to change notification settings - Fork 465
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
Semantical difference between Napi::ThreadSafeFunction and napi_threadsafe_function #594
Comments
Hi @legendecas , Yes, this is a good point. It was briefly mentioned here #556 (comment) and discussed in the subsequent napi meeting, and thus spawning #580. I personally vote for your first solution "Add a caveat section on the doc of Napi::ThreadSafeFunction" because when #580 lands, you can use the tsfn in 1:1 manner. It's just that the "default behavior" is this wrapped thing. |
Good to see it's already progressing here. Yet there is still no constructors for creating |
Ahhh yes I understand that concern now. Considering that using the current |
After discussing this with the N-API team, it looks like we may need to remove this functionality from Removal per se is not an option for backward compatibility reasons. Thus, we need to figure a way forward so as not to break existing users, while providing as smooth a path away from these shortcomings for those who need it. |
Regarding the "performance penalty"... I'm not sure if it's possible to add some type-safety / type-convenience without doing some sort of wrapper around the I'm working on the new TSFN API and I'm not sure if a wrap would be allowed here (similar to how we have a |
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. |
I believe this is fixed by #742 @legendecas , @mhdawson , @gabrielschulhof |
Napi::ThreadSafeFunction
now acts as a bridge between the JavaScript function callback and multiple runtime c++ function callbacks. That is to say,Napi::ThreadSafeFunction
has built a 1:m relation on the JavaScript function and c++ function semantically. See call functions ofNapi::ThreadSafeFunction
and their variants:With these signatures we could provide different c++ functions on each thread safe function call. It might be more convenient to be used. Yet while reviewing
napi_threadsafe_function
docs, we could find thatnapi_threadsafe_function
has a 1:1 relation on JavaScript function and c++ function which is built on the creation function signature:Either this behavior was intended or not, this may cause confusion on introducing
Napi::ThreadSafeFunction
to an existing N-API document reader. They may have the impression that a single thread safe function is going to be used for one purpose, and has 1:1 relation on JavaScript function and the c++ function.Possible solutions (might not be the best solutions):
Napi::ThreadSafeFunction
Or it may not be a problem at all.
The text was updated successfully, but these errors were encountered: