Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Open
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

paradowstack
Copy link
Contributor

This PR brings in:

  • Implementation of following V1 async work runtime functions using facebook::react::CallInvoker:
    • napi_create_async_work
    • napi_queue_async_work
    • napi_delete_async_work
    • napi_cancel_async_work
  • Introduces test addon, adopted from https://github.com/nodejs/node/blob/main/test/node-api/test_async
  • Adds a proper assertion to addon tests
  • Fixed an bug in implementation of napi_create_external_buffer

@paradowstack paradowstack requested a review from Copilot July 16, 2025 09:59
Copy link

changeset-bot bot commented Jul 16, 2025

🦋 Changeset detected

Latest 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

Copy link

@Copilot Copilot AI left a 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 proper assert 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 using napi_env. For consistency and to prevent confusion, consider using napi_env for all async work functions.
napi_status napi_queue_async_work(node_api_basic_env env, napi_async_work work);

@paradowstack paradowstack requested a review from kraenhansen July 16, 2025 10:27
@paradowstack paradowstack added Apple 🍎 Anything related to the Apple platform (iOS, macOS, Cocoapods, Xcode, XCFrameworks, etc.) Android 🤖 Anything related to the Android platform (Gradle, NDK, Android SDK) labels Jul 16, 2025
@paradowstack paradowstack marked this pull request as ready for review July 16, 2025 10:28
@paradowstack paradowstack added CI Continuous integration and removed CI Continuous integration labels Jul 16, 2025
@@ -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);
Copy link
Collaborator

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?

Copy link
Contributor Author

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.

@paradowstack paradowstack force-pushed the kp/async-runtime-functions branch from f5041d2 to 07cfa07 Compare July 16, 2025 13:18
@paradowstack paradowstack requested a review from kraenhansen July 16, 2025 14:20
@paradowstack paradowstack force-pushed the kp/async-runtime-functions branch from 8b59807 to 93a7330 Compare July 17, 2025 10:39
@kraenhansen
Copy link
Collaborator

Seems like the tests are now legitimately failing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Android 🤖 Anything related to the Android platform (Gradle, NDK, Android SDK) Apple 🍎 Anything related to the Apple platform (iOS, macOS, Cocoapods, Xcode, XCFrameworks, etc.)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants