-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
napi_create_threadsafe_function func should be optional #27592
Comments
@gabrielschulhof FYI. Making it optional seems reasonable to me if it is not required for all use cases. |
@mhdawson sounds reasonable. |
What about the |
Sounds fine to me! |
PR-URL: nodejs#27791 Refs: nodejs#27592 Reviewed-By: Gabriel Schulhof <[email protected]>
PR-URL: #27791 Refs: #27592 Reviewed-By: Gabriel Schulhof <[email protected]>
Closing, this was fixed in #27791. |
PR-URL: nodejs#27791 Refs: nodejs#27592 Reviewed-By: Gabriel Schulhof <[email protected]>
PR-URL: nodejs#27791 Refs: nodejs#27592 Reviewed-By: Gabriel Schulhof <[email protected]>
PR-URL: #27791 Backport-PR-URL: #28399 Refs: #27592 Reviewed-By: Gabriel Schulhof <[email protected]>
Short version:
The
func
parameter tonapi_create_threadsafe_function(env, func, ...)
should be optional if you pass a customcall_js_cb
function. Not all uses of threadsafe_function use a static javascript function across all invocations.I'm porting the foundationdb bindings to n-api. FDB creates a network thread on which it returns values. So, the normal usage is:
I'm writing code to solve the missing piece. The current implementation creates a
uv_async
object each time. But that won't work with napi.So I need to use
napi_create_threadsafe_function(env, func, ...)
to send the future value back to the main thread. Each time the future resolves (each item added to the queue) will resolve using its own callback function or future. For this reason I'm passingNULL
as the func argument, and using my own resolver code.But this makes the call to
napi_create_threadsafe_function
throw anapi_invalid_arg
error! The func argument should to be optional if you specify your owncall_js_cb
callback. I'm working around it for now by making a junk function but thats ugly and gross.The nodejs code is here, though we'll want to backport the equivalent change to node v10/11 as well. This change should be backwards compatible, because passing null was previously invalid in all cases.
The text was updated successfully, but these errors were encountered: