-
Notifications
You must be signed in to change notification settings - Fork 3
Implementation of threadsafe functions #220
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
base: main
Are you sure you want to change the base?
Conversation
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.
Pull Request Overview
This pull request implements complete thread-safe function support for Node-API, enabling cross-thread communication between native code and JavaScript. The implementation provides all core Node-API threadsafe functions with proper lifecycle management, queueing semantics, and reference counting.
Key changes:
- Added ThreadSafeFunction class with full Node-API compatibility including creation, calling, acquire/release, and ref/unref operations
- Implemented all seven Node-API threadsafe functions in RuntimeNodeApiAsync.cpp with proper error handling and state management
- Added comprehensive test suite based on Node.js official tests to validate functionality across different threading scenarios
Reviewed Changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 4 comments.
Show a summary per file
File | Description |
---|---|
packages/host/cpp/ThreadsafeFunction.hpp | Header defining the ThreadSafeFunction class with thread-safe queue management and lifecycle controls |
packages/host/cpp/ThreadsafeFunction.cpp | Complete implementation of thread-safe function with global registry, queueing, and finalization logic |
packages/host/cpp/RuntimeNodeApiAsync.cpp | Node-API function implementations delegating to ThreadSafeFunction class methods |
packages/host/scripts/generate-weak-node-api-injector.ts | Added threadsafe function names to implemented functions list |
packages/node-addon-examples/tests/threadsafe_function/* | Test suite files including C++ addon and JavaScript test harness |
packages/host/android/CMakeLists.txt | Build configuration updates to include new ThreadsafeFunction source files |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
This pull request introduces a complete implementation of Node-API's thread-safe function support for the host runtime, including its registration, lifecycle management, and queueing semantics.
Thread-safe function implementation:
napi_create_threadsafe_function
,napi_call_threadsafe_function
,napi_acquire_threadsafe_function
,napi_release_threadsafe_function
,napi_unref_threadsafe_function
,napi_ref_threadsafe_function
,napi_get_threadsafe_function_context
) inRuntimeNodeApiAsync.cpp
ThreadSafeFunction
class , providing a full implementation of Node-API's thread-safe function, including queueing, reference management, context retrieval, and finalization logic. This includes a global registry for safe handle management.Testing and examples: