Added implementation of V1 async_work runtime functions#183
Added implementation of V1 async_work runtime functions#183paradowstack merged 19 commits intomainfrom
V1 async_work runtime functions#183Conversation
🦋 Changeset detectedLatest commit: 5ce6a02 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.
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.hand properassertcalls
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.throwsto verify that the correct error is thrown.
addon.invalidObjectAsBuffer({});
packages/host/cpp/RuntimeNodeApiAsync.hpp:19
- [nitpick] The use of
node_api_basic_envis inconsistent with the other APIs usingnapi_env. For consistency and to prevent confusion, consider usingnapi_envfor all async work functions.
napi_status napi_queue_async_work(node_api_basic_env env, napi_async_work work);
| 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.
In any case, it might make more sense to move this call into the CxxNodeApiHostModule constructor?
There was a problem hiding this comment.
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. |
670e749 to
a0917a3
Compare
a0917a3 to
5ce6a02
Compare
This PR brings in:
V1async work runtime functions usingfacebook::react::CallInvoker:napi_create_async_worknapi_queue_async_worknapi_delete_async_worknapi_cancel_async_worknapi_create_external_buffer