-
Notifications
You must be signed in to change notification settings - Fork 1
Added implementation of V1
async_work runtime functions
#183
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
🦋 Changeset detectedLatest commit: 93a7330 The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
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 PR implements the V1 async work runtime functions (napi_create_async_work
, napi_queue_async_work
, napi_delete_async_work
, napi_cancel_async_work
) using facebook::react::CallInvoker
, adds a new async test suite (C and JS), refactors buffer tests to use shared macros, and fixes a bug in napi_create_external_buffer
.
- Wire up and expose async work APIs in the host runtime
- Add end-to-end async tests under
tests/async
- Refactor buffer tests to use
RuntimeNodeApiTestsCommon.h
and properassert
calls
Reviewed Changes
Copilot reviewed 19 out of 20 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
packages/node-addon-examples/tests/buffers/addon.js | Swapped console.log for assert.strictEqual calls |
packages/node-addon-examples/tests/buffers/addon.c | Replaced inlined macros with RuntimeNodeApiTestsCommon.h |
packages/node-addon-examples/tests/async/… | Added new async test package (JS and C), gyp, CMake setup |
packages/node-addon-examples/index.js | Registered the new async test in the examples index |
packages/host/scripts/generate-weak-node-api-injector.ts | Included RuntimeNodeApiAsync.hpp and extended function list |
packages/host/ios/… and packages/host/android/… | Imported async header and set the CallInvoker |
packages/host/cpp/RuntimeNodeApiAsync.hpp/.cpp | Implemented the async work registry and API entrypoints |
packages/host/cpp/RuntimeNodeApi.hpp/.cpp | Fixed napi_create_external_buffer implementation |
apps/test-app/App.tsx | Updated test runner to handle async test functions |
.changeset/rich-donuts-mix.md | Added changelog entry for async work support |
Comments suppressed due to low confidence (2)
packages/node-addon-examples/tests/buffers/addon.js:21
- This call triggers an invalid buffer conversion but lacks an assertion. Consider wrapping it in
assert.throws
to verify that the correct error is thrown.
addon.invalidObjectAsBuffer({});
packages/host/cpp/RuntimeNodeApiAsync.hpp:19
- [nitpick] The use of
node_api_basic_env
is inconsistent with the other APIs usingnapi_env
. For consistency and to prevent confusion, consider usingnapi_env
for all async work functions.
napi_status napi_queue_async_work(node_api_basic_env env, napi_async_work work);
@@ -12,6 +13,7 @@ jint JNI_OnLoad(JavaVM *vm, void *reserved) { | |||
facebook::react::registerCxxModuleToGlobalModuleMap( | |||
callstack::nodeapihost::CxxNodeApiHostModule::kModuleName, | |||
[](std::shared_ptr<facebook::react::CallInvoker> jsInvoker) { | |||
callstack::nodeapihost::setCallInvoker(jsInvoker); |
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.
In any case, it might make more sense to move this call into the CxxNodeApiHostModule
constructor?
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.
I thought that having all node api initialisations (callstack::nodeapihost::injectIntoWeakNodeApi()
+ callstack::nodeapihost::setCallInvoker(caller)
) in one place would be more correct. But now when revisiting it, code is duplicated because of Android/iOS anyway, so maybe moving it to the constructor makes more sense - I will change that.
f5041d2
to
07cfa07
Compare
8b59807
to
93a7330
Compare
Seems like the tests are now legitimately failing. |
This PR brings in:
V1
async work runtime functions usingfacebook::react::CallInvoker
:napi_create_async_work
napi_queue_async_work
napi_delete_async_work
napi_cancel_async_work
napi_create_external_buffer